2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-31 03:05:08 +08:00
|
|
|
require 'erb'
|
|
|
|
|
2017-04-25 03:26:06 +08:00
|
|
|
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)
|
2017-04-27 23:45:49 +08:00
|
|
|
I18n.t("system_messages.private_topic_title", id: topic.id)
|
2017-04-25 03:26:06 +08:00
|
|
|
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
|
|
|
|
|
2020-05-23 12:56:13 +08:00
|
|
|
def email_html_template
|
2020-07-13 22:39:40 +08:00
|
|
|
EmailStyle.new.html
|
2021-07-06 04:40:52 +08:00
|
|
|
.sub('%{email_content}') { capture { yield } }
|
2020-07-13 22:39:40 +08:00
|
|
|
.gsub('%{html_lang}', html_lang)
|
2022-04-21 02:00:04 +08:00
|
|
|
.gsub('%{dark_mode_meta_tags}', dark_mode_meta_tags)
|
|
|
|
.gsub('%{dark_mode_styles}', dark_mode_styles)
|
2020-07-13 22:39:40 +08:00
|
|
|
.html_safe
|
2019-07-31 03:05:08 +08:00
|
|
|
end
|
|
|
|
|
2017-04-25 03:26:06 +08:00
|
|
|
protected
|
|
|
|
|
2022-04-12 01:27:50 +08:00
|
|
|
def dark_mode_meta_tags
|
|
|
|
"
|
|
|
|
<meta name='color-scheme' content='light dark' />
|
|
|
|
<meta name='supported-color-schemes' content='light dark' />
|
|
|
|
"
|
|
|
|
end
|
|
|
|
|
|
|
|
def dark_mode_styles
|
|
|
|
"
|
|
|
|
<style>
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
|
|
html {
|
|
|
|
background: #151515 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
h1,
|
|
|
|
h2,
|
|
|
|
h3,
|
|
|
|
h4,
|
|
|
|
h5,
|
|
|
|
h6,
|
|
|
|
p,
|
2022-04-13 02:13:34 +08:00
|
|
|
span,
|
|
|
|
td {
|
2022-11-05 04:44:49 +08:00
|
|
|
color: inherit !important;
|
2022-04-12 01:27:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-15 04:08:09 +08:00
|
|
|
[data-stripped-secure-media] {
|
|
|
|
border-color: #454545 !important;
|
|
|
|
}
|
|
|
|
|
2022-09-29 07:24:33 +08:00
|
|
|
[data-stripped-secure-upload] {
|
|
|
|
border-color: #454545 !important;
|
|
|
|
}
|
|
|
|
|
2022-04-12 01:27:50 +08:00
|
|
|
[dm='text-color'] {
|
|
|
|
color: #dddddd;
|
|
|
|
}
|
|
|
|
|
|
|
|
[dm='header'] {
|
|
|
|
background: #151515 !important;
|
|
|
|
}
|
|
|
|
|
2022-04-15 03:03:06 +08:00
|
|
|
[dm='topic-body'] {
|
|
|
|
background: #151515 !important;
|
|
|
|
border-bottom: 1px solid #454545 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
[dm='triangle'] {
|
|
|
|
border-top-color: #151515 !important;
|
|
|
|
}
|
|
|
|
|
2022-04-12 01:27:50 +08:00
|
|
|
[dm='body'] {
|
|
|
|
background: #222222 !important;
|
|
|
|
color: #dddddd !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
[dm='body_primary'] {
|
|
|
|
background: #062e3d !important;
|
|
|
|
color: #dddddd !important;
|
|
|
|
}
|
2022-04-15 03:03:06 +08:00
|
|
|
|
|
|
|
[dm='bg'] {
|
2022-04-15 04:08:09 +08:00
|
|
|
background: #323232 !important;
|
2022-04-15 03:03:06 +08:00
|
|
|
border-color: #454545 !important;
|
|
|
|
}
|
2022-04-12 01:27:50 +08:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
"
|
|
|
|
end
|
|
|
|
|
2017-04-25 03:26:06 +08:00
|
|
|
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
|