Fix template regressions. [Closes #44]

Former-commit-id: 15e98d86c290fea74780822b49b5d71e54064e01
This commit is contained in:
John-David Dalton
2012-07-11 22:46:16 -04:00
parent 971a26c123
commit 0dc88bb412
2 changed files with 60 additions and 67 deletions

View File

@@ -771,9 +771,32 @@
var compiled = _.template(key),
data = { 'a': 1, 'b': 2 };
equal(compiled(data), value);
equal(compiled(data), value, key);
});
});
test('should allow referencing variables declared in "evaluate" delimiters from other delimiters', function() {
var compiled = _.template('<% var b = a; %><%= b.value %>'),
data = { 'a': { 'value': 1 } };
equal(compiled(data), '1');
});
test('should work when passing `options.variable`', function() {
var compiled = _.template(
'<% _.forEach( data.a, function( value ) { %>' +
'<%= value.valueOf() %>' +
'<% }) %>', null, { 'variable': 'data' }
);
var data = { 'a': [1, 2, 3] };
try {
equal(compiled(data), '123');
} catch(e) {
ok(false);
}
});
}());
/*--------------------------------------------------------------------------*/