mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-25 08:39:38 -05:00
31 lines
No EOL
617 B
Ruby
31 lines
No EOL
617 B
Ruby
require_dependency 'email/styles'
|
|
|
|
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')
|
|
end
|
|
|
|
def html
|
|
|
|
if @message.html_part
|
|
style = Email::Styles.new(@message.html_part.body.to_s)
|
|
style.format_basic
|
|
style.format_html
|
|
else
|
|
style = Email::Styles.new(PrettyText.cook(text))
|
|
style.format_basic
|
|
end
|
|
|
|
style.to_html
|
|
end
|
|
|
|
end
|
|
end |