mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 22:46:29 +08:00
FIX: Provide the ability to reduce
cooked content
This allows us to strip polls from the group posts page.
This commit is contained in:
parent
8fcd359e2a
commit
e91379916b
@ -51,7 +51,7 @@ module UserNotificationsHelper
|
|||||||
def email_excerpt(html, posts_count)
|
def email_excerpt(html, posts_count)
|
||||||
# only include 1st paragraph when more than 1 posts
|
# only include 1st paragraph when more than 1 posts
|
||||||
html = first_paragraph_from(html).to_s if posts_count > 1
|
html = first_paragraph_from(html).to_s if posts_count > 1
|
||||||
raw format_for_email(html)
|
PrettyText.format_for_email(html).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_name(name)
|
def normalize_name(name)
|
||||||
@ -65,8 +65,9 @@ module UserNotificationsHelper
|
|||||||
normalize_name(post.user.name) != normalize_name(post.user.username)
|
normalize_name(post.user.name) != normalize_name(post.user.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_for_email(html)
|
def format_for_email(post, use_excerpt)
|
||||||
PrettyText.format_for_email(html).html_safe
|
html = use_excerpt ? post.excerpt : post.cooked
|
||||||
|
PrettyText.format_for_email(html, post).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,12 @@ class GroupPostSerializer < ApplicationSerializer
|
|||||||
object.topic
|
object.topic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cooked
|
||||||
|
fragment = Nokogiri::HTML.fragment(object.cooked)
|
||||||
|
DiscourseEvent.trigger(:reduce_cooked, fragment, object)
|
||||||
|
fragment.to_html
|
||||||
|
end
|
||||||
|
|
||||||
def category
|
def category
|
||||||
object.topic.category
|
object.topic.category
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='body'><%= format_for_email(use_excerpt ? post.excerpt : post.cooked) %></td>
|
<td class='body'><%= format_for_email(post, use_excerpt) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -390,8 +390,9 @@ module PrettyText
|
|||||||
doc.css(".lightbox-wrapper .meta").remove
|
doc.css(".lightbox-wrapper .meta").remove
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.format_for_email(html)
|
def self.format_for_email(html, post = nil)
|
||||||
doc = Nokogiri::HTML.fragment(html)
|
doc = Nokogiri::HTML.fragment(html)
|
||||||
|
DiscourseEvent.trigger(:reduce_cooked, doc, post)
|
||||||
make_all_links_absolute(doc)
|
make_all_links_absolute(doc)
|
||||||
strip_image_wrapping(doc)
|
strip_image_wrapping(doc)
|
||||||
doc.to_html
|
doc.to_html
|
||||||
|
@ -22,19 +22,6 @@ DEFAULT_POLL_NAME ||= "poll".freeze
|
|||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
# turn polls into a link in emails
|
|
||||||
Email::Styles.register_plugin_style do |fragment, opts|
|
|
||||||
post = Post.find_by(id: opts[:post_id]) rescue nil
|
|
||||||
if post.nil? || post.trashed?
|
|
||||||
fragment.css(".poll").each(&:remove)
|
|
||||||
else
|
|
||||||
post_url = "#{Discourse.base_url}#{post.url}"
|
|
||||||
fragment.css(".poll").each do |poll|
|
|
||||||
poll.replace "<p><a href='#{post_url}'>#{I18n.t("poll.email.link_to_poll")}</a></p>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module ::DiscoursePoll
|
module ::DiscoursePoll
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
engine_name PLUGIN_NAME
|
engine_name PLUGIN_NAME
|
||||||
@ -281,7 +268,7 @@ after_initialize do
|
|||||||
self.errors.add(:base, I18n.t("poll.default_poll_with_multiple_choices_has_invalid_parameters")) :
|
self.errors.add(:base, I18n.t("poll.default_poll_with_multiple_choices_has_invalid_parameters")) :
|
||||||
self.errors.add(:base, I18n.t("poll.named_poll_with_multiple_choices_has_invalid_parameters", name: poll["name"]))
|
self.errors.add(:base, I18n.t("poll.named_poll_with_multiple_choices_has_invalid_parameters", name: poll["name"]))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# store the valid poll
|
# store the valid poll
|
||||||
@ -367,6 +354,17 @@ after_initialize do
|
|||||||
user ? [POLLS_CUSTOM_FIELD, VOTES_CUSTOM_FIELD] : [POLLS_CUSTOM_FIELD]
|
user ? [POLLS_CUSTOM_FIELD, VOTES_CUSTOM_FIELD] : [POLLS_CUSTOM_FIELD]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
on(:reduce_cooked) do |fragment, post|
|
||||||
|
if post.nil? || post.trashed?
|
||||||
|
fragment.css(".poll, [data-poll-name]").each(&:remove)
|
||||||
|
else
|
||||||
|
post_url = "#{Discourse.base_url}#{post.url}"
|
||||||
|
fragment.css(".poll, [data-poll-name]").each do |poll|
|
||||||
|
poll.replace "<p><a href='#{post_url}'>#{I18n.t("poll.email.link_to_poll")}</a></p>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# tells the front-end we have a poll for that post
|
# tells the front-end we have a poll for that post
|
||||||
on(:post_created) do |post|
|
on(:post_created) do |post|
|
||||||
next if post.is_first_post? || post.custom_fields[POLLS_CUSTOM_FIELD].blank?
|
next if post.is_first_post? || post.custom_fields[POLLS_CUSTOM_FIELD].blank?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user