Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators should not generate .txt.slim templates #176

Open
diabolo opened this issue Jan 3, 2022 · 1 comment
Open

Generators should not generate .txt.slim templates #176

diabolo opened this issue Jan 3, 2022 · 1 comment

Comments

@diabolo
Copy link

diabolo commented Jan 3, 2022

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
Copy link
Contributor

januszm commented Feb 15, 2023

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 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants