diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 21:25:11 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 22:26:18 +0100 |
commit | c61b29ebfdde6d0bafdd898d9b723d0444a81ca1 (patch) | |
tree | 85189161e10552a6947ad64a5e2dff4816727fd0 /app/controllers | |
parent | 30d9abdfc9b7e99ba516e9baeba699ff319f9f10 (diff) |
Refactor some more
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 881c23f94..0b78e36d6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -74,8 +74,8 @@ class ApplicationController < ActionController::Base end def use_pack(pack_name) - @core = resolve_pack(Themes.instance.core, pack_name) - @theme = resolve_pack(Themes.instance.flavour(current_flavour), pack_name, current_skin) + @core = resolve_pack_with_common(Themes.instance.core, pack_name) + @theme = resolve_pack_with_common(Themes.instance.flavour(current_flavour), pack_name, current_skin) end protected @@ -162,13 +162,13 @@ class ApplicationController < ActionController::Base private - def valid_pack?(data, pack_name) + def valid_pack_data?(data, pack_name) data['pack'].is_a?(Hash) && [String, Hash].any? { |c| data['pack'][pack_name].is_a?(c) } end - def nil_pack(data, pack_name, skin) + def nil_pack(data) { - common: pack_name == 'common' ? nil : resolve_pack(data['name'] ? Themes.instance.flavour(current_flavour) : Themes.instance.core, 'common', skin), + use_common: true, flavour: data['name'], pack: nil, preload: nil, @@ -179,7 +179,7 @@ class ApplicationController < ActionController::Base def pack(data, pack_name, skin) pack_data = { - common: pack_name == 'common' ? nil : resolve_pack(data['name'] ? Themes.instance.flavour(current_flavour) : Themes.instance.core, 'common', skin), + use_common: true, flavour: data['name'], pack: pack_name, preload: nil, @@ -189,7 +189,7 @@ class ApplicationController < ActionController::Base return pack_data unless data['pack'][pack_name].is_a?(Hash) - pack_data[:common] = nil if data['pack'][pack_name]['use_common'] == false + pack_data[:use_common] = false if data['pack'][pack_name]['use_common'] == false pack_data[:pack] = nil unless data['pack'][pack_name]['filename'] preloads = data['pack'][pack_name]['preload'] @@ -205,9 +205,9 @@ class ApplicationController < ActionController::Base pack_data end - def resolve_pack(data, pack_name, skin = 'default') - return pack(data, pack_name, skin) if valid_pack?(data, pack_name) - return nil_pack(data, pack_name, skin) if data['name'].blank? + def resolve_pack(data, pack_name, skin) + return pack(data, pack_name, skin) if valid_pack_data?(data, pack_name) + return if data['name'].blank? fallbacks = [] if data.key?('fallback') @@ -221,6 +221,12 @@ class ApplicationController < ActionController::Base return resolve_pack(Themes.instance.flavour(fallback), pack_name) if Themes.instance.flavour(fallback) end - nil_pack(data, pack_name, skin) + nil + end + + def resolve_pack_with_common(data, pack_name, skin = 'default') + result = resolve_pack(data, pack_name, skin) || nil_pack(data) + result[:common] = resolve_pack(data, 'common', skin) if result.delete(:use_common) + result end end |