Skip to content

Instantly share code, notes, and snippets.

@pure
Created February 6, 2013 08:44
Show Gist options
  • Save pure/4721220 to your computer and use it in GitHub Desktop.
Save pure/4721220 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://github.com/pure/pure/raw/master/libs/pure.js"></script>
</head>
<body>
<!-- main template -->
<ul class="animals">
<li></li>
</ul>
<!-- sub template -->
<ol class="food">
<li></li>
</ol>
<script>
var data = {animals:[
{name:'bird', food:['seed','worm']},
{name:'cat', food:['mouse', 'bird']},
{name:'dog', food:['meat', 'bone']},
{name:'mouse', food:['cheese', 'books']}
]},
dirFood = {
'li':{
'food<-':{
'.':'food'
}
}
},
//compile the sub template as a JS function
foodCompiled = $p('.food').compile(dirFood),
dirAnimals = {
'li':{
'animal<-animals':{
'.':'animal.name',
'.+':function(){
//append to the current LI the subtemplate
return foodCompiled( this.food );
}
}
}
};
$('.animals').render(data, dirAnimals);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment