Refactor some more
This commit is contained in:
parent
30d9abdfc9
commit
c61b29ebfd
|
@ -74,8 +74,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_pack(pack_name)
|
def use_pack(pack_name)
|
||||||
@core = resolve_pack(Themes.instance.core, pack_name)
|
@core = resolve_pack_with_common(Themes.instance.core, pack_name)
|
||||||
@theme = resolve_pack(Themes.instance.flavour(current_flavour), pack_name, current_skin)
|
@theme = resolve_pack_with_common(Themes.instance.flavour(current_flavour), pack_name, current_skin)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -162,13 +162,13 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
private
|
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) }
|
data['pack'].is_a?(Hash) && [String, Hash].any? { |c| data['pack'][pack_name].is_a?(c) }
|
||||||
end
|
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'],
|
flavour: data['name'],
|
||||||
pack: nil,
|
pack: nil,
|
||||||
preload: nil,
|
preload: nil,
|
||||||
|
@ -179,7 +179,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def pack(data, pack_name, skin)
|
def pack(data, pack_name, skin)
|
||||||
pack_data = {
|
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'],
|
flavour: data['name'],
|
||||||
pack: pack_name,
|
pack: pack_name,
|
||||||
preload: nil,
|
preload: nil,
|
||||||
|
@ -189,7 +189,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
return pack_data unless data['pack'][pack_name].is_a?(Hash)
|
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']
|
pack_data[:pack] = nil unless data['pack'][pack_name]['filename']
|
||||||
|
|
||||||
preloads = data['pack'][pack_name]['preload']
|
preloads = data['pack'][pack_name]['preload']
|
||||||
|
@ -205,9 +205,9 @@ class ApplicationController < ActionController::Base
|
||||||
pack_data
|
pack_data
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_pack(data, pack_name, skin = 'default')
|
def resolve_pack(data, pack_name, skin)
|
||||||
return pack(data, pack_name, skin) if valid_pack?(data, pack_name)
|
return pack(data, pack_name, skin) if valid_pack_data?(data, pack_name)
|
||||||
return nil_pack(data, pack_name, skin) if data['name'].blank?
|
return if data['name'].blank?
|
||||||
|
|
||||||
fallbacks = []
|
fallbacks = []
|
||||||
if data.key?('fallback')
|
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)
|
return resolve_pack(Themes.instance.flavour(fallback), pack_name) if Themes.instance.flavour(fallback)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue