Reference Error: options is not defined
alekperos opened this issue · 0 comments
alekperos commented
Hi, thanks for the great job.
There is an issue with this engine, it throws Reference Error: options is not defined
with the example you gave in documentation:
var just = new JUST({ root : {
layout: '<span><%= title %></span><p>Page content</p>',
page: '<%! layout %><p>Page content</p>'
}, useCache : true
});
just.render('layout', { title: 'Hello, World!' }, function(error, html) {
...
});
I have traced the error and it actually comes from the read = function ...
function. Original code is like this in the functions body try ... catch
block:
try {
var data = eval('(options.root.' + file + ')');
if (Object.prototype.toString.call(data) === '[object String]') {
callback(undefined, data);
} else {
callback('Failed to load template');
}
} catch (e) {
callback(e);
}
The problem is around eval
function which actually does its job in global scope, where options
is not defined, hence throwing the mentioned error. If you change the code like as follows, works like a charm :
try {
var data = options.root ? options.root[file] : null;
if ( data && Object.prototype.toString.call(data) === '[object String]') {
callback(undefined, data);
} else {
callback('Failed to load template');
}
} catch (e) {
callback(e);
}
I have created online demos for non working one with original source:
http://codepen.io/anon/pen/efACn
... working one, with the modification
http://codepen.io/anon/pen/CFhGp
hope this helps.