parser.js
1 KB
define(["parser/html", "parser/css", "parser/js", 'jquery'], function(htmlParser, cssParser, jsParser) {
var template = "\
{html.doctype}\
<html>\
<head>\
{html.stuffForHead}\
{css.external}\
<style type='text/css'>{css.inbody ? '' : css.code}</style>\
</head>\
<body>\
<style type='text/css'>{css.inbody ? css.code : ''}</style>\
{html.code}\
{javascript.external}\
<script type='text/javascript'>{javascript.code}</script>\
</body>\
</html>\
";
return function(settings) {
return $.when( htmlParser(settings.html), cssParser(settings.css), jsParser(settings.javascript) )
.then(function() {
return template.replace(/{([\s\S]*?)}/g, function(match, property) {
var render = "with(this){ return " + property + "}";
var _render = new Function(render).bind(settings);
return _render();
});
});
};
});