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

This entry was posted in Open source projects. Bookmark the permalink.

4 Responses to Slippers: Introduction

  1. Ola Bini says:

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

  2. Pingback: Sarah Taraporewalla’s Technical Ramblings » Slippers: How to click your heels

  3. wave says:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>