Sep 10, 2011

Yes, Slim is speedy


Slim
Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic.

What?

Slim is a fast, lightweight templating engine with support for Rails 3. It has been tested on Ruby 1.9.2 and Ruby/REE 1.8.7.

Slim's core syntax is guided by one thought: "What's the minimum required to make this work".

As more people have contributed to Slim, there have been optional syntax additions influenced from their use of Haml and Jade. The Slim team is open to these optional additions because we know beauty is in the eye of the beholder.

Slim uses Temple for parsing/compilation and is also integrated into Tilt, so it can be used together with Sinatra or plain Rack.

Sample View:

doctype html
html
  head
    title Slim Examples
    meta name="keywords" content="template language"

  body
    h1 Markup examples
    #content.example1
      p Nest by indentation

    = yield

    - unless items.empty?
      table
        - for item in items do
          tr
            td = item.name
            td = item.price
    - else
      p No items found

    #footer
      | Copyright © 2010 Andrew Stone

    = render 'tracking_code'

    script
      | $(content).do_something();

No comments:

Post a Comment