Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created January 16, 2012 20:57
Show Gist options
  • Save jrmoran/1623031 to your computer and use it in GitHub Desktop.
Save jrmoran/1623031 to your computer and use it in GitHub Desktop.
Precompiled Haml templates with CoffeeScript

Precompiled Haml templates with CoffeeScript

Read more here

To compile the files just run

haml index.haml index.html && coffee -c app.coffee

You might be interested in the following command line tools to compile files automatically

Friendlier tools

companies = [{"id":1,"ticker":"AAPL","name":"Apple Inc"},
{"id":2,"ticker":"ABC","name":"Amerisourcebergen Corp"},
{"id":3,"ticker":"ABT","name":"Abbott Labs"},
{"id":4,"ticker":"ACE","name":"Ace Ltd"},
{"id":5,"ticker":"ADBE","name":"Adobe Sys Inc"}]
_.templateSettings = interpolate :/\{\{(.+?)\}\}/g
$ ->
template = $('#templates .company_li').html()
htmlstr = ( _.template( template, c) for c in companies)
$('#companies ul').append htmlstr.join ''
!!! 5
%html
%head
%title Test
%script{:src => 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.2.2/underscore-min.js'}
%script{:src => 'http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js'}
%script{:src => 'app.js'}
%body
#templates{:style=>'display:none'}
.company_li
%li
%span.ticker {{ticker}}
%span.name {{name}}
#companies
%ul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment