Determine template_args only once per instance
This commit is contained in:
parent
112b9f9c2a
commit
ea51f0fe04
|
@ -11,10 +11,23 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
class MessageBuilder
|
class MessageBuilder
|
||||||
|
attr_reader :template_args
|
||||||
|
|
||||||
def initialize(to, opts=nil)
|
def initialize(to, opts=nil)
|
||||||
@to = to
|
@to = to
|
||||||
@opts = opts || {}
|
@opts = opts || {}
|
||||||
|
|
||||||
|
@template_args = {site_name: SiteSetting.title,
|
||||||
|
base_url: Discourse.base_url,
|
||||||
|
user_preferences_url: "#{Discourse.base_url}/user_preferences" }.merge!(@opts)
|
||||||
|
|
||||||
|
if @template_args[:url].present?
|
||||||
|
if allow_reply_by_email?
|
||||||
|
@template_args[:respond_instructions] = I18n.t('user_notifications.reply_by_email', @template_args)
|
||||||
|
else
|
||||||
|
@template_args[:respond_instructions] = I18n.t('user_notifications.visit_link_to_respond', @template_args)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def subject
|
def subject
|
||||||
|
@ -35,22 +48,6 @@ module Email
|
||||||
body
|
body
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_args
|
|
||||||
@template_args ||= { site_name: SiteSetting.title,
|
|
||||||
base_url: Discourse.base_url,
|
|
||||||
user_preferences_url: "#{Discourse.base_url}/user_preferences" }.merge!(@opts)
|
|
||||||
|
|
||||||
if @template_args[:url].present?
|
|
||||||
if allow_reply_by_email? and
|
|
||||||
@template_args[:respond_instructions] = I18n.t('user_notifications.reply_by_email', @template_args)
|
|
||||||
else
|
|
||||||
@template_args[:respond_instructions] = I18n.t('user_notifications.visit_link_to_respond', @template_args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@template_args
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_args
|
def build_args
|
||||||
{ to: @to,
|
{ to: @to,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
|
|
Loading…
Reference in New Issue