Comparing version 0.0.1 to 0.0.2
48
index.js
@@ -0,1 +1,7 @@ | ||
/** | ||
* Flexible template engine powered by ES6 template strings. | ||
* | ||
* @author Wells Johnston <wells@littlstar.com> | ||
*/ | ||
'use strict' | ||
@@ -7,7 +13,16 @@ | ||
var odesza = {}; | ||
module.exports = odesza; | ||
odesza.render = (path, vars) => { | ||
/** | ||
* Renders a template with the given variables. | ||
* | ||
* @param {string} template The template to render. | ||
* @param {object} vars An object of key-value pairs representing the | ||
* variables to be used in the template. | ||
* @return {string} The rendered template. | ||
*/ | ||
odesza.render = (template, vars) => { | ||
try { | ||
let t = fs.readFileSync(path).toString(); | ||
return vm.runInNewContext('`' + t + '`', vars); | ||
return vm.runInNewContext('`' + template + '`', vars); | ||
} catch (e) { | ||
@@ -18,6 +33,27 @@ throw new Error(e); | ||
/** | ||
* @param {string} path The path to the template file. | ||
* @param {object} options Options passed in to render the template. | ||
* @return {string} The rendered template. | ||
*/ | ||
odesza.compile = (path, options) => { | ||
try { | ||
var template = fs.readFileSync(path).toString(); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
return this.render(template, options); | ||
}; | ||
/** | ||
* Adds support for express. | ||
* | ||
* @param {string} path | ||
* @param {object} options | ||
* @param {function} fn | ||
*/ | ||
odesza.__express = (path, options, fn) => { | ||
return fn(this.render()); | ||
return fn(this.compile(path, options)); | ||
}; | ||
module.exports = odesza; |
{ | ||
"name": "odesza", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Flexible templates powered by ES6 template strings.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1404
48