hamlc backbone collection
by jaimem
HTML
<script src='http://underscorejs.org/underscore-min.js'></script>
<script src='http://backbonejs.org/backbone-min.js'></script>
<div id='out'></div>
JavaScript
(function() {
var _ref;
if ((_ref = window.HAML) == null) {
window.HAML = {};
}
window.HAML['test'] = function(context) {
return (function() {
var $c, $e, $o, font, _i, _len, _ref1;
$e = function(text, escape) {
return ("" + text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/\//g, '/').replace(/"/g, '"');
};
$c = function(text) {
switch (text) {
case null:
case void 0:
return '';
case true:
case false:
return '' + text;
default:
return text;
}
};
$o = [];
$o.push("<ul>");
_ref1 = this.fonts;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
font = _ref1[_i];
$o.push(" <li>");
$o.push(" " + $e($c(font.name)));
$o.push(" </li>");
}
$o.push("</ul>");
return $o.join("\n").replace(/\s(\w+)='true'/mg, ' $1').replace(/\s(\w+)='false'/mg, '');
}).call(context);
};
}).call(this);
// Backbone collection
var fonts = new Backbone.Collection;
fonts.add([
{ name: 'arial'},
{ name: 'arial black'},
{ name: 'comic sans ms'},
{ name: 'courier'},
{ name: 'courier new'},
{ name: 'georgia'},
{ name: 'helvetica'},
{ name: 'impact'},
{ name: 'palatino'},
{ name: 'times new roman'},
{ name: 'trebuchet ms'},
{ name: 'verdana'}
]);
var html = window.HAML.test({fonts:fonts.toJSON()});
document.getElementById('out').innerHTML = html;