Open aleksandrs-ledovskis opened 6 years ago
@aleksandrs-ledovskis I haven't used Haml or Slim, so will take your recommendation for the best way forward.
But again, please use your best judgement. :-)
For the time being the documentation should contain a hint that other template languages than ERB are currently broken.
@biastoch2 @jbwl would your favoured solutions be to change if template.source =~ /<mjml>/
to if compiled_source =~ /<mjml>/
as you've done in your fork @biatoch2 ?
I tried the fix from @biatoch2 and it works for me. I'd vote for it.
In https://github.com/sighmon/mjml-rails/pull/33 / v4.2.0 a change in logic was made around assumption that layout template will always contain verbatim
<mjml>
.In ERb world this (mostly) holds, but when layout is composed using advanced templating languages like Haml and Slim, both allowing tag definition without
<>
wrapping, it fails.Also, it doesn't handle edge case where somebody is referencing/writing code comment in partial that is e.g.
<%# Let's use MJML in this partial. Note that <mjml> must reside in layout %>
- currently,mjml-rails
will take that comment's<mjml>
as flag to process template with MJML library. Or when root tag is generated usingcontent_tag
. Or when it's contained in a partial.Current workaround: Put verbatim
<mjml>
in Haml/Slim layouts. Avoid dynamically generating MJML root tag. Don't reference<mjml>
proper anywhere else except MJML layout files.Simple change of
to
would solve no
<>
and comment-triggering-MJML situations, but still leave other aforementioned edge cases broken.Possible solutions:
Doing first-pass render of template to process nested partials/helpers, capture this output and use same match (
=~ /<mjml>/
) as done currently.Require some kind of magic comment in file (e.g.
# mjml_processing: true
) that would serve as signal to do MJML processing of rendered file.Require users to whitelist paths to MJML-processed layout/legacy-template files in initializer, akin to Asset Pipeline compilation does. Then just match against
template.identifer
/cc @sighmon