Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
Created May 8, 2012 22:00
Show Gist options
  • Save niklasvincent/2639727 to your computer and use it in GitHub Desktop.
Save niklasvincent/2639727 to your computer and use it in GitHub Desktop.
Sammy.js + Mustache + seamless presentation of REST API data
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