Class: DecorationMail::HTML
- Inherits:
-
Object
- Object
- DecorationMail::HTML
- Defined in:
- lib/decoration_mail/html.rb
Instance Method Summary collapse
- #append_img(src) ⇒ Object
-
#initialize(str) ⇒ HTML
constructor
A new instance of HTML.
- #match(regexp) ⇒ Object
- #prepend_img(src) ⇒ Object
- #to_s ⇒ Object
- #update_img_src(from, to) ⇒ Object
Constructor Details
#initialize(str) ⇒ HTML
Returns a new instance of HTML.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/decoration_mail/html.rb', line 5 def initialize(str) @tree = Nokogiri.HTML(str) @unresolved_references = @tree.css('img').map{|img| img['src'] } raise ArgumentError, 'invalid HTML' if @tree.search("body").empty? convert_font_color_to_css convert_font_size_to_css convert_align_to_css convert_blink_to_css convert_marquee_to_css end |
Instance Method Details
#append_img(src) ⇒ Object
21 22 23 |
# File 'lib/decoration_mail/html.rb', line 21 def append_img(src) @tree.css('body').children.after(%(<br /><div style="text-align:center;"><img src="#{src}" /></div>)) if src end |
#match(regexp) ⇒ Object
17 18 19 |
# File 'lib/decoration_mail/html.rb', line 17 def match(regexp) @tree.css('body').to_html =~ regexp end |
#prepend_img(src) ⇒ Object
25 26 27 |
# File 'lib/decoration_mail/html.rb', line 25 def prepend_img(src) @tree.css('body').children.before(%(<div style="text-align:center;"><img src="#{src}" /></div><br />)) if src end |
#to_s ⇒ Object
40 41 42 43 |
# File 'lib/decoration_mail/html.rb', line 40 def to_s remove_invalid_references to_div.to_html end |
#update_img_src(from, to) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/decoration_mail/html.rb', line 29 def update_img_src(from, to) @unresolved_references.delete(from) @tree.css("img[src=\"#{from}\"]").each do |e| if to e['src'] = to else e.remove end end end |