Make email_excerpt method take an optional post param (#7570)

The spoiler alert plugin replaces spoiler text found in email excerpts with posts URL, which means it needs to have a reference to the post it's processing.

This change makes `email_excerpt` accepts an optional post param, which calls `PrettyText.format_for_email` which then triggers the `reduce_cooked` event that the plugin subscribes to.
This commit is contained in:
Osama Sayegh 2019-05-20 11:04:23 +03:00 committed by Régis Hanol
parent 50e6ee55a9
commit 14bae6d52d
3 changed files with 4 additions and 4 deletions

View File

@ -51,9 +51,9 @@ module UserNotificationsHelper
doc.css('div').first
end
def email_excerpt(html_arg)
def email_excerpt(html_arg, post = nil)
html = (first_paragraphs_from(html_arg) || html_arg).to_s
PrettyText.format_for_email(html).html_safe
PrettyText.format_for_email(html, post).html_safe
end
def normalize_name(name)

View File

@ -205,7 +205,7 @@ class UserNotifications < ActionMailer::Base
@excerpts = {}
@popular_topics.map do |t|
@excerpts[t.first_post.id] = email_excerpt(t.first_post.cooked) if t.first_post.present?
@excerpts[t.first_post.id] = email_excerpt(t.first_post.cooked, t.first_post) if t.first_post.present?
end
# Try to find 3 interesting stats for the top of the digest

View File

@ -248,7 +248,7 @@ body, table, td, th, h1, h2, h3 {font-family: Helvetica, Arial, sans-serif !impo
<tbody>
<tr>
<td class="post-excerpt" style="color:#0a0a0a;font-size:14px;font-weight:normal;padding:16px;text-align:<%= rtl? ? 'right' : 'left' %>;width:100%;">
<%= email_excerpt(post.cooked) %>
<%= email_excerpt(post.cooked, post) %>
</td>
</tr>
</tbody>