Class: MailDude::HtmlBodyRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_dude/html_body_renderer.rb

Constant Summary collapse

PLACEHOLDER =
'<p>This message does not include an HTML body.</p>'

Instance Method Summary collapse

Constructor Details

#initialize(presenter, attachment_url:) ⇒ HtmlBodyRenderer

Returns a new instance of HtmlBodyRenderer.



9
10
11
12
# File 'lib/mail_dude/html_body_renderer.rb', line 9

def initialize(presenter, attachment_url:)
  @attachment_url = attachment_url
  @presenter = presenter
end

Instance Method Details

#renderObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mail_dude/html_body_renderer.rb', line 14

def render
  html = presenter.html_body
  return PLACEHOLDER if html.blank?

  fragment = Nokogiri::HTML::DocumentFragment.parse(html)
  rewrite_cid_images(fragment)
  rewrite_links(fragment)
  fragment.to_html
rescue StandardError
  html.to_s
end