FIX: sending email wasn't working anymore when a plugin used 'reduce_cooked' (cc @gdpelican)

This commit is contained in:
Régis Hanol 2016-05-21 20:13:00 +02:00
parent feffe23cc5
commit c012b18601
4 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -60,7 +60,7 @@
<span> - </span>
<span><%= I18n.l(post.created_at, format: :long) %></span>
</p>
<%= raw format_for_email(post, false, style: :notification) %>
<%= raw format_for_email(post, false, :notification) %>
<hr />
</div>
<% end %>

View File

@ -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 || {}

View File

@ -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