2017-09-26 03:24:32 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'singleton'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
class Themes
|
|
|
|
include Singleton
|
|
|
|
|
2024-04-05 10:52:43 +01:00
|
|
|
THEME_COLORS = {
|
2024-08-20 16:56:44 +01:00
|
|
|
dark: '#181820',
|
2024-06-27 17:46:20 +01:00
|
|
|
light: '#ffffff',
|
2024-04-05 10:52:43 +01:00
|
|
|
}.freeze
|
2024-03-29 13:32:07 +00:00
|
|
|
|
2017-09-26 03:24:32 +01:00
|
|
|
def initialize
|
2024-04-27 21:34:41 +01:00
|
|
|
@flavours = {}
|
|
|
|
|
2023-04-09 10:25:30 +01:00
|
|
|
Rails.root.glob('app/javascript/flavours/*/theme.yml') do |pathname|
|
|
|
|
data = YAML.load_file(pathname)
|
2024-04-28 11:08:08 +01:00
|
|
|
next unless data['pack_directory']
|
2022-01-16 20:46:48 +00:00
|
|
|
|
2023-04-09 10:25:30 +01:00
|
|
|
dir = pathname.dirname
|
|
|
|
name = dir.basename.to_s
|
2017-12-11 04:15:09 +00:00
|
|
|
locales = []
|
|
|
|
screenshots = []
|
2022-01-16 20:46:48 +00:00
|
|
|
|
2017-12-08 03:07:47 +00:00
|
|
|
if data['locales']
|
2017-12-11 04:15:09 +00:00
|
|
|
Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale|
|
2023-04-09 10:25:30 +01:00
|
|
|
locale_name = File.basename(locale, File.extname(locale))
|
|
|
|
locales.push(locale_name) unless /defaultMessages|whitelist|index/.match?(locale_name)
|
2017-12-08 03:07:47 +00:00
|
|
|
end
|
2017-12-11 04:15:09 +00:00
|
|
|
end
|
2022-01-16 20:46:48 +00:00
|
|
|
|
2017-12-11 04:15:09 +00:00
|
|
|
if data['screenshot']
|
|
|
|
if data['screenshot'].is_a? Array
|
|
|
|
screenshots = data['screenshot']
|
|
|
|
else
|
|
|
|
screenshots.push(data['screenshot'])
|
|
|
|
end
|
2017-12-08 03:07:47 +00:00
|
|
|
end
|
2022-01-16 20:46:48 +00:00
|
|
|
|
|
|
|
data['name'] = name
|
|
|
|
data['locales'] = locales
|
|
|
|
data['screenshot'] = screenshots
|
2024-04-27 21:34:41 +01:00
|
|
|
data['skins'] = []
|
|
|
|
@flavours[name] = data
|
2017-09-26 03:24:32 +01:00
|
|
|
end
|
2017-11-21 06:13:37 +00:00
|
|
|
|
2023-04-09 10:25:30 +01: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
|
2024-04-27 21:34:41 +01:00
|
|
|
next unless @flavours[name]
|
2022-01-16 20:46:48 +00:00
|
|
|
|
2023-04-09 10:25:30 +01:00
|
|
|
if pathname.directory?
|
2024-04-27 21:34:41 +01:00
|
|
|
@flavours[name]['skins'] << skin if pathname.glob('{common,index,application}.{css,scss}').any?
|
2023-04-09 10:25:30 +01:00
|
|
|
elsif /^\.s?css$/i.match?(ext)
|
2024-04-27 21:34:41 +01:00
|
|
|
@flavours[name]['skins'] << pathname.basename(ext).to_s
|
2022-01-16 20:46:48 +00:00
|
|
|
end
|
2017-12-01 03:29:47 +00:00
|
|
|
end
|
2017-11-21 06:13:37 +00:00
|
|
|
end
|
|
|
|
|
2017-12-04 07:26:40 +00:00
|
|
|
def flavour(name)
|
2024-04-27 21:34:41 +01:00
|
|
|
@flavours[name]
|
2017-11-17 05:35:25 +00:00
|
|
|
end
|
|
|
|
|
2017-12-04 07:26:40 +00:00
|
|
|
def flavours
|
2024-04-27 21:34:41 +01:00
|
|
|
@flavours.keys
|
2017-09-26 03:24:32 +01:00
|
|
|
end
|
2017-12-01 03:29:47 +00:00
|
|
|
|
|
|
|
def skins_for(name)
|
2024-05-01 13:06:09 +01:00
|
|
|
skins = @flavours[name]['skins']
|
|
|
|
skins.include?('default') && skins.include?('mastodon-light') ? ['system'] + skins : skins
|
2017-12-01 03:29:47 +00:00
|
|
|
end
|
2018-10-08 14:00:27 +01:00
|
|
|
|
|
|
|
def flavours_and_skins
|
|
|
|
flavours.map do |flavour|
|
2023-04-09 10:25:30 +01:00
|
|
|
[flavour, skins_for(flavour).map { |skin| [flavour, skin] }]
|
2018-10-08 14:00:27 +01:00
|
|
|
end
|
|
|
|
end
|
2017-09-26 03:24:32 +01:00
|
|
|
end
|