breezeblock
Advanced tools
Comparing version 0.2.0 to 0.2.1
39
index.js
@@ -35,5 +35,42 @@ exports.nodes = require('./lib/nodes'); | ||
*/ | ||
exports.asHTMLGenerator = function asHTMLGenerator(parsed, scope) { | ||
exports.asHTML = function asHTML(parsed, scope) { | ||
var ctx = new InterpreterContext(scope); | ||
return parsed.asHTML(ctx); | ||
}; | ||
/** | ||
* Parses and compiles the template at the provided path | ||
* @param {string} path Path to the file | ||
* @return {*} | ||
*/ | ||
exports.compileTemplate = function compileTemplate(path) { | ||
var source = require('fs').readFileSync(path).toString(); | ||
var parsed = exports.parse(source); | ||
return exports.asHTMLGenerator(parsed); | ||
}; | ||
/** | ||
* Parses and renders the template at the provided path | ||
* @param {string} path Path to the file | ||
* @param {object} options | ||
* @param {Function} cb Callback | ||
* @return {void} | ||
*/ | ||
exports.renderTemplate = function renderTemplate(path, options, cb) { | ||
require('fs').readFile(path, function(err, buf) { | ||
if (err) { | ||
cb(err, null); | ||
return; | ||
} | ||
var source = buf.toString(); | ||
var parsed = exports.parse(source); | ||
try { | ||
cb(null, exports.asHTML(parsed, options)); | ||
} catch (e) { | ||
cb(e, null); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "breezeblock", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A flexible JS-based templating engine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,3 +7,22 @@ # BreezeBlock | ||
```bash | ||
npm install breezeblock --save | ||
``` | ||
Using Breezeblock in Express: | ||
```js | ||
var express = require('express'); | ||
var app = express(); | ||
app.engine('brz', require('breezeblock').renderFile); | ||
app.set('view engine', 'brz'); | ||
app.get('/', function(req, res) { | ||
// This will render myTemplate.brz | ||
res.render('myTemplate', {foo: 'bar', my: 'variables'}); | ||
}); | ||
``` | ||
## Technique | ||
@@ -10,0 +29,0 @@ |
54090
1557
122
3