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?
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.