How to use hogan.js.scan:
81 82 83 84 85 86 87 88 89 90
if (!cscan || cscan.mt<sta.mtime.valueOf()) { log("refreshing",ofile); // do actual compile fs.readFile(tfile,safe.sure(cb, function (content) { var ttext = content.toString(); var scan = hogan.scan(ttext); var partials = _(scan) .filter(function(item) { return item.tag == '>'; }) .map(function(item) { return item.n.replace(' this',''); }) .without(file)
How to use hogan.js.cacheKey:
3516 3517 3518 3519 3520 3521 3522 3523 3524 3525
return [text, !!options.asString, !!options.disableLambda, options.delimiters, !!options.modelGet].join('||'); } Hogan.compile = function(text, options) { options = options || {}; var key = Hogan.cacheKey(text, options); var template = this.cache[key]; if (template) { var partials = template.partials;
How to use hogan.js.wrapMain:
3376 3377 3378 3379 3380 3381 3382 3383 3384 3385
} return "partials: {" + partials.join(",") + "}, subs: " + stringifySubstitutions(codeObj.subs); } Hogan.stringify = function(codeObj, text, options) { return "{code: function (c,p,i) { " + Hogan.wrapMain(codeObj.code) + " }," + stringifyPartials(codeObj) + "}"; } var serialNo = 0; Hogan.generate = function(tree, text, options) {
How to use hogan.js.walk:
3383 3384 3385 3386 3387 3388 3389 3390 3391 3392
var serialNo = 0; Hogan.generate = function(tree, text, options) { serialNo = 0; var context = { code: '', subs: {}, partials: {} }; Hogan.walk(tree, context); if (options.asString) { return this.stringify(context, text, options); }
How to use hogan.js.Template:
3562 3563 3564 3565 3566 3567 3568 3569 3570 3571
this.partials = codeObj.partials || {}; this.subs = codeObj.subs || {}; this.buf = ''; } Hogan.Template.prototype = { // render: replaced by generated code. r: function (context, partials, indent) { return ''; }, // variable escaping
How to use hogan.js.compile:
88 89 90 91 92 93 94 95 96 97
engines: engines }); if (!view.path) { throw new Error('Could not find template file: ' + relativeTemplatePath); } const compiledTemplate = Hogan.compile(fs.readFileSync(view.path).toString()); compiled[relativeTemplatePath] = compiledTemplate; }); } catch (e) { return next(e);
See more examples