Class: DigestEmail::Digest
- Inherits:
-
DigestElement
- Object
- DigestElement
- DigestEmail::Digest
- Defined in:
- lib/digest_email/digest.rb
Instance Attribute Summary
Attributes inherited from DigestElement
Instance Method Summary collapse
-
#initialize(header, items, footer) ⇒ Digest
constructor
A new instance of Digest.
- #render(template = "{{content}}", show_warnings = false) ⇒ Object
- #wrap(inner) ⇒ Object
Constructor Details
#initialize(header, items, footer) ⇒ Digest
Returns a new instance of Digest.
8 9 10 11 12 13 |
# File 'lib/digest_email/digest.rb', line 8 def initialize(header, items, ) @header = header @items = items @footer = @children = [@header, @items, @footer] end |
Instance Method Details
#render(template = "{{content}}", show_warnings = false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/digest_email/digest.rb', line 15 def render(template = "{{content}}", show_warnings = false) html = [@header.render(@items.children), @items.render, @footer.render].join html = template.gsub '{{content}}', wrap(html) # Convert any styles to inline premailer = Premailer.new(html, :with_html_string => true) html = premailer.to_inline_css # Output any CSS warnings if show_warnings puts "Email Client Compatibility Warnings:" premailer.warnings.each do |w| puts "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}" end end html end |
#wrap(inner) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/digest_email/digest.rb', line 33 def wrap(inner) ["<div class=\"digest\">", "<table>", "<tr>", "<td>", inner, "</td>", "</tr>", "</table>", "</div>"].join end |