Skip to content

Instantly share code, notes, and snippets.

@ruedap
Forked from jrmoran/app.coffee
Created March 24, 2013 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruedap/5232910 to your computer and use it in GitHub Desktop.
Save ruedap/5232910 to your computer and use it in GitHub Desktop.

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