Created
February 15, 2016 03:23
-
-
Save lsongdev/93d5ef9596283036374c 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
<!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