discourse/lib/email/renderer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
816 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2013-06-11 03:33:37 +08:00
module Email
class Renderer
2017-07-28 09:20:09 +08:00
def initialize(message, opts = nil)
2013-06-11 03:33:37 +08:00
@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)
2013-06-11 03:33:37 +08:00
end
def html
style = if @message.html_part
Email::Styles.new(@message.html_part.body.to_s, @opts)
2013-06-11 03:33:37 +08:00
else
unstyled = UserNotificationRenderer.render(
template: 'layouts/email_template',
format: :html,
locals: { html_body: PrettyText.cook(text).html_safe }
)
Email::Styles.new(unstyled, @opts)
2013-06-11 03:33:37 +08:00
end
style.format_basic
style.format_html
style.to_html
2013-06-11 03:33:37 +08:00
end
end
end