User:Pgomata/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 what could be removed (<, >, closing tags, etc...) to 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". It's supported by major frameworks like Rails, Sinatra.

How does SLIM simplify the use of 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
SLIM started with a goal of reducing view syntax and achieve the similar behavior and performance.

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 engine like Markdown 

Installation
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 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

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