Refactor theme config loading

This commit is contained in:
Claire 2022-01-16 21:46:48 +01:00
parent c61b29ebfd
commit 1b386c881c

View file

@ -14,16 +14,20 @@ class Themes
result = Hash.new result = Hash.new
Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path| Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path|
data = YAML.load_file(path) data = YAML.load_file(path)
next unless data['pack']
dir = File.dirname(path) dir = File.dirname(path)
name = File.basename(dir) name = File.basename(dir)
locales = [] locales = []
screenshots = [] screenshots = []
if data['locales'] if data['locales']
Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale| Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale|
localeName = File.basename(locale, File.extname(locale)) localeName = File.basename(locale, File.extname(locale))
locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/) locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/)
end end
end end
if data['screenshot'] if data['screenshot']
if data['screenshot'].is_a? Array if data['screenshot'].is_a? Array
screenshots = data['screenshot'] screenshots = data['screenshot']
@ -31,20 +35,20 @@ class Themes
screenshots.push(data['screenshot']) screenshots.push(data['screenshot'])
end end
end end
if data['pack']
data['name'] = name data['name'] = name
data['locales'] = locales data['locales'] = locales
data['screenshot'] = screenshots data['screenshot'] = screenshots
data['skin'] = { 'default' => [] } data['skin'] = { 'default' => [] }
result[name] = data result[name] = data
end end
end
Dir.glob(Rails.root.join('app', 'javascript', 'skins', '*', '*')) do |path| Dir.glob(Rails.root.join('app', 'javascript', 'skins', '*', '*')) do |path|
ext = File.extname(path) ext = File.extname(path)
skin = File.basename(path) skin = File.basename(path)
name = File.basename(File.dirname(path)) name = File.basename(File.dirname(path))
if result[name] next unless result[name]
if File.directory?(path) if File.directory?(path)
pack = [] pack = []
Dir.glob(File.join(path, '*.{css,scss}')) do |sheet| Dir.glob(File.join(path, '*.{css,scss}')) do |sheet|
@ -54,15 +58,14 @@ class Themes
skin = File.basename(path, ext) skin = File.basename(path, ext)
pack = ['common'] pack = ['common']
end end
if skin != 'default' if skin != 'default'
result[name]['skin'][skin] = pack result[name]['skin'][skin] = pack
end end
end end
end
@core = core @core = core
@conf = result @conf = result
end end
def core def core