mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 16:48:03 +08:00
DEV: Apply syntax_tree formatting to app/*
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
class ThemeModifierSet < ActiveRecord::Base
|
||||
class ThemeModifierSetError < StandardError; end
|
||||
class ThemeModifierSetError < StandardError
|
||||
end
|
||||
|
||||
belongs_to :theme
|
||||
|
||||
@ -26,12 +27,8 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
end
|
||||
|
||||
after_save do
|
||||
if saved_change_to_svg_icons?
|
||||
SvgSprite.expire_cache
|
||||
end
|
||||
if saved_change_to_csp_extensions?
|
||||
CSP::Extension.clear_theme_extensions_cache!
|
||||
end
|
||||
SvgSprite.expire_cache if saved_change_to_svg_icons?
|
||||
CSP::Extension.clear_theme_extensions_cache! if saved_change_to_csp_extensions?
|
||||
end
|
||||
|
||||
# Given the ids of multiple active themes / theme components, this function
|
||||
@ -39,7 +36,11 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
def self.resolve_modifier_for_themes(theme_ids, modifier_name)
|
||||
return nil if !(config = self.modifiers[modifier_name])
|
||||
|
||||
all_values = self.where(theme_id: theme_ids).where.not(modifier_name => nil).map { |s| s.public_send(modifier_name) }
|
||||
all_values =
|
||||
self
|
||||
.where(theme_id: theme_ids)
|
||||
.where.not(modifier_name => nil)
|
||||
.map { |s| s.public_send(modifier_name) }
|
||||
case config[:type]
|
||||
when :boolean
|
||||
all_values.any?
|
||||
@ -55,17 +56,21 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
|
||||
return if array.nil?
|
||||
|
||||
array.map do |dimension|
|
||||
parts = dimension.split("x")
|
||||
next if parts.length != 2
|
||||
[parts[0].to_i, parts[1].to_i]
|
||||
end.filter(&:present?)
|
||||
array
|
||||
.map do |dimension|
|
||||
parts = dimension.split("x")
|
||||
next if parts.length != 2
|
||||
[parts[0].to_i, parts[1].to_i]
|
||||
end
|
||||
.filter(&:present?)
|
||||
end
|
||||
|
||||
def topic_thumbnail_sizes=(val)
|
||||
return write_attribute(:topic_thumbnail_sizes, val) if val.nil?
|
||||
return write_attribute(:topic_thumbnail_sizes, val) if !val.is_a?(Array)
|
||||
return write_attribute(:topic_thumbnail_sizes, val) if !val.all? { |v| v.is_a?(Array) && v.length == 2 }
|
||||
if !val.all? { |v| v.is_a?(Array) && v.length == 2 }
|
||||
return write_attribute(:topic_thumbnail_sizes, val)
|
||||
end
|
||||
|
||||
super(val.map { |dim| "#{dim[0]}x#{dim[1]}" })
|
||||
end
|
||||
@ -77,7 +82,7 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
def self.load_modifiers
|
||||
hash = {}
|
||||
columns_hash.each do |column_name, info|
|
||||
next if ["id", "theme_id"].include?(column_name)
|
||||
next if %w[id theme_id].include?(column_name)
|
||||
|
||||
type = nil
|
||||
if info.type == :string && info.array?
|
||||
@ -85,7 +90,9 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
elsif info.type == :boolean && !info.array?
|
||||
type = :boolean
|
||||
else
|
||||
raise ThemeModifierSetError "Invalid theme modifier column type" if ![:boolean, :string].include?(info.type)
|
||||
if !%i[boolean string].include?(info.type)
|
||||
raise ThemeModifierSetError "Invalid theme modifier column type"
|
||||
end
|
||||
end
|
||||
|
||||
hash[column_name.to_sym] = { type: type }
|
||||
|
Reference in New Issue
Block a user