2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-10 15:33:37 -04:00
|
|
|
require_dependency 'email/styles'
|
|
|
|
|
|
|
|
module Email
|
|
|
|
class Renderer
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
def initialize(message, opts = nil)
|
2013-06-10 15:33:37 -04:00
|
|
|
@message = message
|
|
|
|
@opts = opts || {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
2013-11-28 17:20:56 -05:00
|
|
|
return @text if @text
|
2018-06-05 03:29:17 -04:00
|
|
|
@text = (+(@message.text_part ? @message.text_part : @message).body.to_s).force_encoding('UTF-8')
|
2014-10-06 13:57:38 -04:00
|
|
|
@text = CGI.unescapeHTML(@text)
|
2013-06-10 15:33:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def html
|
2019-07-30 15:05:08 -04:00
|
|
|
style = if @message.html_part
|
|
|
|
Email::Styles.new(@message.html_part.body.to_s, @opts)
|
2013-06-10 15:33:37 -04:00
|
|
|
else
|
2019-07-30 15:05:08 -04:00
|
|
|
unstyled = UserNotificationRenderer.with_view_paths(
|
|
|
|
Rails.configuration.paths["app/views"]
|
|
|
|
).render(
|
|
|
|
template: 'layouts/email_template',
|
|
|
|
format: :html,
|
|
|
|
locals: { html_body: PrettyText.cook(text).html_safe }
|
|
|
|
)
|
|
|
|
Email::Styles.new(unstyled, @opts)
|
2013-06-10 15:33:37 -04:00
|
|
|
end
|
2013-11-28 17:20:56 -05:00
|
|
|
|
2019-07-30 15:05:08 -04:00
|
|
|
style.format_basic
|
|
|
|
style.format_html
|
2013-11-28 17:20:56 -05:00
|
|
|
style.to_html
|
2013-06-10 15:33:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-10-06 13:57:38 -04:00
|
|
|
end
|