User:Ramadheeraj/sandbox

SLIM is a template language/engine. The aim of this is to reduce the view syntax to just the needed part without being cryptic. The base was taken as HTML template and how much could be removed (<, >, closing tags, etc...) and make the template more flexible in nature. Slim was developed right from the start with performance in mind. Slim's core syntax is guided by one thought: "What's the minimum required to make this work". Its supported by major frameworks like Rails, Sinatra.

How does SLIM incorporate HTML?
SLIM works on the simple understandable free flow coding. So it removes the numerous tags in HTML and replaces them with indentation.

In SLIM

html body h1 The content of the document......

Indentation matters, but the indentation depth can be chosen as you like. If you want to first indent 2 spaces, then 5 spaces.

Features
The slim started with a goal of reducing view syntax and achieve the similar behavior and performance. The flexibility of slim increased proportionally with huge number of people taking interest and contributing to slim.

A short list of the features ...

Elegant syntax


 * HTML style mode with closing tags


 * Configurable shortcut tags

Safety


 * Automatic HTML escaping by default


 * Support for Rails' html_safe?

Highly configurable

Extensible via the following plugins:


 * Logic less mode similar to Mustache


 * High performance


 * Comparable speed to ERB/Erubis


 * Streaming support in Rails


 * Supported by all major frameworks (Rails, Sinatra, ...)

Full Unicode support for tags and attributes

Embedded engines like Markdown and Textile

Install
In the Rails environment slim can be installed as a Gem

One line Command to install gem gem install slim

Now just use the .slim extension when u save the template. Another thing to note is SLIM has some run time dependencies namely temple and tilt.

Usage
Here are a few examples of slim template usage :

Syntax Examples

Verbatim Text

The pipe tells the slim to just copy the line following pipe.

Inline html

Slim allows you to write both html coding and a mix of html and slim style.

Control Code

The dash statement at the beginning denotes a control code  Examples of control code are loops and conditionals. Blocks are defined only by indentation. If your ruby code needs to use multiple lines, append a backslash \ at the end of the lines. If your line ends with comma, (e.g because of a method call) you don't need the additional backslash before the line break.

Code Comment

Use the forward slash for code comments - anything after it won't get displayed in the final render. Use / for code comments and /! for html comments.

Text Content

Either start on the same line as the tag.

Or nest it. You must use a pipe or an apostrophe to escape processing

Dynamic Content

Can make the call on the same line

Or nest it.

Attributes

Attributes can be directly written after tags.

Short cuts

Tag shortcuts

Attribute Shortcuts

You can define custom tag shortcuts by setting the option :shortcut.

Tools

The gem 'slim' comes with the small tool 'slimrb' to test Slim from the command line.