-
-
Save julien51/225525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildNode = function(tag, attrs){ | |
var node = document.createElement(tag); | |
for(var k in attrs) { | |
node.setAttribute(k, attrs[k]) | |
} | |
return node; | |
}; | |
text = function(text) { | |
return document.createTextNode(text); | |
}; | |
xml = function(tag, attrs, closure){ | |
var node = buildNode(tag, attrs); | |
if(closure) { | |
var scope = { | |
xml: function(tag, attrs, closure) { node.appendChild(xml(tag, attrs, closure));}, | |
text: function(t) { node.appendChild(text(t)); } | |
}; | |
closure.apply(scope); | |
} | |
return node; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment