var items = [ "x" , "y" ];
< div >
< div id ="some" class ="some-class" >
some div
</ div >
some text
< div > x </ div >
< div > y </ div >
</ div >
var result;
with (Htmls) {
result = div(
div({ id: "some" , class : "some-class" },
"some div" ),
"some text" ,
items.map( function (i) {
return div(i);
}))
.outerHTML;
}
* This source code was highlighted with Source Code Highlighter .
data = {
title: 'C pocket reference' ,
type: 'PDF Document' ,
tag: 'programming' ,
created_at: '5.31.2010'
}
with (Htmls) {
var tagUrl = "tags/" + data.tag;
var result = tr(
td(data.title),
td(data.type),
td(a({href: tagUrl}, data.tag)),
td(data.created_at))
.outerHTML;
}
* This source code was highlighted with Source Code Highlighter .
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);
}
//
}
})();
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/96636/
All Articles