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