restyle all user notification emails to use a custom html template

This commit is contained in:
Sam
2013-07-24 17:13:15 +10:00
parent cb5ce3aab9
commit 366cb13140
7 changed files with 94 additions and 23 deletions

View File

@ -6,7 +6,9 @@ module Email
def build_email(*builder_args)
builder = Email::MessageBuilder.new(*builder_args)
headers(builder.header_args) if builder.header_args.present?
mail(builder.build_args)
mail(builder.build_args).tap { |message|
message.html_part = builder.html_part if message
}
end
end
@ -22,11 +24,12 @@ module Email
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
@template_args[:respond_instructions] =
if allow_reply_by_email?
I18n.t('user_notifications.reply_by_email', @template_args)
else
I18n.t('user_notifications.visit_link_to_respond', @template_args)
end
end
end
@ -36,6 +39,27 @@ module Email
subject
end
def html_part
return unless html_override = @opts[:html_override]
if @opts[:add_unsubscribe_link]
html_override << "<br>".html_safe
if response_instructions = @template_args[:respond_instructions]
html_override << PrettyText.cook(response_instructions).html_safe
end
html_override << PrettyText.cook(I18n.t('unsubscribe_link', template_args)).html_safe
end
styled = Email::Styles.new(html_override)
styled.format_basic
Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body styled.to_html
end
end
def body
body = @opts[:body]
body = I18n.t("#{@opts[:template]}.text_body_template", template_args) if @opts[:template]