2017-09-25 22:24:32 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'singleton'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
class Themes
|
|
|
|
include Singleton
|
|
|
|
|
|
|
|
def initialize
|
2017-11-21 01:13:37 -05:00
|
|
|
|
|
|
|
core = YAML.load_file(Rails.root.join('app', 'javascript', 'core', 'theme.yml'))
|
|
|
|
core['pack'] = Hash.new unless core['pack']
|
|
|
|
|
2017-09-25 22:24:32 -04:00
|
|
|
result = Hash.new
|
2017-12-04 02:26:40 -05:00
|
|
|
Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path|
|
2017-09-25 22:24:32 -04:00
|
|
|
data = YAML.load_file(path)
|
2017-12-10 23:15:09 -05:00
|
|
|
dir = File.dirname(path)
|
|
|
|
name = File.basename(dir)
|
|
|
|
locales = []
|
|
|
|
screenshots = []
|
2017-12-07 22:07:47 -05:00
|
|
|
if data['locales']
|
2017-12-10 23:15:09 -05:00
|
|
|
Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale|
|
2017-12-07 22:07:47 -05:00
|
|
|
localeName = File.basename(locale, File.extname(locale))
|
|
|
|
locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/)
|
|
|
|
end
|
2017-12-10 23:15:09 -05:00
|
|
|
end
|
|
|
|
if data['screenshot']
|
|
|
|
if data['screenshot'].is_a? Array
|
|
|
|
screenshots = data['screenshot']
|
|
|
|
else
|
|
|
|
screenshots.push(data['screenshot'])
|
|
|
|
end
|
2017-12-07 22:07:47 -05:00
|
|
|
end
|
2017-11-17 00:35:25 -05:00
|
|
|
if data['pack']
|
2017-11-21 01:13:37 -05:00
|
|
|
data['name'] = name
|
2017-12-10 23:15:09 -05:00
|
|
|
data['locales'] = locales
|
|
|
|
data['screenshot'] = screenshots
|
2017-11-30 22:29:47 -05:00
|
|
|
data['skin'] = { 'default' => [] }
|
2017-11-17 00:35:25 -05:00
|
|
|
result[name] = data
|
2017-09-25 22:24:32 -04:00
|
|
|
end
|
|
|
|
end
|
2017-11-21 01:13:37 -05:00
|
|
|
|
2017-11-30 22:29:47 -05:00
|
|
|
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
|
2017-12-04 01:30:45 -05:00
|
|
|
elsif ext.match(/^\.s?css$/i)
|
2017-11-30 22:29:47 -05:00
|
|
|
skin = File.basename(path, ext)
|
|
|
|
pack = ['common']
|
|
|
|
end
|
|
|
|
if skin != 'default'
|
|
|
|
result[name]['skin'][skin] = pack
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
@core = core
|
2017-09-25 22:24:32 -04:00
|
|
|
@conf = result
|
2017-11-21 01:13:37 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def core
|
|
|
|
@core
|
2017-09-25 22:24:32 -04:00
|
|
|
end
|
|
|
|
|
2017-12-04 02:26:40 -05:00
|
|
|
def flavour(name)
|
2017-11-17 00:35:25 -05:00
|
|
|
@conf[name]
|
|
|
|
end
|
|
|
|
|
2017-12-04 02:26:40 -05:00
|
|
|
def flavours
|
2017-09-25 22:24:32 -04:00
|
|
|
@conf.keys
|
|
|
|
end
|
2017-11-30 22:29:47 -05:00
|
|
|
|
|
|
|
def skins_for(name)
|
|
|
|
@conf[name]['skin'].keys
|
|
|
|
end
|
2018-10-08 09:00:27 -04:00
|
|
|
|
|
|
|
def flavours_and_skins
|
|
|
|
flavours.map do |flavour|
|
|
|
|
[flavour, skins_for(flavour).map{ |skin| [flavour, skin] }]
|
|
|
|
end
|
|
|
|
end
|
2017-09-25 22:24:32 -04:00
|
|
|
end
|