jasonmoo / t.js

A tiny javascript templating framework in ~400 bytes gzipped
MIT License
827 stars 89 forks source link

Add Function Support #7

Closed icyflash closed 12 years ago

icyflash commented 12 years ago

Sometimes we need format data before render.

We have:

{"CreatedAt": 1346295626942}

We need:

Thu Aug 30 2012 11:00:26 GMT+0800

We can:

var template = new t("<div>{{#CreatedAt|dateFormat}}</div>");
template.register("dateFormat",function(data){return new Date(parseInt(data));});
template.render({"CreatedAt": 1346295626942});
jasonmoo commented 12 years ago

Hey I'm not really feeling the function support. I think the same thing can be accomplished by processing your data before you pass it to the render function, or building markup in a loop with a couple templates.

Also you managed to rewrite all the line endings so I can't tell what changes you've made from the diff.