Class: PrettyMailer::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/pretty_mailer/html.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ HTML

Returns a new instance of HTML.



7
8
9
# File 'lib/pretty_mailer/html.rb', line 7

def initialize body
  @doc = Nokogiri::HTML body
end

Instance Method Details

#add_rules(selector, declarations, specificity) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pretty_mailer/html.rb', line 11

def add_rules selector, declarations, specificity
  if selector =~ /^[\.\#a-z]/i
    begin
      @doc.css(selector).each do |tag|
        tag['specificities'] = "#{tag['specificities']}#{specificity};"
        tag[specificity.to_s] = declarations.gsub /\s+/, ''
      end
    rescue Nokogiri::CSS::SyntaxError
      Rails.logger.debug "Ignoring invalid selector: #{selector}"
    end
  end
end

#reduce_specificities!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pretty_mailer/html.rb', line 24

def reduce_specificities!
  tags_with_specificities.each do |tag|
    specificities_on_tag(tag).each do |specificity|
      if tag['style'].blank?
        tag['style'] = "#{ tag[specificity] }"
      else
        merge_in_styles tag, specificity
      end
      tag.delete specificity
    end
    tag.delete 'specificities'
  end
end

#to_sObject



38
39
40
# File 'lib/pretty_mailer/html.rb', line 38

def to_s
  @doc.to_s
end