Refactor some more
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user