mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Add "imports" option to _.templateSettings. [closes #148]
Former-commit-id: 16a019d27aea2e7a72665f62adf4c4c35e29b4bf
This commit is contained in:
24
test/test.js
24
test/test.js
@@ -1768,20 +1768,25 @@
|
||||
});
|
||||
|
||||
test('should tokenize delimiters', function() {
|
||||
var compiled = _.template('<span class="icon-<%= type %>2"></span>');
|
||||
equal(compiled({ 'type': 1 }), '<span class="icon-12"></span>');
|
||||
var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
|
||||
data = { 'type': 1 };
|
||||
|
||||
equal(compiled(data), '<span class="icon-12"></span>');
|
||||
});
|
||||
|
||||
test('should work with "interpolate" delimiters containing ternary operators', function() {
|
||||
var compiled = _.template('<%= value ? value : "b" %>');
|
||||
equal(compiled({ 'value': 'a' }), 'a');
|
||||
var compiled = _.template('<%= value ? value : "b" %>'),
|
||||
data = { 'value': 'a' };
|
||||
|
||||
equal(compiled(data), 'a');
|
||||
});
|
||||
|
||||
test('should parse delimiters with newlines', function() {
|
||||
var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
|
||||
compiled = _.template(expected, null, { 'evaluate': /<<(.+?)>>/g });
|
||||
compiled = _.template(expected, null, { 'evaluate': /<<(.+?)>>/g }),
|
||||
data = { 'value': true };
|
||||
|
||||
equal(compiled({ 'value': true }), expected);
|
||||
equal(compiled(data), expected);
|
||||
});
|
||||
|
||||
test('should parse ES6 template delimiters', function() {
|
||||
@@ -1789,6 +1794,13 @@
|
||||
equal(_.template('1${value}3', data), '123');
|
||||
equal(_.template('${"{" + value + "\\}"}', data), '{2}');
|
||||
});
|
||||
|
||||
test('supports the "imports" option', function() {
|
||||
var options = { 'imports': { 'a': 1 } },
|
||||
compiled = _.template('<%= a %>', null, options);
|
||||
|
||||
equal(compiled({}), '1');
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user