summaryrefslogtreecommitdiff
path: root/app/node_modules/oktemplate/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-07 22:52:39 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-07 22:52:39 -0400
commit007384de007844e865bf906b8cb6eadaed4027e6 (patch)
tree57926bb03ba60fcd1bd4131b665698bd96c210df /app/node_modules/oktemplate/index.js
parentc4a05d608d59a178dbdb7494fedb7a63cf55f96f (diff)
Add partials support in templates
Diffstat (limited to 'app/node_modules/oktemplate/index.js')
-rw-r--r--app/node_modules/oktemplate/index.js29
1 files changed, 15 insertions, 14 deletions
diff --git a/app/node_modules/oktemplate/index.js b/app/node_modules/oktemplate/index.js
index 65f8c18..700020c 100644
--- a/app/node_modules/oktemplate/index.js
+++ b/app/node_modules/oktemplate/index.js
@@ -2,13 +2,12 @@ var fs = require('fs');
var path = require('path');
var glob = require('glob');
var stringify = require('json-to-html');
-var LiquidEngine = require('liquid-node').Engine;
-var liquid = new LiquidEngine();
+var Liquid = require('liquid-node');
/**
- * Add any custom liquid filters here.
+ * Define any custom liquid filters here.
*/
-liquid.registerFilters({
+var filters = {
/**
* Return a string formatted version of a JSON object.
@@ -22,17 +21,20 @@ liquid.registerFilters({
}
}
-});
+};
/**
* Manages templates. Only supports Mustache currently/
*/
function OKTemplateRepo(options) {
options = options || {};
- this._root = options.root || 'templates';
- this._extPattern = options.ext || '.+(liquid|html)';
- this._cache = {};
- this._populateCache(this._cache);
+ var root = this._root = options.root || 'templates';
+ var ext = 'liquid';
+ var cache = this._cache = {};
+ var engine = this._engine = new Liquid.Engine;
+ engine.registerFilters(filters);
+ engine.fileSystem = new Liquid.LocalFileSystem(root, ext);
+ this._populateCache(engine, cache, ext);
}
OKTemplateRepo.prototype.getTemplate = function getTemplate(name) {
@@ -44,19 +46,18 @@ OKTemplateRepo.prototype.getTemplate = function getTemplate(name) {
* into memory as strings.
* Assumes all templates fit into memory.
*/
-OKTemplateRepo.prototype._populateCache = function _populateCache(cache) {
+OKTemplateRepo.prototype._populateCache = function _populateCache(engine, cache, ext) {
var self = this;
- var files = glob.sync(this._root + '/*' + this._extPattern);
+ var files = glob.sync(this._root + '/*.' + ext);
files.forEach(function eachFile(file) {
- var ext = path.extname(file);
- var name = path.basename(file, ext);
+ var name = path.basename(file, '.' + ext);
var templateString = fs.readFileSync(file, {encoding: 'UTF8'});
cache[name] = {
name: name,
templateString: templateString,
render: function(data) {
// TODO Not sure if this caches parsed templates behind the scenes?
- return liquid.parseAndRender(templateString, data);
+ return engine.parseAndRender(templateString, data);
}
}
});