diff options
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/templateBlock.js | 23 | ||||
-rw-r--r-- | lib/models/templateEngine.js | 13 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/models/templateBlock.js b/lib/models/templateBlock.js index cce636e..4094b89 100644 --- a/lib/models/templateBlock.js +++ b/lib/models/templateBlock.js @@ -9,12 +9,24 @@ var NODE_ENDARGS = '%%endargs%%'; var blockBodies = {}; var TemplateBlock = Immutable.Record({ + // Name of block, also the start tag name: String(), + + // End tag, default to "end<name>" end: String(), + + // Function to process the block content process: Function(), + + // List of String, for inner block tags blocks: Immutable.List(), + + // List of shortcuts to replace with this block shortcuts: Immutable.List(), + + // Function to execute in post processing post: null, + parse: true }, 'TemplateBlock'); @@ -208,6 +220,7 @@ TemplateBlock.prototype.handleBlockResult = function(result) { if (is.string(result)) { result = { body: result }; } + result.name = this.getName(); return result; }; @@ -251,6 +264,16 @@ TemplateBlock.indexBlockResult = function(blk) { }; /** + Get a block results indexed for a specific key + + @param {String} key + @return {Object|undefined} +*/ +TemplateBlock.getBlockResultByKey = function(key) { + return blockBodies[key]; +}; + +/** Create a template block from a function or an object @param {String} blockName diff --git a/lib/models/templateEngine.js b/lib/models/templateEngine.js index 9a18bd4..28322ea 100644 --- a/lib/models/templateEngine.js +++ b/lib/models/templateEngine.js @@ -43,6 +43,19 @@ TemplateEngine.prototype.getContext = function() { }; /** + Return a block by its name (or undefined) + + @param {String} name + @return {TemplateBlock} +*/ +TemplateEngine.prototype.getBlock = function(name) { + var blocks = this.getBlocks(); + return blocks.find(function(block) { + return block.getName() === name; + }); +}; + +/** Return a nunjucks environment from this configuration @return {Nunjucks.Environment} |