summaryrefslogtreecommitdiffstats
path: root/lib/template/index.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-11 17:30:58 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-11 17:30:58 +0100
commit98a13cf487e3b2823cfde38ab1d1b8f97f614517 (patch)
tree81d07c7095822867ba180a79e9a5b1343d81de0e /lib/template/index.js
parent7f9aa214a412f3d173ac52042bd7250aacda6143 (diff)
downloadgitbook-98a13cf487e3b2823cfde38ab1d1b8f97f614517.zip
gitbook-98a13cf487e3b2823cfde38ab1d1b8f97f614517.tar.gz
gitbook-98a13cf487e3b2823cfde38ab1d1b8f97f614517.tar.bz2
Add conrefs loader for nunjucks
Diffstat (limited to 'lib/template/index.js')
-rw-r--r--lib/template/index.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/template/index.js b/lib/template/index.js
index 833ff76..a3021e6 100644
--- a/lib/template/index.js
+++ b/lib/template/index.js
@@ -7,6 +7,7 @@ var Promise = require('../utils/promise');
var error = require('../utils/error');
var gitbook = require('../gitbook');
var defaultBlocks = require('./blocks');
+var Loader = require('./loader');
// Return extension name for a specific block
function blockExtName(name) {
@@ -23,6 +24,10 @@ function TemplateEngine(book) {
this.book = book;
this.log = book.log;
+ // Create file loader
+ this.loader = new Loader(this);
+
+ // Create nunjucks instance
this.env = new nunjucks.Environment(
this.loader,
{
@@ -57,6 +62,14 @@ function TemplateEngine(book) {
this.addBlocks(defaultBlocks);
}
+// Interpolate a string content to replace shortcuts according to the filetype
+TemplateEngine.prototype.interpolate = function(filepath, source) {
+ var parser = parsers.get(path.extname(filepath));
+ var type = parser? parser.name : null;
+
+ return this.applyShortcuts(type, source);
+};
+
// Add a new custom filter
TemplateEngine.prototype.addFilter = function(filterName, func) {
try {