discourse/lib/email/renderer.rb

32 lines
674 B
Ruby
Raw Normal View History

2013-06-10 14:33:37 -05:00
require_dependency 'email/styles'
module Email
class Renderer
2017-07-27 20:20:09 -05:00
def initialize(message, opts = nil)
2013-06-10 14:33:37 -05: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-10 14:33:37 -05:00
end
def html
if @message.html_part
style = Email::Styles.new(@message.html_part.body.to_s, @opts)
style.format_basic
style.format_html
2013-06-10 14:33:37 -05:00
else
style = Email::Styles.new(PrettyText.cook(text), @opts)
style.format_basic
2013-06-10 14:33:37 -05:00
end
style.to_html
2013-06-10 14:33:37 -05:00
end
end
end