Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference Error: options is not defined #3

Open
alekperos opened this issue Jul 17, 2013 · 0 comments
Open

Reference Error: options is not defined #3

alekperos opened this issue Jul 17, 2013 · 0 comments

Comments

@alekperos
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant