Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slim Line breaks and formatting

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?

like image 288
SoWhat Avatar asked Feb 24 '13 12:02

SoWhat


People also ask

What is slim format?

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.

What is word break in computer?

This word-break property is used to specify how to break the word when the word reached at end of the line.

How do you insert a line break in plain text email?

You must be using double quotes, and you use \r\n to make a new line.

How do you break a line in HTML?

<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return).


1 Answers

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.

like image 174
deefour Avatar answered Sep 19 '22 15:09

deefour