Merge pull request #250 from jsumners/missing-global

Make renderSync behave if no context was supplied
This commit is contained in:
Patrick Steele-Idem 2016-03-18 14:25:45 -06:00
commit f878db5545
3 changed files with 13 additions and 4 deletions

View File

@ -103,15 +103,16 @@ Template.prototype = {
this._ = createFunc(helpers);
},
renderSync: function(data) {
var localData = data || {};
var out = new AsyncWriter();
out.sync();
if (data.$global) {
out.global = extend(out.global, data.$global);
delete data.$global;
if (localData.$global) {
out.global = extend(out.global, localData.$global);
delete localData.$global;
}
this._(data, out);
this._(localData, out);
return out.getOutput();
},

View File

@ -256,6 +256,13 @@ describe('api' , function() {
expect(e).to.not.equal(undefined);
});
it('should handle no context passed to renderSync', function() {
var template = marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello-empty.marko'));
var output = template.renderSync();
expect(output).to.equal('Hello!');
});
it('should allow a template to be loaded from a compiled JS module', function(done) {
// Load the JS file to ensure the hello.marko.js file is created
marko.load(nodePath.join(__dirname, 'fixtures/api-tests/hello.marko'));

View File

@ -0,0 +1 @@
- Hello!