Only use HTML templates for the digest email.
This commit is contained in:
parent
7bc80c2dcf
commit
8f32aed944
|
@ -30,7 +30,7 @@ class Admin::EmailController < Admin::AdminController
|
|||
|
||||
def preview_digest
|
||||
params.require(:last_seen_at)
|
||||
renderer = EmailRenderer.new(UserNotifications.digest(current_user, since: params[:last_seen_at]))
|
||||
renderer = EmailRenderer.new(UserNotifications.digest(current_user, since: params[:last_seen_at]), html_template: true)
|
||||
render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<table style="border: 1px solid #ddd;">
|
||||
<table style="border: 1px solid #ddd;" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td style="padding: 10px 10px; background-color: #eee; border: 1px solid #ddd;">
|
||||
<a href="<%= Discourse.base_url %>">
|
||||
|
@ -6,7 +6,7 @@
|
|||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-color: #fff; padding: 0 10px; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
|
||||
<td style="background-color: #fff; padding: 10px 10px; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
|
||||
<%= raw(html_body) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -2,28 +2,35 @@ require_dependency 'email_styles'
|
|||
|
||||
class EmailRenderer
|
||||
|
||||
def initialize(message)
|
||||
def initialize(message, opts=nil)
|
||||
@message = message
|
||||
@opts = opts || {}
|
||||
end
|
||||
|
||||
def text
|
||||
@text ||= @message.body.to_s.force_encoding('UTF-8')
|
||||
end
|
||||
|
||||
def html
|
||||
formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
|
||||
|
||||
def logo_url
|
||||
logo_url = SiteSetting.logo_url
|
||||
if logo_url !~ /http(s)?\:\/\//
|
||||
logo_url = "#{Discourse.base_url}#{logo_url}"
|
||||
end
|
||||
logo_url
|
||||
end
|
||||
|
||||
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
|
||||
template: 'email/template',
|
||||
format: :html,
|
||||
locals: { html_body: formatted_body,
|
||||
logo_url: logo_url }
|
||||
)
|
||||
def html
|
||||
formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
|
||||
|
||||
if @opts[:html_template]
|
||||
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
|
||||
template: 'email/template',
|
||||
format: :html,
|
||||
locals: { html_body: formatted_body, logo_url: logo_url }
|
||||
)
|
||||
else
|
||||
formatted_body
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -22,7 +22,14 @@ class EmailSender
|
|||
return if @message.body.blank?
|
||||
|
||||
@message.charset = 'UTF-8'
|
||||
renderer = EmailRenderer.new(@message)
|
||||
|
||||
opts = {}
|
||||
|
||||
# Only use the html template on digest emails
|
||||
opts[:html_template] = true if (@email_type == 'digest')
|
||||
|
||||
renderer = EmailRenderer.new(@message, opts)
|
||||
|
||||
@message.html_part = Mail::Part.new do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body renderer.html
|
||||
|
|
Loading…
Reference in New Issue