I am using slim for templating and ruby on rails(just started using them). The only problem I am facing is: there is no formatting for the html rendered. i.e no line breaks, no indentation. I can understand it can be a little tricky for slim to render formatting intrinsically.
Is there anyway to render properly formatted html?
Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner.
This word-break property is used to specify how to break the word when the word reached at end of the line.
You must be using double quotes, and you use \r\n to make a new line.
<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return).
From the docs:
Slim::Engine.set_default_options pretty: true
or directly
Slim::Engine.default_options[:pretty] = true
To expand a bit, as @rubiii mentioned in the comments this is a feature of Slim. For the same reasons it's good practice to minify and compress Javascript and CSS in production Slim strips unecessary whitespace from the HTML it produces without this :pretty
option set to true
.
If you have some config/initializers/slim.rb
file you can configure the :pretty
option dynamically by checking the environment.
Slim::Engine.set_default_options pretty: Rails.env.development?
Otherwise you should set this option to true
only in config/environments/development.rb
, leaving it false
in production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With