FIX: Emoji sizes in emails should be done by the EmailStyler

This commit is contained in:
Robin Ward
2013-06-13 12:15:05 -04:00
parent 3f03ce3c8c
commit 66f5a3f6f6
5 changed files with 108 additions and 48 deletions

View File

@ -21,16 +21,19 @@ module Email
end
def html
cooked = PrettyText.cook(text)
style = Email::Styles.new(PrettyText.cook(text))
style.format_basic
if @opts[:html_template]
style.format_html
ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
template: 'email/template',
format: :html,
locals: { html_body: Email::Styles.new(cooked).format, logo_url: logo_url }
locals: { html_body: style.to_html, logo_url: logo_url }
)
else
cooked
style.to_html
end
end

View File

@ -7,44 +7,58 @@ module Email
def initialize(html)
@html = html
@fragment = Nokogiri::HTML.fragment(@html)
end
def format
fragment = Nokogiri::HTML.fragment(@html)
def format_basic
@fragment.css('img').each do |img|
fragment.css('h3').each do |h3|
if img['src'] =~ /\/assets\/emoji\//
img['style'] = "width: 20px; height: 20px;"
else
img['style'] = "max-width: 694px;"
end
if img['src'][0] == "/"
img['src'] = "#{Discourse.base_url}#{img['src']}"
end
end
end
def format_html
@fragment.css('h3').each do |h3|
h3['style'] = 'margin: 15px 0 20px 0; border-bottom: 1px solid #ddd;'
end
fragment.css('hr').each do |hr|
@fragment.css('hr').each do |hr|
hr['style'] = 'background-color: #ddd; height: 1px; border: 1px;'
end
fragment.css('img').each do |img|
img['style'] = "max-width: 694px;"
end
fragment.css('a').each do |a|
@fragment.css('a').each do |a|
a['style'] = 'text-decoration: none; font-weight: bold; font-size: 15px; color: #006699;'
end
fragment.css('ul').each do |ul|
@fragment.css('ul').each do |ul|
ul['style'] = 'margin: 0 0 0 10px; padding: 0 0 0 20px;'
end
fragment.css('li').each do |li|
@fragment.css('li').each do |li|
li['style'] = 'padding-bottom: 10px'
end
fragment.css('pre').each do |pre|
@fragment.css('pre').each do |pre|
pre.replace(pre.text)
end
fragment.css('div.digest-post').each do |div|
@fragment.css('div.digest-post').each do |div|
div['style'] = 'margin-left: 15px; margin-top: 20px; max-width: 694px;'
end
end
fragment.to_html
def to_html
@fragment.to_html
end