Skip to content

Instantly share code, notes, and snippets.

@wilkerlucio
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save wilkerlucio/1f5d54eaf21f9dcf92da to your computer and use it in GitHub Desktop.

Select an option

Save wilkerlucio/1f5d54eaf21f9dcf92da to your computer and use it in GitHub Desktop.
var Template = {
compile: function(string, builder) {
var rootNode = $(string);
var map = {};
rootNode.find("[data-binding]").each(function () {
var el = $(this);
var bindingName = el.data("binding");
map[bindingName] = el;
});
builder(map);
return rootNode;
},
fromId: function(id, builder) {
var templateString = $("#" + id).html();
return Template.compile(templateString, builder);
}
};
var samplePerson = {
name: "Walter White",
email: "mrwhite@bitches.com"
};
var personView = function(person) {
return Template.fromId("person-template", function(map) {
map.name.text(person.name);
map.email.text(person.email);
});
};
$("#template-demo").append(personView(samplePerson));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment