mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 04:04:21 +08:00
03363d03e8
Previously theme setting descriptions were defined in the `settings.yml` file like this: ``` setting_name: default: "My Default Value" description: en: "English description" fr: "French description" ``` This commit allows developers to store the localised descriptions in the theme locale files instead: ``` en: theme_metadata: description: Theme Description settings: setting_name: "The localised description for setting_name" ```
57 lines
987 B
Ruby
57 lines
987 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsSerializer < ApplicationSerializer
|
|
attributes :setting, :type, :default, :value, :description, :valid_values,
|
|
:list_type, :textarea
|
|
|
|
def setting
|
|
object.name
|
|
end
|
|
|
|
def type
|
|
object.type_name
|
|
end
|
|
|
|
def default
|
|
object.default
|
|
end
|
|
|
|
def value
|
|
object.value
|
|
end
|
|
|
|
def description
|
|
locale_file_description = object.theme.internal_translations.find { |t| t.key == "theme_metadata.settings.#{setting}" } &.value
|
|
locale_file_description || object.description
|
|
end
|
|
|
|
def valid_values
|
|
object.choices
|
|
end
|
|
|
|
def include_valid_values?
|
|
object.type == ThemeSetting.types[:enum]
|
|
end
|
|
|
|
def include_description?
|
|
description.present?
|
|
end
|
|
|
|
def list_type
|
|
object.list_type
|
|
end
|
|
|
|
def include_list_type?
|
|
object.type == ThemeSetting.types[:list]
|
|
end
|
|
|
|
def textarea
|
|
object.textarea
|
|
end
|
|
|
|
def include_textarea?
|
|
object.type == ThemeSetting.types[:string]
|
|
end
|
|
|
|
end
|