2013-06-10 14:33:37 -05:00
|
|
|
require_dependency 'email/styles'
|
|
|
|
|
|
|
|
module Email
|
|
|
|
class Renderer
|
|
|
|
|
|
|
|
def initialize(message, opts=nil)
|
|
|
|
@message = message
|
|
|
|
@opts = opts || {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
2013-11-28 16:20:56 -06:00
|
|
|
return @text if @text
|
|
|
|
@text = (@message.text_part ? @message.text_part : @message).body.to_s.force_encoding('UTF-8')
|
2014-10-06 12:57:38 -05:00
|
|
|
@text = CGI.unescapeHTML(@text)
|
2013-06-10 14:33:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def html
|
2013-11-28 16:20:56 -06:00
|
|
|
if @message.html_part
|
|
|
|
style = Email::Styles.new(@message.html_part.body.to_s)
|
|
|
|
style.format_basic
|
2013-06-13 11:15:05 -05:00
|
|
|
style.format_html
|
2013-06-10 14:33:37 -05:00
|
|
|
else
|
2013-11-28 16:20:56 -06:00
|
|
|
style = Email::Styles.new(PrettyText.cook(text))
|
|
|
|
style.format_basic
|
2013-06-10 14:33:37 -05:00
|
|
|
end
|
2013-11-28 16:20:56 -06:00
|
|
|
|
|
|
|
style.to_html
|
2013-06-10 14:33:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-10-06 12:57:38 -05:00
|
|
|
end
|