Skip to content

Instantly share code, notes, and snippets.

@pure
Created October 17, 2013 21:09
Show Gist options
  • Save pure/7032248 to your computer and use it in GitHub Desktop.
Save pure/7032248 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://pure.github.io/pure/libs/pure.js"></script>
</head>
<body>
<!-- main template -->
<div class="animals">
<select class="food">
<option></option>
</select>
</div>
<!-- sub template -->
<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 = {
'option':{
'food<-':{
'.':'food'
}
}
},
//compile the sub template as a JS function
foodCompiled = $p('.food').compile(dirFood),
dirAnimals = {
'select':{
'animal<-animals':{
'@class':'animal.name',
'.':function(){
return foodCompiled( this.food ).replace(/\s*<\/?select[^\>]*>\s*/g, '');
}
}
}
};
$('.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