Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Created February 15, 2016 03:23
Show Gist options
  • Save lsongdev/93d5ef9596283036374c to your computer and use it in GitHub Desktop.
Save lsongdev/93d5ef9596283036374c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
var obj = {};
[ 'html', 'head', 'title', 'meta', 'body', 'div', 'h1', 'li' ].forEach(function(key){
obj[ key ] = (function createMarkup(tagName){
return function(attrs){
attrs = Object.keys(attrs || []).map((attr)=> [ attr, '"' + attrs[attr] + '"' ].join('=')).join(' ');
return function(children){
children = [].slice.call(arguments).join('');
return [ '<' + tagName + ' ' + attrs + '>' , children, '</' + tagName + '>' ].join('');
}
};
})(key);
});
var arr = [1, 2, 3, 4, 5];
with(obj){
var page = html({ lang: 'en' })(
head()(
title()("hello"),
meta({ name: 'charset', value: 'utf-8' })('meta')
),
body({ class: [ 'app' ] })(
div({ id: 'container' })(
h1()("hello world"),
arr.map((i)=> li()(i * 3))
)
)
);
console.log(page);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment