Can I use multiple preprocessors in Rails views?

Using Rails 3.2, you can make files in the asset pipeline using multiple preprocessors by adding multiple file extensions, as follows: index.css.scss.erb

I tried to do this with a view ( index.html.slim.erb ), and he didn't seem to know what to do (more precisely, he just didn't find the view at all).

Doesn't Rails really pass views through Tilt? Is there any other way to get a view to work through one preprocessor and then another?

(Context: I'm working on what is meant to change the HTML code before it is returned, so I would like it to run after haml / slim / erb.)

+2
source share
1 answer

In fact, you cannot. Rails does not use skew for view templates.

One of the reasons it would be difficult to do this is that during normal operation, ERB actually โ€œcompilesโ€ ruby โ€‹โ€‹code, not text, for performance. Those. The erb template compiles once to live in ruby โ€‹โ€‹code, which is then executed each time it needs to be displayed in a different context.

I do not know how to do what you want. Of course, you can roll yourself. No one says you need to call the "render" template "to render. Don't forget that you can always

 render :text => any_method_that_returns_a_string 

You can transfer things through Tilt yourself. You can see some performance degradation compared to what Rails usually does.

+2
source

Source: https://habr.com/ru/post/943755/


All Articles