mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 10:41:25 +08:00
DEV: Refactor subclasses in ThemeSettingsManager
to individual files (#25605)
Why this change? One Ruby class per file improves readability
This commit is contained in:

committed by
GitHub

parent
7ce76143ac
commit
fb0e656cb7
46
lib/theme_settings_manager/upload.rb
Normal file
46
lib/theme_settings_manager/upload.rb
Normal file
@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ThemeSettingsManager::Upload < ThemeSettingsManager
|
||||
def value
|
||||
has_record? ? cdn_url(db_record.value) : default
|
||||
end
|
||||
|
||||
def default
|
||||
upload_id = default_upload_id
|
||||
return if upload_id.blank?
|
||||
|
||||
cdn_url(upload_id)
|
||||
end
|
||||
|
||||
def value=(new_value)
|
||||
if new_value.present?
|
||||
if new_value == default
|
||||
new_value = default_upload_id
|
||||
else
|
||||
upload = ::Upload.find_by(url: new_value)
|
||||
new_value = upload.id if upload.present?
|
||||
end
|
||||
end
|
||||
|
||||
super(new_value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cdn_url(upload_id)
|
||||
return if upload_id.blank?
|
||||
|
||||
upload = ::Upload.find_by_id(upload_id.to_i)
|
||||
return if upload.blank?
|
||||
|
||||
Discourse.store.cdn_url(upload.url)
|
||||
end
|
||||
|
||||
def default_upload_id
|
||||
theme_field =
|
||||
theme.theme_fields.find_by(name: @default, type_id: ThemeField.types[:theme_upload_var])
|
||||
return if theme_field.blank?
|
||||
|
||||
theme_field.upload_id
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user