Add template and settings build options unit tests and tweak _.template docs.

Former-commit-id: c814799c82e5a1dde60e5eda4dda5cb192d437f9
This commit is contained in:
John-David Dalton
2012-09-30 01:03:43 -07:00
parent 463b5c6e49
commit de821e55ae
4 changed files with 100 additions and 50 deletions

View File

@@ -2527,7 +2527,7 @@ var compiled = _.template('hello: <%= name %>');
compiled({ 'name': 'moe' });
// => 'hello: moe'
var list = '<% _.forEach(people, function(name) { %> <li><%= name %></li> <% }); %>';
var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
_.template(list, { 'people': ['moe', 'larry', 'curly'] });
// => '<li>moe</li><li>larry</li><li>curly</li>'
@@ -2536,12 +2536,12 @@ _.template('<b><%- value %></b>', { 'value': '<script>' });
// => '<b>&lt;script></b>'
// using the internal `print` function in "evaluate" delimiters
_.template('<% print("Hello " + epithet); %>', { 'epithet': 'stooge' });
_.template('<% print("Hello " + epithet); %>.', { 'epithet': 'stooge' });
// => 'Hello stooge.'
// using custom template delimiter settings
_.templateSettings = {
'interpolate': /\{\{(.+?)\}\}/g
'interpolate': /\{\{([\s\S]+?)\}\}/g
};
_.template('Hello {{ name }}!', { 'name': 'Mustache' });