diff --git a/Gemfile b/Gemfile index 05fc760bc..3a1b44c26 100644 --- a/Gemfile +++ b/Gemfile @@ -59,7 +59,7 @@ gem 'redis', :require => ["redis", "redis/connection/hiredis"] gem 'active_model_serializers' -gem 'truncate_html' +gem 'html_truncator' # we had issues with latest, stick to the rev till we figure this out # PR that makes it all hang together welcome diff --git a/Gemfile_rails4.lock b/Gemfile_rails4.lock index 3a5acf86b..09232ea9b 100644 --- a/Gemfile_rails4.lock +++ b/Gemfile_rails4.lock @@ -208,6 +208,8 @@ GEM highline (1.6.20) hike (1.2.3) hiredis (0.4.5) + html_truncator (0.3.1) + nokogiri (~> 1.5) httpauth (0.2.0) i18n (0.6.5) ice_cube (0.11.0) @@ -442,7 +444,6 @@ GEM polyglot polyglot (>= 0.3.1) trollop (2.0) - truncate_html (0.9.2) tzinfo (0.3.38) uglifier (2.3.1) execjs (>= 0.3.0) @@ -484,6 +485,7 @@ DEPENDENCIES handlebars-source (= 1.0.12) highline hiredis + html_truncator image_optim image_sorcery librarian (>= 0.0.25) @@ -544,7 +546,6 @@ DEPENDENCIES therubyracer thin timecop - truncate_html uglifier unf unicorn diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 08939cf46..9ba6c9849 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -30,7 +30,6 @@ module UserNotificationsHelper end def email_excerpt(html) - html_string = TruncateHtml::HtmlString.new(html) - raw Sanitize.clean(TruncateHtml::HtmlTruncator.new(html_string, length: 1000).truncate, Sanitize::Config::RELAXED) + raw Sanitize.clean(HTML_Truncator.truncate(html, 300), Sanitize::Config::RELAXED) end end diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 957952bfc..d269bfce5 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -34,7 +34,9 @@ module Email renderer = Email::Renderer.new(@message, opts) - unless @message.html_part + if @message.html_part + @message.html_part.body = renderer.html + else @message.html_part = Mail::Part.new do content_type 'text/html; charset=UTF-8' body renderer.html diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 6dd86133b..041ac01e2 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -59,6 +59,10 @@ 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%') + + style('pre', 'white-space: pre-wrap') + style('code', 'background-color: f1f1ff; padding: 2px 5px;') + style('pre code', 'display: block; background-color: f1f1ff; padding: 5px') end def to_html