Created
May 8, 2012 22:00
-
-
Save niklasvincent/2639727 to your computer and use it in GitHub Desktop.
Sammy.js + Mustache + seamless presentation of REST API data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var model = { | |
'/animals': { | |
'verb': "get", | |
'template': '<div id="animal-{{ID}}"> \ | |
<a href="#/animals/{{ID}}"><h2>{{title}}</h2></a> \ | |
<h3>{{time_added}}</h3> \ | |
<img src="{{thumbnail.0}}" /></div>' | |
}, | |
'/animals/:ID': { | |
'verb': "get", | |
'template': '<div id="animal-{{ID}}"> \ | |
<a href="#/animals/{{ID}}"> \ | |
<h2>{{title}}</h2></a> \ | |
{{#attachments.images}} \ | |
<img width="200px" src="{{url}}" /> \ | |
{{/attachments.images}}<div id="content"> \ | |
</div>', | |
'after': 'renderContent' | |
} | |
}; | |
function renderContent(data) { | |
$('#content').html(data.content); | |
} | |
// start the application | |
$(document).ready(function() { | |
vertebrate_init(app); | |
app.run('#/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment