mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 20:51:50 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
57 lines
941 B
Ruby
57 lines
941 B
Ruby
# frozen_string_literal: true
|
|
|
|
class WizardFieldChoiceSerializer < ApplicationSerializer
|
|
attributes :id, :label, :extra_label, :description, :icon, :data
|
|
|
|
def id
|
|
object.id
|
|
end
|
|
|
|
def i18nkey
|
|
field = object.field
|
|
step = field.step
|
|
"wizard.step.#{step.id}.fields.#{field.id}.choices.#{id}"
|
|
end
|
|
|
|
def label
|
|
return object.label if object.label.present?
|
|
|
|
# Try getting one from a translation
|
|
I18n.t("#{i18nkey}.label", default: id)
|
|
end
|
|
|
|
def extra_label
|
|
object.extra_label
|
|
end
|
|
|
|
def include_extra_label?
|
|
object.extra_label.present?
|
|
end
|
|
|
|
def description
|
|
I18n.t("#{i18nkey}.description", default: "")
|
|
end
|
|
|
|
def include_description?
|
|
description.present?
|
|
end
|
|
|
|
def icon
|
|
object.icon
|
|
end
|
|
|
|
def include_icon?
|
|
object.icon.present?
|
|
end
|
|
|
|
def data
|
|
result = object.data.dup
|
|
result.delete(:id)
|
|
result
|
|
end
|
|
|
|
def include_data?
|
|
object.data.present?
|
|
end
|
|
end
|