Class: Thredded::EmailTransformer::Spoiler
- Defined in:
- lib/thredded/email_transformer/spoiler.rb
Overview
Changes the spoiler tags to work in emails.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods included from Helpers
Constructor Details
This class inherits a constructor from Thredded::EmailTransformer::Base
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/thredded/email_transformer/spoiler.rb', line 8 def call doc.css('.thredded--post--content--spoiler--summary').each do |node| node.content = I18n.t('thredded.posts.spoiler_summary_for_email') end doc.css('.thredded--post--content--spoiler--contents img').each do |img| text = "#{img['src']} #{" (#{img['alt']})" if img['alt'].present?}" img.swap( if img.parent.name == 'a' && img.parent.children.size == 1 doc.document.create_text_node(text) else doc.document.create_element('a', text, href: img['src'], target: '_blank') end ) end end |