FIX: Code and Emoticon formatting in HTML emails.

This commit is contained in:
Robin Ward
2013-11-28 17:20:56 -05:00
parent 4ec0543362
commit 8c8645f158
11 changed files with 100 additions and 43 deletions

View File

@ -9,32 +9,22 @@ module Email
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
return @text if @text
@text = (@message.text_part ? @message.text_part : @message).body.to_s.force_encoding('UTF-8')
end
def html
style = Email::Styles.new(PrettyText.cook(text))
style.format_basic
if @opts[:html_template]
if @message.html_part
style = Email::Styles.new(@message.html_part.body.to_s)
style.format_basic
style.format_html
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
template: 'email/template',
format: :html,
locals: { html_body: style.to_html, logo_url: logo_url }
)
else
style.to_html
style = Email::Styles.new(PrettyText.cook(text))
style.format_basic
end
style.to_html
end
end

View File

@ -21,15 +21,17 @@ module Email
def send
return if @message.blank?
return if @message.to.blank?
return if @message.body.blank?
if @message.text_part
return if @message.text_part.body.to_s.blank?
else
return if @message.body.to_s.blank?
end
@message.charset = 'UTF-8'
opts = {}
# Only use the html template on digest emails
opts[:html_template] = true if (@email_type == 'digest')
renderer = Email::Renderer.new(@message, opts)
unless @message.html_part

View File

@ -13,7 +13,9 @@ module Email
def format_basic
@fragment.css('img').each do |img|
if img['src'] =~ /\/assets\/emoji\//
next if img['class'] == 'site-logo'
if img['class'] == "emoji" || img['src'] =~ /plugins\/emoji/
img['width'] = 20
img['height'] = 20
else
@ -57,11 +59,6 @@ module Email
style('div.digest-post', 'margin-left: 15px; margin-top: 20px; max-width: 694px;')
style('div.digest-post h1', 'font-size: 20px;')
style('span.footer-notice', 'color:#666; font-size:80%')
@fragment.css('pre').each do |pre|
pre.replace(pre.text)
end
end
def to_html