slim-template / slim-rails

Slim templates generator for Rails
MIT License
691 stars 129 forks source link

Generators should not generate .txt.slim templates #176

Open diabolo opened 2 years ago

diabolo commented 2 years ago

Whilst working through an example app I came across an issue with email templates generated by rails. Slim isn't really suitable for this because the expected behaviour of rendering plain text as is doesn't happen with slim. I'll illustrate

with an erb template with content

hello world

you get output

hello world

with a slim template with the same content you get output

<hello>world</hello>

This isn't a bug with slim, its fundamental to how slim works.

It would an improvement if slim-rails could fall back to generating an erb template for txt email views. An alternative might be to generate a template with some content like

# prefer erb over slim for txt templates
# otherwise make sure your content is contained in a slim block
|
  content here inside the slim block de-lineated by |
januszm commented 1 year ago

Not sure if I understand your issue @diabolo Please see an example below where I generate a new template and get both text.slim and html.slim templates which seem legit to me:

❯ rails g  mailer HelloWorld ping
      create  app/mailers/hello_world_mailer.rb
      invoke  slim
      create    app/views/hello_world_mailer
      create    app/views/hello_world_mailer/ping.text.slim
      create    app/views/hello_world_mailer/ping.html.slim

cat app/views/hello_world_mailer/ping.text.slim

' HelloWorld#ping
= "\r\n" * 2
' #{@greeting}, find me in app/views/hello_world_mailer/ping.text.slim

and when you preview that template with http://localhost:3000/rails/mailers/hello_world/ping , it shows clear text, no markup:

HelloWorld#ping 

Hi, find me in app/views/hello_world_mailer/ping.text.slim