2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-05 08:04:23 +08:00
|
|
|
class ThemeSettingsSerializer < ApplicationSerializer
|
2018-08-04 04:41:37 +08:00
|
|
|
attributes :setting,
|
|
|
|
:type,
|
|
|
|
:default,
|
|
|
|
:value,
|
|
|
|
:description,
|
2024-03-15 07:47:42 +08:00
|
|
|
:objects_schema_property_descriptions,
|
2018-08-04 04:41:37 +08:00
|
|
|
:valid_values,
|
2021-03-11 09:15:04 +08:00
|
|
|
:list_type,
|
|
|
|
:textarea,
|
2024-03-06 08:24:29 +08:00
|
|
|
:json_schema,
|
|
|
|
:objects_schema
|
2018-03-05 08:04:23 +08:00
|
|
|
|
|
|
|
def setting
|
|
|
|
object.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
object.type_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
object.default
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
object.value
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2024-03-15 07:47:42 +08:00
|
|
|
description_regexp = /^theme_metadata\.settings\.#{setting}(\.description)?$/
|
|
|
|
|
2019-05-31 21:49:59 +08:00
|
|
|
locale_file_description =
|
2024-03-15 07:47:42 +08:00
|
|
|
object.theme.internal_translations.find { |t| t.key.match?(description_regexp) }&.value
|
|
|
|
|
2019-05-31 21:49:59 +08:00
|
|
|
locale_file_description || object.description
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|
|
|
|
|
2024-03-15 07:47:42 +08:00
|
|
|
def objects_schema_property_descriptions
|
|
|
|
locales = {}
|
|
|
|
key = "theme_metadata.settings.#{setting}.schema.properties."
|
|
|
|
|
|
|
|
object.theme.internal_translations.each do |internal_translation|
|
|
|
|
if internal_translation.key.start_with?(key)
|
|
|
|
locales[internal_translation.key.delete_prefix(key)] = internal_translation.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
locales
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_objects_schema_property_descriptions?
|
|
|
|
include_objects_schema?
|
|
|
|
end
|
|
|
|
|
2018-03-05 08:04:23 +08:00
|
|
|
def valid_values
|
|
|
|
object.choices
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_valid_values?
|
|
|
|
object.type == ThemeSetting.types[:enum]
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
2019-05-31 21:49:59 +08:00
|
|
|
description.present?
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|
2018-08-04 04:41:37 +08:00
|
|
|
|
|
|
|
def list_type
|
|
|
|
object.list_type
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_list_type?
|
|
|
|
object.type == ThemeSetting.types[:list]
|
|
|
|
end
|
2019-02-05 22:14:53 +08:00
|
|
|
|
|
|
|
def textarea
|
|
|
|
object.textarea
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_textarea?
|
|
|
|
object.type == ThemeSetting.types[:string]
|
|
|
|
end
|
|
|
|
|
2024-03-06 08:24:29 +08:00
|
|
|
def objects_schema
|
|
|
|
object.schema
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_objects_schema?
|
|
|
|
object.type == ThemeSetting.types[:objects]
|
|
|
|
end
|
|
|
|
|
2021-03-11 09:15:04 +08:00
|
|
|
def json_schema
|
|
|
|
object.json_schema
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_json_schema?
|
|
|
|
object.type == ThemeSetting.types[:string] && object.json_schema.present?
|
|
|
|
end
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|