Class: Thredded::EmailTransformer::Spoiler

Inherits:
Base
  • Object
show all
Defined in:
lib/thredded/email_transformer/spoiler.rb

Overview

Changes the spoiler tags to work in emails.

Instance Attribute Summary

Attributes inherited from Base

#doc

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize

Methods included from Helpers

#anchor, #paragraph

Constructor Details

This class inherits a constructor from Thredded::EmailTransformer::Base

Instance Method Details

#callObject



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