Comparing version 0.0.1 to 0.1.0
@@ -17,2 +17,3 @@ var defaults = { | ||
* - `debug` include debugging information | ||
* - `errorFn` a function to log runtime errors | ||
* | ||
@@ -37,3 +38,3 @@ * @param {Options} opts | ||
var code = fest.compile(path, options), | ||
tmpl = (new Function('return ' + code))(); | ||
tmpl = (new Function('__fest_error', 'return ' + code))(options.errorFn); | ||
cache[path] = { | ||
@@ -44,3 +45,3 @@ ts: ts, | ||
fn(null, tmpl(data)); | ||
} catch(err) { | ||
} catch (err) { | ||
fn(err); | ||
@@ -77,2 +78,3 @@ } | ||
* - `debug` include debugging information | ||
* - `errorFn` a function to log runtime errors | ||
* | ||
@@ -96,3 +98,3 @@ * @param {Options} opts | ||
var code = fest.compile(path, options), | ||
tmpl = (new Function('return ' + code))(); | ||
tmpl = (new Function('__fest_error', 'return ' + code))(options.errorFn); | ||
cache[path] = { | ||
@@ -99,0 +101,0 @@ ts: ts, |
{ | ||
"name": "artist", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Template engine built on Fest (javascript templates)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,10 @@ # Artist | ||
Features: | ||
* Caches compiled templates | ||
* Auto regenerates the cache on files change | ||
* Synchronous and asynchronous versions | ||
* Express-compatible | ||
* Handles Fest's runtime errors | ||
## Installation | ||
@@ -15,2 +23,4 @@ | ||
See sources for documentation. | ||
Express: | ||
@@ -17,0 +27,0 @@ |
var assert = require('assert'), | ||
artist = require('..'); | ||
describe('api', function() { | ||
it('.render(opts)', function () { | ||
var render = artist.renderSync(); | ||
// init | ||
assert.equal(render(__dirname + '/test.xml', {foo: 'bar'}), 'bar'); | ||
// cache | ||
assert.equal(render(__dirname + '/test.xml', {foo: 'bar'}), 'bar'); | ||
try { | ||
render(__dirname + '/nonexistent.xml', {foo: 'bar'}); | ||
assert.equal(false, true); | ||
} catch (err) { | ||
assert.equal(err.code, 'ENOENT'); | ||
} | ||
describe("api", function() { | ||
describe(".render(opts)", function () { | ||
it("should invoke the function with null and a string", function () { | ||
var errors = [], | ||
render = artist.render({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
// compile | ||
render(__dirname + '/test.xml', {foo: 'bar'}, function (err, str) { | ||
assert.equal(err, null); | ||
assert.equal(str, 'bar'); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
// from cache | ||
render(__dirname + '/test.xml', {foo: 'bar'}, function (err, str) { | ||
assert.equal(err, null); | ||
assert.equal(str, 'bar'); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
}); | ||
it("should invoke the function with an error when the file doesn't exist", function () { | ||
var errors = [], | ||
render = artist.render({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
render(__dirname + '/nonexistent.xml', {}, function (err, str) { | ||
assert.notEqual(err, null); | ||
assert.equal(err.code, 'ENOENT'); | ||
assert.equal(str, undefined); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
}); | ||
it("should invoke the function with an error when the file contains syntax errors", function () { | ||
var errors = [], | ||
render = artist.render({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
render(__dirname + '/error-syntax.xml', {}, function (err, str) { | ||
assert.notEqual(err, null); | ||
assert(err.message.match(/Unexpected close tag/)); | ||
assert.equal(str, undefined); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
}); | ||
it("should log an message when the file contains runtime error", function () { | ||
var errors = [], | ||
render = artist.render({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
render(__dirname + '/error-runtime.xml', {}, function (err, str) { | ||
assert.equal(err, null); | ||
assert.equal(str, ''); | ||
assert.deepEqual(errors, [ | ||
"Cannot read property 'bar' of undefined2\nin block \"fest:value\" at line: 2\nfile: /Users/eprev/projects/WGD/artist/test/error-runtime.xml" | ||
]); | ||
}); | ||
}); | ||
}); | ||
it('.renderSync(opts)', function () { | ||
var render = artist.render(); | ||
// init | ||
render(__dirname + '/test.xml', {foo: 'bar'}, function (err, str) { | ||
assert.strictEqual(err, null); | ||
assert.equal(str, 'bar'); | ||
describe(".renderSync(opts)", function () { | ||
it("should return a string", function () { | ||
var errors = [], | ||
render = artist.renderSync({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
// compile | ||
assert.equal(render(__dirname + '/test.xml', {foo: 'bar'}), 'bar'); | ||
// from cache | ||
assert.equal(render(__dirname + '/test.xml', {foo: 'bar'}), 'bar'); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
// cache | ||
render(__dirname + '/test.xml', {foo: 'bar'}, function (err, str) { | ||
assert.strictEqual(err, null); | ||
assert.equal(str, 'bar'); | ||
it("should throw an error when the file doesn't exist", function () { | ||
var errors = [], | ||
render = artist.renderSync({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
assert.throws(function () { | ||
render(__dirname + '/nonexistent.xml', {}); | ||
}, function (err) { | ||
return err.code === 'ENOENT'; | ||
}) | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
render(__dirname + '/nonexistent.xml', {foo: 'bar'}, function (err, str) { | ||
assert.notStrictEqual(err, null); | ||
assert.equal(err.code, 'ENOENT'); | ||
it("should throw an error when the file contains syntax errors", function () { | ||
var errors = [], | ||
render = artist.renderSync({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
assert.throws(function () { | ||
render(__dirname + '/error-syntax.xml', {}); | ||
}, 'Unexpected close tag'); | ||
// no runtime errors | ||
assert.deepEqual(errors, []); | ||
}); | ||
it("should log an message when the file contains runtime error", function () { | ||
var errors = [], | ||
render = artist.renderSync({ | ||
errorFn: function (err) { | ||
errors.push(err) | ||
} | ||
}); | ||
render(__dirname + '/error-runtime.xml', {}); | ||
assert.deepEqual(errors, [ | ||
"Cannot read property 'bar' of undefined2\nin block \"fest:value\" at line: 2\nfile: /Users/eprev/projects/WGD/artist/test/error-runtime.xml" | ||
]); | ||
}); | ||
}); | ||
}); |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
9879
9
223
48