1

If I use roadie/premailer to transform my emails in Hanami, then where should I place the transformation code in Hanami?

Thx

Boti
  • 3,275
  • 1
  • 29
  • 54

2 Answers2

0

this is a more general question about email CSS inlining. You can check this gem: https://github.com/premailer/premailer

Luca Guidi
  • 1,201
  • 10
  • 10
  • I've used that gem in my projects :) The question was, where to put the transformation code in Hanami if I use premailer/roadie – Boti Sep 10 '18 at 13:58
  • Did you try to alter the `mail` object via `prepare`? It's a hook that is executed before to deliver the email. See https://github.com/hanami/mailer#attachments – Luca Guidi Sep 11 '18 at 15:26
0

Here is the code which works:

In the gemfile:

gem 'roadie', '~> 3.4'

And assuming that we put the style in the: lib/app/mailers/assets/stylesheets/mail.css the prepare method of the email:

html_part = mail.html_part
old_html = html_part.body.decoded

document = Roadie::Document.new old_html
document.add_css File.read( File.join(Hanami.root, "lib", "app", "mailers", "assets", "stylesheets", "mail.css"))
new_html = document.transform

html_part.body = new_html
Boti
  • 3,275
  • 1
  • 29
  • 54