mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 04:33:45 +08:00
9656a21fdb
This feature adds the ability to customize the HTML part of all emails using a custom HTML template and optionally some CSS to style it. The CSS will be parsed and converted into inline styles because CSS is poorly supported by email clients. When writing the custom HTML and CSS, be aware of what email clients support. Keep customizations very simple. Customizations can be added and edited in Admin > Customize > Email Style. Since the summary email is already heavily styled, there is a setting to disable custom styles for summary emails called "apply custom styles to digest" found in Admin > Settings > Email. As part of this work, RTL locales are now rendered correctly for all emails.
51 lines
1.2 KiB
Ruby
51 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'erb'
|
|
|
|
module EmailHelper
|
|
|
|
def mailing_list_topic(topic, post_count)
|
|
render(
|
|
partial: partial_for("mailing_list_post"),
|
|
locals: { topic: topic, post_count: post_count }
|
|
)
|
|
end
|
|
|
|
def mailing_list_topic_text(topic)
|
|
url, title = extract_details(topic)
|
|
raw(@markdown_linker.create(title, url))
|
|
end
|
|
|
|
def private_topic_title(topic)
|
|
I18n.t("system_messages.private_topic_title", id: topic.id)
|
|
end
|
|
|
|
def email_topic_link(topic)
|
|
url, title = extract_details(topic)
|
|
raw "<a href='#{Discourse.base_url}#{url}' style='color: ##{@anchor_color}'>#{title}</a>"
|
|
end
|
|
|
|
def email_html_template(binding_arg)
|
|
template = EmailStyle.new.html.sub(
|
|
'%{email_content}',
|
|
'<%= yield %><% if defined?(html_body) %><%= html_body %><% end %>'
|
|
)
|
|
ERB.new(template).result(binding_arg)
|
|
end
|
|
|
|
protected
|
|
|
|
def extract_details(topic)
|
|
if SiteSetting.private_email?
|
|
[topic.slugless_url, private_topic_title(topic)]
|
|
else
|
|
[topic.relative_url, format_topic_title(topic.title)]
|
|
end
|
|
end
|
|
|
|
def partial_for(name)
|
|
SiteSetting.private_email? ? "email/secure_#{name}" : "email/#{name}"
|
|
end
|
|
|
|
end
|