class Mjml::Handler
Public Instance Methods
call(template, source = nil)
click to toggle source
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.
# File lib/mjml/handler.rb, line 16 def call(template, source = nil) compiled_source = compile_source(source, template) parser_class = Mjml.use_mrml ? 'MrmlParser' : 'Parser' # Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag # If we get here and template source doesn't start with one it means # that we are rendering partial named according to legacy naming convention (partials ending with '.mjml') # Therefore we skip MJML processing and return raw compiled source. It will be processed # by MJML library when top-level layout/template is rendered # # [0] - https://github.com/mjmlio/mjml/blob/master/doc/components_1.md#mjml if /<mjml.*?>/i.match?(compiled_source) "Mjml::#{parser_class}.new(begin;#{compiled_source};end).render.html_safe" else compiled_source end end
template_handler()
click to toggle source
# File lib/mjml/handler.rb, line 9 def template_handler @template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language) end
Private Instance Methods
compile_source(source, template)
click to toggle source
# File lib/mjml/handler.rb, line 36 def compile_source(source, template) if Rails::VERSION::MAJOR >= 6 template_handler.call(template, source) else template_handler.call(template) end end