discourse/app/serializers/admin_email_template_serial...

37 lines
789 B
Ruby
Raw Normal View History

class AdminEmailTemplateSerializer < ApplicationSerializer
2015-11-20 12:30:04 -05:00
attributes :id, :title, :subject, :body, :can_revert?
def id
object
end
def title
if I18n.exists?("#{object}.title")
I18n.t("#{object}.title")
else
object.gsub(/.*\./, '').titleize
end
end
def subject
if I18n.exists?("#{object}.subject_template.other")
@subject = nil
else
@subject ||= I18n.t("#{object}.subject_template")
end
end
def body
2015-11-20 12:30:04 -05:00
@body ||= I18n.t("#{object}.text_body_template")
end
def can_revert?
current_body, current_subject = body, subject
I18n.overrides_disabled do
return I18n.t("#{object}.subject_template") != current_subject ||
I18n.t("#{object}.text_body_template") != current_body
end
end
end