hogan-engine
Advanced tools
Comparing version 0.9.0 to 0.9.1
var Hogan = require('hogan.js') | ||
, fs = require('fs'); | ||
, fs = require('fs') | ||
, pathjoin = require('path').join; | ||
@@ -10,12 +11,22 @@ | ||
if (options.cache && cache[path]) { | ||
if (!(options.settings && options.settings.views) && module.exports.root) { | ||
path = pathjoin(module.exports.root, path); | ||
} | ||
if ((options.cache || module.exports.cache) && cache[path]) { | ||
compiled = cache[path]; | ||
} else { | ||
var template = fs.readFileSync(path, 'utf8'); | ||
compiled = Hogan.compile(template); | ||
compiled.partials = {}; | ||
compilePartials(partialNames(template), options, compiled.partials); | ||
console.log('Reading file.'); | ||
cache[path] = compiled; | ||
try { | ||
var template = fs.readFileSync(path, 'utf8'); | ||
compiled = Hogan.compile(template); | ||
compiled.partials = {}; | ||
compilePartials(partialNames(template), options, compiled.partials); | ||
cache[path] = compiled; | ||
} catch (e) { | ||
return callback(e); | ||
} | ||
} | ||
@@ -30,3 +41,4 @@ | ||
if (!compiled[name]) { | ||
var path = options.settings.views + '/' + name; | ||
var root = ((options.settings && options.settings.views) || module.exports.root) | ||
, path = pathjoin(root, name); | ||
@@ -36,3 +48,3 @@ try { | ||
} catch (e) { | ||
e.message = 'Failed to load hogan partail with path: ' + path; | ||
e.message = 'Failed to load hogan partial with path: ' + path; | ||
throw e; | ||
@@ -39,0 +51,0 @@ } |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"homepage": "http://github.com/raycmorgan/hogan-engine", | ||
@@ -13,0 +13,0 @@ "author": "RayMorgan <raycmorgan@gmail.com>", |
@@ -5,3 +5,3 @@ # Hogan.js engine for Express 3.x | ||
npm install hogan-engine | ||
npm install hogan-engine | ||
@@ -33,3 +33,3 @@ ## Setup | ||
<h1>{{ titile }}</h1> | ||
<h1>{{ title }}</h1> | ||
@@ -39,2 +39,17 @@ {{> footer.html}} | ||
Notice we included a couple partials. You don't have to do anything more then | ||
have them in the views directory for them to be loaded and rendered. Easy. | ||
have them in the views directory for them to be loaded and rendered. Easy. | ||
## Usage outside of Express's render function | ||
var hogan = require('hogan-engine'); | ||
// Set the root of the template directory | ||
hogan.root = __dirname + '/views'; | ||
// Set cache to true to cache the templates, do this in production please | ||
hogan.cache = true; | ||
hogan('index.html', { title: 'Hello World' }, function (err, text) { | ||
// ... | ||
}); |
3111
48
53