Mustache (http://mustache.github.com/) is a simple simple template language without any logical solutions. It has implementations in both Javascript and Ruby, so templates can be displayed in any environment.
A little harder to use than RJS (or similar template languages). Since templates do not have logic, JSON objects must be extended with functions to provide more complex behavior.
Here is a markup example:
<div id="person_image"><img src="{{avatar_url}}"></img></div> <div class="info"> <div id="person_location">{{location}}</div> <h2 class="name">{{name}}</h2> <div id="person_positions"> <ul class="positions"> {{#positions}} <li>{{company_name}} — {{title}}</li> {{/positions}} </ul> </div> <div id="person_social_links"> <div class="social-profiles research-links"> {{#links}} <a href="{{url}}" class="branded" target="_blank" style="background-image:url(https://www.google.com/s2/favicons?domain={{name}})"></a> {{/links}} </div> </div> </div>
What this object will display:
{ "id":"4c0578d940cfd305ff00011c", "name":"Steve Someguy", "location":"Austin, Texas, United States", "positions":[ {"title":"CEO", "company_name":"ACME, Inc.", "company_id":null}, {"title":"Director", "company_name":"Capsasin, Inc.", "company_id":"4c0578d940cfd305ff00011c"} ], "links":[ {"name":"twitter.com","url":"http://twitter.com/spicyjs","image_url":"http://a3.twimg.com/profile_images/439463427/Picture_7_bigger.png"}, {"name":"twitter.com","url":"http://twitter.com/shadr","image_url":"http://a1.twimg.com/profile_images/20072132/me.jpg"}, {"name":"facebook.com","url":"http://facebook.com/shad.reynolds","image_url":"http://www.facebook.com/profile/pic.php?uid=AAAAAQAQm2JvEZLOpW8bCG-rToD8VQAAAAlFjZG9cIKwaX2wuA_Nspjn"} ] }
Handlebars.js is a related project that also gets some traction, although the Ruby implementation does not seem complete (http://yehudakatz.com/2010/09/09/announcing-handlebars-js/).
user185871
source share