mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Code review comments.
This commit is contained in:
@@ -173,6 +173,8 @@ module Stylesheet
|
||||
end
|
||||
|
||||
def theme_import(target)
|
||||
return "" if !@theme_id
|
||||
|
||||
attr = target == :embedded_theme ? :embedded_scss : :scss
|
||||
target = target.to_s.gsub("_theme", "").to_sym
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class Stylesheet::Manager
|
||||
attr_reader :theme_ids
|
||||
|
||||
def initialize(theme_id: nil)
|
||||
@theme_id = theme_id || SiteSetting.default_theme_id
|
||||
@theme_id = theme_id
|
||||
@theme_ids = Theme.transform_ids(@theme_id)
|
||||
@themes_cache = {}
|
||||
end
|
||||
@@ -218,16 +218,23 @@ class Stylesheet::Manager
|
||||
|
||||
scss_checker = ScssChecker.new(target, stale_theme_ids)
|
||||
|
||||
load_themes(stale_theme_ids).each do |theme|
|
||||
theme_id = theme.id
|
||||
themes = @theme_id.blank? ? [nil] : load_themes(stale_theme_ids)
|
||||
|
||||
themes.each do |theme|
|
||||
theme_id = theme&.id
|
||||
data = { target: target, theme_id: theme_id }
|
||||
builder = Builder.new(target: target, theme: theme, manager: self)
|
||||
is_theme = builder.is_theme?
|
||||
has_theme = builder.theme.present?
|
||||
|
||||
next if builder.theme.component && !scss_checker.has_scss(theme_id)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
|
||||
cache.defer_set("path_#{target}_#{theme_id}_#{current_hostname}", href)
|
||||
if is_theme && !has_theme
|
||||
next
|
||||
else
|
||||
next if builder.theme&.component && !scss_checker.has_scss(theme_id)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
cache.defer_set("path_#{target}_#{theme_id}_#{current_hostname}", href)
|
||||
end
|
||||
|
||||
data[:new_href] = href
|
||||
stylesheets << data
|
||||
@@ -239,7 +246,7 @@ class Stylesheet::Manager
|
||||
end
|
||||
|
||||
def color_scheme_stylesheet_details(color_scheme_id = nil, media)
|
||||
theme_id = @theme_ids.first
|
||||
theme_id = @theme_id || SiteSetting.default_theme_id
|
||||
|
||||
color_scheme = begin
|
||||
ColorScheme.find(color_scheme_id)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class Stylesheet::Manager::Builder
|
||||
attr_reader :theme
|
||||
|
||||
def initialize(target: :desktop, theme:, color_scheme: nil, manager:)
|
||||
def initialize(target: :desktop, theme: nil, color_scheme: nil, manager:)
|
||||
@target = target
|
||||
@theme = theme
|
||||
@color_scheme = color_scheme
|
||||
@@ -115,11 +115,11 @@ class Stylesheet::Manager::Builder
|
||||
|
||||
def qualified_target
|
||||
if is_theme?
|
||||
"#{@target}_#{theme.id}"
|
||||
"#{@target}_#{theme&.id}"
|
||||
elsif @color_scheme
|
||||
"#{@target}_#{scheme_slug}_#{@color_scheme&.id.to_s}"
|
||||
else
|
||||
scheme_string = theme && theme.color_scheme ? "_#{theme.color_scheme.id}" : ""
|
||||
scheme_string = theme&.color_scheme ? "_#{theme.color_scheme.id}" : ""
|
||||
"#{@target}#{scheme_string}"
|
||||
end
|
||||
end
|
||||
@@ -186,10 +186,10 @@ class Stylesheet::Manager::Builder
|
||||
end
|
||||
|
||||
def settings_digest
|
||||
theme_ids = Theme.is_parent_theme?(theme.id) ? @manager.theme_ids : [theme.id]
|
||||
|
||||
themes =
|
||||
if Theme.is_parent_theme?(theme.id)
|
||||
if !theme
|
||||
[]
|
||||
elsif Theme.is_parent_theme?(theme.id)
|
||||
@manager.load_themes(@manager.theme_ids)
|
||||
else
|
||||
[@manager.get_theme(theme.id)]
|
||||
@@ -211,7 +211,7 @@ class Stylesheet::Manager::Builder
|
||||
def uploads_digest
|
||||
sha1s = []
|
||||
|
||||
theme.upload_fields.map do |upload_field|
|
||||
(theme&.upload_fields || []).map do |upload_field|
|
||||
sha1s << upload_field.upload.sha1
|
||||
end
|
||||
|
||||
@@ -247,7 +247,9 @@ class Stylesheet::Manager::Builder
|
||||
|
||||
def resolve_baked_field(target, name)
|
||||
theme_ids =
|
||||
if Theme.is_parent_theme?(theme.id)
|
||||
if !theme
|
||||
[]
|
||||
elsif Theme.is_parent_theme?(theme.id)
|
||||
@manager.theme_ids
|
||||
else
|
||||
[theme.id]
|
||||
|
||||
@@ -358,7 +358,7 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
def self.search(searched_icon)
|
||||
searched_icon = process(searched_icon.dup)
|
||||
|
||||
sprite_sources([SiteSetting.default_theme_id]).each do |fname|
|
||||
sprite_sources(SiteSetting.default_theme_id).each do |fname|
|
||||
next if !File.exist?(fname)
|
||||
|
||||
svg_file = Nokogiri::XML(File.open(fname))
|
||||
@@ -381,7 +381,7 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
def self.icon_picker_search(keyword)
|
||||
results = Set.new
|
||||
|
||||
sprite_sources([SiteSetting.default_theme_id]).each do |fname|
|
||||
sprite_sources(SiteSetting.default_theme_id).each do |fname|
|
||||
next if !File.exist?(fname)
|
||||
|
||||
svg_file = Nokogiri::XML(File.open(fname))
|
||||
@@ -465,9 +465,10 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
return [] if theme_id.blank?
|
||||
|
||||
theme_icon_settings = []
|
||||
theme_ids = Theme.transform_ids(theme_id)
|
||||
|
||||
# Need to load full records for default values
|
||||
Theme.where(id: Theme.transform_ids(theme_id)).each do |theme|
|
||||
Theme.where(id: theme_ids).each do |theme|
|
||||
settings = theme.cached_settings.each do |key, value|
|
||||
if key.to_s.include?("_icon") && String === value
|
||||
theme_icon_settings |= value.split('|')
|
||||
@@ -475,7 +476,7 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
end
|
||||
end
|
||||
|
||||
theme_icon_settings |= ThemeModifierHelper.new(theme_ids: [theme_id]).svg_icons
|
||||
theme_icon_settings |= ThemeModifierHelper.new(theme_ids: theme_ids).svg_icons
|
||||
|
||||
theme_icon_settings
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
class ThemeModifierHelper
|
||||
def initialize(request: nil, theme_ids: nil)
|
||||
@theme_ids = theme_ids || [request&.env&.[](:resolved_theme_id)]
|
||||
@theme_ids = theme_ids || Theme.transform_ids(request&.env&.[](:resolved_theme_id))
|
||||
end
|
||||
|
||||
ThemeModifierSet.modifiers.keys.each do |modifier|
|
||||
|
||||
Reference in New Issue
Block a user