Class: Mrml::Rails::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/mrml/rails/handler.rb

Instance Method Summary collapse

Instance Method Details

#call(template, source = nil) ⇒ Object

Optional second source parameter to make it work with Rails >= 6: Beginning with Rails 6 template handlers get the source of the template as the second parameter.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mrml/rails/handler.rb', line 16

def call(template, source = nil)
  compiled_source = if ::Rails::VERSION::MAJOR >= 6
      template_handler.call(template, source)
  else
      template_handler.call(template)
  end

  if compiled_source =~ /<mjml.*?>/i
    # "MRML.to_html(begin;#{compiled_source};end).html_safe"
    "MRML::Template.new(begin;#{compiled_source};end).to_html"
  else
    compiled_source
  end
end

#template_handlerObject



9
10
11
# File 'lib/mrml/rails/handler.rb', line 9

def template_handler
  @template_handler ||= ActionView::Template.registered_template_handler(:erb)
end