Main menu:

Site search

Categories

March 2010
M T W T F S S
« Jan    
1234567
891011121314
15161718192021
22232425262728
293031  

Tags

Blogroll

Slippers: Introduction

There are many template engines that you can choose for the generation of views in your mvc application. The problem with most of the them, however, is that they are too permissive. These turing-complete engines allow for many complex constructs within the template, which begin at simple if statements and for loops, and expand to complex object traversal. While these permissive languages are intended to offer great flexibility, in reality they promote bad practices. Allowing logic to permeate your view is bad for many reasons: firstly, the code in views is rarely tested; secondly, the separation between the models and the view blurs and business logic creeps into the view.

All we want our template engine to do is read a string which has holes in it, and replace those holes with the desired string, much like mail merge. Luckily for me, there is already a templating engine which enforces strict separation of model and view by only supporting these strings with holes – String Template. String Template is originally created in Java, however there has been subsequent ports to C# and python. It is opinionated, and I like it’s opinions. (And if you prefer permissive views, I would recommend you reading about the origins of String Template before completely ruling it out.)

Unfortunately, when I started to try out Ramaze (a great web framework for ruby – much better than rails imho) I looked around for a port of String Template to ruby, but couldn’t find out. So, I decided that if no-one else would port it, I would…and so Slippers was born.

Slippers is a strict template engine for ruby, supporting the syntax from String Template including anonymous template, named templates and template group directories but also goes beyond this to allow you to use your own renderers. Nearly all the useful constructs from String Template have been ported, and you can see the comparison on the Slippers vs String Template page.

In creating Slippers, I have been surprised to find how many development tools for ruby can now be found “in the cloud” (ie on the web):

  • Slippers code repository is hosted on github.
  • Slippers has been test-driven, and I have a CI build at runcoderun.com. As you can see, I have also made it Ruby 1.9 compatible.
  • The gem can be found on gemcutter. To install:
    # Run the following if you haven't done so before:
    $ gem sources -a http://gemcutter.org
    # Install the gem:
    $ sudo gem install slippers
    

Ramaze now supports Slippers as a view engine, as of gem version 2009.10 (also on gemcutter).

More information about Slippers can be found at http://slippersrb.com

Comments

Comment from Ola Bini
Time October 13, 2009 at 11:59 am

Actually, it’s probably easier to just do: “sudo gem install gemcutter” – that will set everything up correctly.

Pingback from Sarah Taraporewalla’s Technical Ramblings » Slippers: How to click your heels
Time October 14, 2009 at 7:13 am

[...] my last post about Slippers, I introduced it’s philosophy and the places that you could find it. In this [...]

Comment from wave
Time December 6, 2009 at 8:14 am

The word ‘Ramaze’ above links to the stringtemplate website instead of ramaze.net.

Comment from Sarah
Time December 8, 2009 at 7:41 pm

Thanks! Fixed it now

Write a comment