Module: Premailer::Adapter::Decidim

Includes:
Nokogiri
Defined in:
lib/premailer/adapter/decidim.rb

Overview

Decidim adapter for Premailer

Instance Method Summary collapse

Instance Method Details

#to_plain_textString

Converts the HTML document to a format suitable for plain-text e-mail.

If present, uses the <body> element as its base; otherwise uses the whole document.

Customized for Decidim in order to strip the inline <style> tags away from the plain text body.

Returns:

  • (String)

    a plain text.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/premailer/adapter/decidim.rb', line 17

def to_plain_text
  html_src = begin
    @doc.css("style").remove
    @doc.at("body").inner_html
  rescue StandardError
    ""
  end

  unless html_src && html_src.present?
    @doc.css("style").remove
    html_src = @doc.to_html
  end

  convert_to_text(html_src, @options[:line_length], @html_encoding)
end