2013-06-11 03:33:37 +08:00
|
|
|
require_dependency 'email/styles'
|
|
|
|
|
|
|
|
module Email
|
|
|
|
class Renderer
|
|
|
|
|
|
|
|
def initialize(message, opts=nil)
|
|
|
|
@message = message
|
|
|
|
@opts = opts || {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
|
|
|
@text ||= @message.body.to_s.force_encoding('UTF-8')
|
|
|
|
end
|
|
|
|
|
|
|
|
def logo_url
|
|
|
|
logo_url = SiteSetting.logo_url
|
|
|
|
if logo_url !~ /http(s)?\:\/\//
|
|
|
|
logo_url = "#{Discourse.base_url}#{logo_url}"
|
|
|
|
end
|
|
|
|
logo_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def html
|
2013-06-14 00:15:05 +08:00
|
|
|
style = Email::Styles.new(PrettyText.cook(text))
|
|
|
|
style.format_basic
|
2013-06-11 03:33:37 +08:00
|
|
|
|
|
|
|
if @opts[:html_template]
|
2013-06-14 00:15:05 +08:00
|
|
|
style.format_html
|
|
|
|
|
2013-06-11 03:33:37 +08:00
|
|
|
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
|
|
|
|
template: 'email/template',
|
|
|
|
format: :html,
|
2013-06-14 00:15:05 +08:00
|
|
|
locals: { html_body: style.to_html, logo_url: logo_url }
|
2013-06-11 03:33:37 +08:00
|
|
|
)
|
|
|
|
else
|
2013-06-14 00:15:05 +08:00
|
|
|
style.to_html
|
2013-06-11 03:33:37 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|