mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
Only use HTML templates for the digest email.
This commit is contained in:
@ -30,7 +30,7 @@ class Admin::EmailController < Admin::AdminController
|
|||||||
|
|
||||||
def preview_digest
|
def preview_digest
|
||||||
params.require(:last_seen_at)
|
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)
|
render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<table style="border: 1px solid #ddd;">
|
<table style="border: 1px solid #ddd;" cellspacing="0" cellpadding="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding: 10px 10px; background-color: #eee; border: 1px solid #ddd;">
|
<td style="padding: 10px 10px; background-color: #eee; border: 1px solid #ddd;">
|
||||||
<a href="<%= Discourse.base_url %>">
|
<a href="<%= Discourse.base_url %>">
|
||||||
@ -6,7 +6,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<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) %>
|
<%= raw(html_body) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -2,28 +2,35 @@ require_dependency 'email_styles'
|
|||||||
|
|
||||||
class EmailRenderer
|
class EmailRenderer
|
||||||
|
|
||||||
def initialize(message)
|
def initialize(message, opts=nil)
|
||||||
@message = message
|
@message = message
|
||||||
|
@opts = opts || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
@text ||= @message.body.to_s.force_encoding('UTF-8')
|
@text ||= @message.body.to_s.force_encoding('UTF-8')
|
||||||
end
|
end
|
||||||
|
|
||||||
def html
|
def logo_url
|
||||||
formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
|
|
||||||
|
|
||||||
logo_url = SiteSetting.logo_url
|
logo_url = SiteSetting.logo_url
|
||||||
if logo_url !~ /http(s)?\:\/\//
|
if logo_url !~ /http(s)?\:\/\//
|
||||||
logo_url = "#{Discourse.base_url}#{logo_url}"
|
logo_url = "#{Discourse.base_url}#{logo_url}"
|
||||||
end
|
end
|
||||||
|
logo_url
|
||||||
|
end
|
||||||
|
|
||||||
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
|
def html
|
||||||
template: 'email/template',
|
formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
|
||||||
format: :html,
|
|
||||||
locals: { html_body: formatted_body,
|
if @opts[:html_template]
|
||||||
logo_url: logo_url }
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,14 @@ class EmailSender
|
|||||||
return if @message.body.blank?
|
return if @message.body.blank?
|
||||||
|
|
||||||
@message.charset = 'UTF-8'
|
@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
|
@message.html_part = Mail::Part.new do
|
||||||
content_type 'text/html; charset=UTF-8'
|
content_type 'text/html; charset=UTF-8'
|
||||||
body renderer.html
|
body renderer.html
|
||||||
|
Reference in New Issue
Block a user