summaryrefslogtreecommitdiff
path: root/app/node_modules/oktemplate/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-01 18:27:51 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-01 18:27:51 -0400
commit2e041ff6cd1b40c26bf16d37777c2c1c5153a669 (patch)
tree1e427659faf343bf42795beae8980000436617b8 /app/node_modules/oktemplate/index.js
parentae24790e8122296b06f88fa883b8e272c6454d46 (diff)
Bootstrappin young lad
Diffstat (limited to 'app/node_modules/oktemplate/index.js')
-rw-r--r--app/node_modules/oktemplate/index.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/node_modules/oktemplate/index.js b/app/node_modules/oktemplate/index.js
new file mode 100644
index 0000000..4aec98b
--- /dev/null
+++ b/app/node_modules/oktemplate/index.js
@@ -0,0 +1,36 @@
+var fs = require('fs');
+var path = require('path');
+var glob = require('glob');
+var hogan = require('hogan.js');
+
+/**
+ * Manages templates. Only supports Mustache currently/
+ */
+function OKTemplateRepo(options) {
+ options = options || {};
+ this._root = options.root || 'www';
+ this._ext = options.ext || '.mustache';
+ this._cache = {};
+ this._populateCache(this._cache);
+}
+
+OKTemplateRepo.prototype.getTemplate = function getTemplate(name) {
+ return this._cache[name];
+}
+
+/**
+ * Go through our template dir and read the template files
+ * into memory as strings.
+ * Assumes all templates fit into memory.
+ */
+OKTemplateRepo.prototype._populateCache = function _populateCache(cache) {
+ var self = this;
+ var files = glob.sync(this._root + '/*' + this._ext);
+ files.forEach(function eachFile(file) {
+ var name = path.basename(file, self._ext);
+ var templateString = fs.readFileSync(file, {encoding: 'UTF8'});
+ cache[name] = hogan.compile(templateString);
+ });
+}
+
+module.exports = OKTemplateRepo;