Class: Mjml::Handler
- Inherits:
-
Object
- Object
- Mjml::Handler
- Defined in:
- lib/mjml.rb
Instance Method Summary collapse
-
#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.
- #template_handler ⇒ Object
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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mjml.rb', line 61 def call(template, source = nil) compiled_source = if Rails::VERSION::MAJOR >= 6 template_handler.call(template, source) else template_handler.call(template) end # 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/guide.md#mjml if compiled_source =~ /<mjml(.+)?>/i "Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe" else compiled_source end end |
#template_handler ⇒ Object
54 55 56 |
# File 'lib/mjml.rb', line 54 def template_handler @_template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language) end |