diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 21:46:48 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 22:26:18 +0100 |
commit | 1b386c881c1a426c69a0f06fa6918fea3fcc2aaf (patch) | |
tree | a3c9fcabefcab904b13c69b7a353050e111b656d /app | |
parent | c61b29ebfdde6d0bafdd898d9b723d0444a81ca1 (diff) |
Refactor theme config loading
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/themes.rb | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/app/lib/themes.rb b/app/lib/themes.rb index 2147904e4..81e016d4a 100644 --- a/app/lib/themes.rb +++ b/app/lib/themes.rb @@ -14,16 +14,20 @@ class Themes result = Hash.new Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path| data = YAML.load_file(path) + next unless data['pack'] + dir = File.dirname(path) name = File.basename(dir) locales = [] screenshots = [] + if data['locales'] Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale| localeName = File.basename(locale, File.extname(locale)) locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/) end end + if data['screenshot'] if data['screenshot'].is_a? Array screenshots = data['screenshot'] @@ -31,38 +35,37 @@ class Themes screenshots.push(data['screenshot']) end end - if data['pack'] - data['name'] = name - data['locales'] = locales - data['screenshot'] = screenshots - data['skin'] = { 'default' => [] } - result[name] = data - end + + data['name'] = name + data['locales'] = locales + data['screenshot'] = screenshots + data['skin'] = { 'default' => [] } + result[name] = data end Dir.glob(Rails.root.join('app', 'javascript', 'skins', '*', '*')) do |path| ext = File.extname(path) skin = File.basename(path) name = File.basename(File.dirname(path)) - if result[name] - if File.directory?(path) - pack = [] - Dir.glob(File.join(path, '*.{css,scss}')) do |sheet| - pack.push(File.basename(sheet, File.extname(sheet))) - end - elsif ext.match(/^\.s?css$/i) - skin = File.basename(path, ext) - pack = ['common'] - end - if skin != 'default' - result[name]['skin'][skin] = pack + next unless result[name] + + if File.directory?(path) + pack = [] + Dir.glob(File.join(path, '*.{css,scss}')) do |sheet| + pack.push(File.basename(sheet, File.extname(sheet))) end + elsif ext.match(/^\.s?css$/i) + skin = File.basename(path, ext) + pack = ['common'] + end + + if skin != 'default' + result[name]['skin'][skin] = pack end end @core = core @conf = result - end def core |