Class: ActiveMail::Rails::TemplateHandler

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activemail/rails/template_handler.rb

Defined Under Namespace

Modules: Composer

Instance Method Summary collapse

Constructor Details

#initialize(compose_with = nil) ⇒ TemplateHandler

Returns a new instance of TemplateHandler.



12
13
14
15
16
17
18
19
20
21
# File 'lib/activemail/rails/template_handler.rb', line 12

def initialize(compose_with = nil)
  # ActionView handlers share no interface (Procs, objects, classes).
  @engine_handler = T.let(nil, T.untyped)
  return unless compose_with

  # Without this guard a typo would silently fall back to the configured
  # template_engine in #engine_handler.
  @engine_handler = ActionView::Template.registered_template_handler(compose_with) ||
                    raise(ArgumentError, "No template handler found for #{compose_with}")
end

Instance Method Details

#call(template, source = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/activemail/rails/template_handler.rb', line 33

def call(template, source = nil)
  compiled_source =
    if source
      engine_handler.call(template, source)
    else
      engine_handler.call(template)
    end
  "ActiveMail::Core.new.release_the_kraken(begin; #{compiled_source};end)"
end

#engine_handlerObject



24
25
26
27
28
29
30
# File 'lib/activemail/rails/template_handler.rb', line 24

def engine_handler
  return @engine_handler if @engine_handler

  type = ::ActiveMail.configuration.template_engine
  ActionView::Template.registered_template_handler(type) ||
    raise("No template handler found for #{type}")
end