Class: HtmlEmail

Inherits:
Object
  • Object
show all
Defined in:
lib/html2email/html_email.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, layout = nil, options = {}) ⇒ HtmlEmail

Returns a new instance of HtmlEmail.



7
8
9
10
11
# File 'lib/html2email/html_email.rb', line 7

def initialize(template, layout = nil, options = {})
  @template, @layout, @options = template, layout, options
  @options[:default_type] ||= 'str'
  @context = Context.new
end

Instance Method Details

#renderObject

returns converted html string



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/html2email/html_email.rb', line 14

def render
  buf = if @layout
    # run through template once to catch prebinding block
    begin
      tilt_render @template
    rescue Context::PrebindingException
    rescue
      # some other StandardError was raised, probably a NameError;
      # reset the context to minimize the leaky abstraction
      @context = Context.new
    end
    # return the full render with the new lexical binding
    tilt_render(@layout) { tilt_render @template }
  else
    tilt_render @template
  end
  inline_css buf
end

#test_recipientsObject



33
34
35
# File 'lib/html2email/html_email.rb', line 33

def test_recipients
  @context.test_recipients
end