So, I write it by myself.
Htmls = (function () {
function initTag(tag, args) {
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if (arg.constructor == String) {
tag.innerHTML += arg;
}
else if(arg instanceof HTMLElement) {
tag.appendChild(arg);
}
else if (arg.constructor == Array) {
initTag(tag, arg);
}
else if (arg.constructor == Object) {
for (var j in arg) {
tag.setAttribute(j, arg[j]);
}
}
}
return tag;
}
function createTag(name, args) {
return initTag(document.createElement(name), args);
}
return {
div: function () {
return createTag("div", arguments);
}
}
})();
test("complete test", function() {
with(Htmls){
var items = ["x","y"];
var d = div(
div({id:"some", class:"some-class"}, "some div"),
"some text",
items.map(function(i){
return div(i)
}));
equals(div(d).innerHTML,
'<div><div class="some-class" id="some">some div</div>some text'
+ '<div>x</div><div>y</div></div>');
}
});