Skip to content

Instantly share code, notes, and snippets.

@patrick-steele-idem
Created July 28, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrick-steele-idem/0514b480219d1c9ed8d4 to your computer and use it in GitHub Desktop.
Save patrick-steele-idem/0514b480219d1c9ed8d4 to your computer and use it in GitHub Desktop.
Compiled template output (Marko FTW!)
module.exports=function anonymous(it
/**/) {
var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : (function (doNotSkipEncoded) {
var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': "&#34;", "'": "&#39;", "/": "&#47;" },
matchHTML = doNotSkipEncoded ? /[&<>"'\/]/g : /&(?!#?\w+;)|<|>|"|'|\//g;
return function(code) {
return code ? code.toString().replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : "";
};
}());var out='Hello '+encodeHTML(it.name)+'! ';if(it.colors && it.colors.length){out+=' <ul> ';var arr1=it.colors;if(arr1){var color,i1=-1,l1=arr1.length-1;while(i1<l1){color=arr1[i1+=1];out+=' <li class="color">'+encodeHTML(color)+'</li> ';} } out+='</ul>';}else{out+='<div> No colors!</div>';}return out;
}
(function(dust){dust.register("simple-1",body_0);function body_0(chk,ctx){return chk.w("Hello ").f(ctx.get(["name"], false),ctx,"h").w("!").x(ctx.get(["colors"], false),ctx,{"else":body_1,"block":body_2},{});}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("<div>No colors!</div>");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.w(" <ul>").s(ctx.get(["colors"], false),ctx,{"block":body_3},{}).w("</ul>");}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("<li class=\"color\">").f(ctx.getPath(true, []),ctx,"h").w("</li>");}body_3.__dustBody=!0;return body_0}(dust));
(function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates["simple-1"] = template({"1":function(depth0,helpers,partials,data) {
var stack1;
return "<ul>\n"
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.colors : depth0),{"name":"each","hash":{},"fn":this.program(2, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
+ "</ul>\n";
},"2":function(depth0,helpers,partials,data) {
return " <li class=\"color\">"
+ this.escapeExpression(this.lambda(depth0, depth0))
+ "</li>\n";
},"4":function(depth0,helpers,partials,data) {
return "<div>\n No colors!\n</div>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper;
return "Hello "
+ this.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0,{"name":"name","hash":{},"data":data}) : helper)))
+ "!\n \n"
+ ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.colors : depth0),{"name":"if","hash":{},"fn":this.program(1, data, 0),"inverse":this.program(4, data, 0),"data":data})) != null ? stack1 : "");
},"useData":true});})();
function template(locals) {
var buf = [];
var jade_mixins = {};
var jade_interp;
;var locals_for_with = (locals || {});(function (colors, name, undefined) {
buf.push(jade.escape(null == (jade_interp = 'Hello ' + name + '!') ? "" : jade_interp));
if ( colors && colors.length)
{
buf.push("<ul>");
// iterate colors
;(function(){
var $$obj = colors;
if ('number' == typeof $$obj.length) {
for (var $index = 0, $$l = $$obj.length; $index < $$l; $index++) {
var color = $$obj[$index];
buf.push("<li class=\"color\">" + (jade.escape(null == (jade_interp = color) ? "" : jade_interp)) + "</li>");
}
} else {
var $$l = 0;
for (var $index in $$obj) {
$$l++; var color = $$obj[$index];
buf.push("<li class=\"color\">" + (jade.escape(null == (jade_interp = color) ? "" : jade_interp)) + "</li>");
}
}
}).call(this);
buf.push("</ul>");
}
if ( !colors || !colors.length)
{
buf.push("<div>No colors!</div>");
}}.call(this,"colors" in locals_for_with?locals_for_with.colors:typeof colors!=="undefined"?colors:undefined,"name" in locals_for_with?locals_for_with.name:typeof name!=="undefined"?name:undefined,"undefined" in locals_for_with?locals_for_with.undefined:typeof undefined!=="undefined"?undefined:undefined));;return buf.join("");
}
function create(__helpers) {
var str = __helpers.s,
empty = __helpers.e,
notEmpty = __helpers.ne,
escapeXml = __helpers.x,
forEach = __helpers.f;
return function render(data, out) {
out.w('Hello ' +
escapeXml(data.name) +
'! ');
if (notEmpty(data.colors)) {
out.w('<ul>');
forEach(data.colors, function(color) {
out.w('<li class="color">' +
escapeXml(color) +
'</li>');
});
out.w('</ul>');
}
else {
out.w('<div>No colors!</div>');
}
};
}
(module.exports = require("marko").c(__filename)).c(create);
(function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["simple-1"] = (function() {function root(env, context, frame, runtime, cb) {
var lineno = null;
var colno = null;
var output = "";
try {
output += "Hello ";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "name"), env.opts.autoescape);
output += "!\n \n";
if(runtime.contextOrFrameLookup(context, frame, "colors") && runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "colors")),"length", env.opts.autoescape)) {
output += "\n<ul>\n ";
frame = frame.push();
var t_3 = runtime.contextOrFrameLookup(context, frame, "colors");
if(t_3) {var t_2 = t_3.length;
for(var t_1=0; t_1 < t_3.length; t_1++) {
var t_4 = t_3[t_1];
frame.set("color", t_4);
frame.set("loop.index", t_1 + 1);
frame.set("loop.index0", t_1);
frame.set("loop.revindex", t_2 - t_1);
frame.set("loop.revindex0", t_2 - t_1 - 1);
frame.set("loop.first", t_1 === 0);
frame.set("loop.last", t_1 === t_2 - 1);
frame.set("loop.length", t_2);
output += "\n <li class=\"color\">";
output += runtime.suppressValue(t_4, env.opts.autoescape);
output += "</li>\n ";
;
}
}
frame = frame.pop();
output += "\n</ul>\n";
;
}
else {
output += "\n<div>\n No colors!\n</div>\n";
;
}
cb(null, output);
;
} catch (e) {
cb(runtime.handleError(e, lineno, colno));
}
}
return {
root: root
};
})();
})();
module.exports=function (_swig,_ctx,_filters,_utils,_fn
/**/) {
var _ext = _swig.extensions,
_output = "";
_output += "Hello ";
_output += _filters["e"]((((typeof _ctx.name !== "undefined" && _ctx.name !== null) ? ((typeof _ctx.name !== "undefined" && _ctx.name !== null) ? _ctx.name : "") : ((typeof name !== "undefined" && name !== null) ? name : "")) !== null ? ((typeof _ctx.name !== "undefined" && _ctx.name !== null) ? ((typeof _ctx.name !== "undefined" && _ctx.name !== null) ? _ctx.name : "") : ((typeof name !== "undefined" && name !== null) ? name : "")) : "" ));
_output += "!\n \n";
if ((((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? _ctx.colors : "") : ((typeof colors !== "undefined" && colors !== null) ? colors : "")) !== null ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? _ctx.colors : "") : ((typeof colors !== "undefined" && colors !== null) ? colors : "")) : "" ) && (((typeof _ctx.colors !== "undefined" && _ctx.colors !== null && _ctx.colors.length !== undefined && _ctx.colors.length !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null && _ctx.colors.length !== undefined && _ctx.colors.length !== null) ? _ctx.colors.length : "") : ((typeof colors !== "undefined" && colors !== null && colors.length !== undefined && colors.length !== null) ? colors.length : "")) !== null ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null && _ctx.colors.length !== undefined && _ctx.colors.length !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null && _ctx.colors.length !== undefined && _ctx.colors.length !== null) ? _ctx.colors.length : "") : ((typeof colors !== "undefined" && colors !== null && colors.length !== undefined && colors.length !== null) ? colors.length : "")) : "" )) {
_output += "\n<ul>\n ";
(function () {
var __l = (((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? _ctx.colors : "") : ((typeof colors !== "undefined" && colors !== null) ? colors : "")) !== null ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? ((typeof _ctx.colors !== "undefined" && _ctx.colors !== null) ? _ctx.colors : "") : ((typeof colors !== "undefined" && colors !== null) ? colors : "")) : "" ), __len = (_utils.isArray(__l) || typeof __l === "string") ? __l.length : _utils.keys(__l).length;
if (!__l) { return; }
var _ctx__loopcache04097393217962235 = { loop: _ctx.loop, color: _ctx.color, __k: _ctx.__k };
_ctx.loop = { first: false, index: 1, index0: 0, revindex: __len, revindex0: __len - 1, length: __len, last: false };
_utils.each(__l, function (color, __k) {
_ctx.color = color;
_ctx.__k = __k;
_ctx.loop.key = __k;
_ctx.loop.first = (_ctx.loop.index0 === 0);
_ctx.loop.last = (_ctx.loop.revindex0 === 0);
_output += "\n <li class=\"color\">";
_output += _filters["e"]((((typeof _ctx.color !== "undefined" && _ctx.color !== null) ? ((typeof _ctx.color !== "undefined" && _ctx.color !== null) ? _ctx.color : "") : ((typeof color !== "undefined" && color !== null) ? color : "")) !== null ? ((typeof _ctx.color !== "undefined" && _ctx.color !== null) ? ((typeof _ctx.color !== "undefined" && _ctx.color !== null) ? _ctx.color : "") : ((typeof color !== "undefined" && color !== null) ? color : "")) : "" ));
_output += "</li>\n ";
_ctx.loop.index += 1; _ctx.loop.index0 += 1; _ctx.loop.revindex -= 1; _ctx.loop.revindex0 -= 1;
});
_ctx.loop = _ctx__loopcache04097393217962235.loop;
_ctx.color = _ctx__loopcache04097393217962235.color;
_ctx.__k = _ctx__loopcache04097393217962235.__k;
_ctx__loopcache04097393217962235 = undefined;
})();
_output += "\n</ul>\n";
} else {
_output += "\n<div>\n No colors!\n</div>\n";
}
return _output;
}
@patrick-steele-idem
Copy link
Author

The output shown in this Gist was taken from the following project: https://github.com/marko-js/templating-benchmarks

You can find the source template files in the following directory: https://github.com/marko-js/templating-benchmarks/tree/master/templates/simple-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment