diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-04-25 13:52:56 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-04-25 13:52:56 +0200 |
commit | 4aed2cf65240abb26384d7d86ccb27b171e6bb9a (patch) | |
tree | 949ede45c93c37215c44bd1b190248d7669501b0 /lib/models | |
parent | 244fb0ca28f29ac429f58e0e885d21cc6c40beba (diff) | |
download | gitbook-4aed2cf65240abb26384d7d86ccb27b171e6bb9a.zip gitbook-4aed2cf65240abb26384d7d86ccb27b171e6bb9a.tar.gz gitbook-4aed2cf65240abb26384d7d86ccb27b171e6bb9a.tar.bz2 |
Add post processing for templates
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} |