forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.rb
38 lines (34 loc) · 900 Bytes
/
renderer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true
module Email
class Renderer
def initialize(message, opts = nil)
@message = message
@opts = opts || {}
end
def text
return @text if @text
@text =
(+(@message.text_part ? @message.text_part : @message).body.to_s).force_encoding("UTF-8")
@text = CGI.unescapeHTML(@text)
end
def html
style =
if @message.html_part
Email::Styles.new(@message.html_part.body.to_s, @opts)
else
unstyled =
UserNotificationRenderer.render(
template: "layouts/email_template",
format: :html,
locals: {
html_body: PrettyText.cook(text).html_safe,
},
)
Email::Styles.new(unstyled, @opts)
end
style.format_basic
style.format_html
style.to_html
end
end
end