From c012b18601e9b79ed64e713a043bdfd707985727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 21 May 2016 20:13:00 +0200 Subject: [PATCH] FIX: sending email wasn't working anymore when a plugin used 'reduce_cooked' (cc @gdpelican) --- app/helpers/user_notifications_helper.rb | 4 ++-- app/views/user_notifications/mailing_list.html.erb | 2 +- lib/email/styles.rb | 4 ++++ lib/pretty_text.rb | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 39553ffcab4..afa80d832a1 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -65,9 +65,9 @@ module UserNotificationsHelper normalize_name(post.user.name) != normalize_name(post.user.username) end - def format_for_email(post, use_excerpt, style: nil) + def format_for_email(post, use_excerpt, style = nil) html = use_excerpt ? post.excerpt : post.cooked - PrettyText.format_for_email(html, post, style: style).html_safe + PrettyText.format_for_email(html, post, style).html_safe end end diff --git a/app/views/user_notifications/mailing_list.html.erb b/app/views/user_notifications/mailing_list.html.erb index efd6ac3df8b..2cd21164505 100644 --- a/app/views/user_notifications/mailing_list.html.erb +++ b/app/views/user_notifications/mailing_list.html.erb @@ -60,7 +60,7 @@ - <%= I18n.l(post.created_at, format: :long) %>

- <%= raw format_for_email(post, false, style: :notification) %> + <%= raw format_for_email(post, false, :notification) %>
<% end %> diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 25076ab72f0..0156fe06438 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -6,6 +6,10 @@ module Email class Styles @@plugin_callbacks = [] + attr_accessor :fragment + + delegate :css, to: :fragment + def initialize(html, opts=nil) @html = html @opts = opts || {} diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 5ff3c054f10..e3e5cc756b8 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -390,11 +390,11 @@ module PrettyText doc.css(".lightbox-wrapper .meta").remove end - def self.format_for_email(html, post = nil, style: nil) + def self.format_for_email(html, post = nil, style = nil) Email::Styles.new(html, style: style).tap do |doc| + DiscourseEvent.trigger(:reduce_cooked, doc, post) doc.make_all_links_absolute doc.send :"format_#{style}" if style - DiscourseEvent.trigger(:reduce_cooked, doc, post) end.to_html end