class MailxRuby::Body

Attributes

html[RW]
text[RW]

Public Class Methods

new(html) click to toggle source
# File lib/mailx_ruby/body.rb, line 9
def initialize(html)
  @html = html
end

Public Instance Methods

has_css?() click to toggle source
# File lib/mailx_ruby/body.rb, line 13
def has_css?
  nokogiri_html.xpath("//style").any?
end
premailer() click to toggle source
# File lib/mailx_ruby/body.rb, line 17
def premailer
  @premailer ||= generate_premailer
end

Private Instance Methods

generate_premailer() click to toggle source
# File lib/mailx_ruby/body.rb, line 27
def generate_premailer
  File.open(tmp_filepath, "w"){|f| f.write(html) }
  premailer = Premailer.new(tmp_filepath, warn_level: Premailer::Warnings::SAFE)
  File.delete(tmp_filepath)
  premailer
end
nokogiri_html() click to toggle source
# File lib/mailx_ruby/body.rb, line 23
def nokogiri_html
  @nokogiri_html ||= Nokogiri::HTML(html)
end
tmp_filepath() click to toggle source
# File lib/mailx_ruby/body.rb, line 34
def tmp_filepath
  @tmp_filepath ||= "mail#{Time.now.to_i}.html"
end