phoenix_mjml icon indicating copy to clipboard operation
phoenix_mjml copied to clipboard

switch eex and mjml rendering

Open julien-leclercq opened this issue 7 years ago • 11 comments

Please correct me if I am wrong but in your implementation, you generate html then compile it with EEx. This way you aren't able to generate really dynamic mails because mjml can't decide the exact number of elements in the page. Eex compilation should happen before to generate proper responsives emails.

julien-leclercq avatar Aug 14 '17 09:08 julien-leclercq

hi @julien-leclercq, the flow is like this: eex -> mjml -> html

Just checked your implement, quite confuse 🤔

MQuy avatar Aug 14 '17 09:08 MQuy

How could it be so ? your Module entry point is compile which is

def compile(path, _name) do
   path
   |> generate_html_path
   |> compile_content
end

you call EEx in compile_content and mjml in generate_html_path we are confusing each other right now

julien-leclercq avatar Aug 14 '17 13:08 julien-leclercq

My benchmarks with both implementation https://gist.github.com/julien-leclercq/5fbe854f7c87f072b7bb799b283acbb7

julien-leclercq avatar Aug 14 '17 14:08 julien-leclercq

ops, my bad. the flow will be mjml -> html -> eex 😂 . It seems like your solution is faster, it doesn't need to create a new file 🤔

MQuy avatar Aug 14 '17 14:08 MQuy

clearly the benches show no difference because the bottleneck is in the mjml bootup. But we need to change the flow to EEx -> mjml -> html to allow mjml to generate truly responsive email

julien-leclercq avatar Aug 14 '17 14:08 julien-leclercq

you are right, let's stick with your solution 👍🏻

MQuy avatar Aug 14 '17 14:08 MQuy

I am working on inversing the flow but if you have an idea I would be glad to cooperate on this !

julien-leclercq avatar Aug 14 '17 14:08 julien-leclercq

What package do you use to render your emails ? I personally use Bamboo, I think would be smarter to implement a Bamboo engine than a Phoenix Engine, what do you think ?

julien-leclercq avatar Aug 14 '17 15:08 julien-leclercq

I use Bamboo, can you explain why Bamboo engine is better than Phoenix Engine 🤔

MQuy avatar Aug 14 '17 15:08 MQuy

Because Phoenix Engine expect its unique function compile to return a quoted expression to be then evaluated. In your process that's what EEx does. What we need here is EEx to run before mjml to ensure the output to be a responsive html email. I would go with a Bamboo phoenix engine extension that call mjml at the end of the render function. What do you think of it ?

I am not a native english speaker so if it is unclear please don't be afraid to ask further explanations.

julien-leclercq avatar Aug 14 '17 15:08 julien-leclercq

created a repo for it be free to fork and pull request (I don't think I am gonna push today I have other things to do) https://github.com/derniercri/bamboo_mjml

julien-leclercq avatar Aug 14 '17 15:08 julien-leclercq