UNPKG

ziggurat.js

Version:

a tiny modular js library for templates and other shorthands

32 lines (31 loc) 1 kB
// Generated by CoffeeScript 2.7.0 // template creation zg.create = function(name, data) { var build, template; template = zg.queryone("zg-template#" + name); if (template == null) { throw new TypeError('no such template with name ' + name); } build = function(div, data) { var child, elements, i, len, new_elements, ref; elements = div.cloneNode(true); new_elements = []; ref = elements.childNodes; // compile every child for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; // depending on tag, replace with something switch (child.nodeName.toLowerCase()) { case "zg-var": child = document.createTextNode(zg.deepfind(data, child.innerHTML)); } // if the child has more children, build the child if (child.children != null) { child.replaceChildren(...(build(child, data))); } new_elements.push(child); } return new_elements; }; return HTML.div(build(template, data)); };