mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 11:43:40 +08:00
89ad2b5900
This updates tests to use latest rails 5 practice and updates ALL dependencies that could be updated Performance testing shows that performance has not regressed if anything it is marginally faster now.
32 lines
674 B
Ruby
32 lines
674 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')
|
|
@text = CGI.unescapeHTML(@text)
|
|
end
|
|
|
|
def html
|
|
if @message.html_part
|
|
style = Email::Styles.new(@message.html_part.body.to_s, @opts)
|
|
style.format_basic
|
|
style.format_html
|
|
else
|
|
style = Email::Styles.new(PrettyText.cook(text), @opts)
|
|
style.format_basic
|
|
end
|
|
|
|
style.to_html
|
|
end
|
|
|
|
end
|
|
end
|