Module: Premailer::Adapter::Decidim

Includes:
Nokogiri
Defined in:
decidim-core/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
# File 'decidim-core/lib/premailer/adapter/decidim.rb', line 17

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

  html_src = @doc.to_html unless html_src && html_src.present?

  # remove style tags and content
  html_src.gsub!(%r{<style.*?/style>}m, "")

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