Add sourceURL template option. [closes #90]

Former-commit-id: 5db79c6b08aa7c8b2925db70d86dde75298da4c4
This commit is contained in:
John-David Dalton
2012-10-11 22:13:42 -07:00
parent b751fd738d
commit 4cd4d8f31a

View File

@@ -3693,9 +3693,9 @@
* @example
*
* // using a compiled template
* var compiled = _.template('hello: <%= name %>');
* var compiled = _.template('hello <%= name %>');
* compiled({ 'name': 'moe' });
* // => 'hello: moe'
* // => 'hello moe'
*
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
* _.template(list, { 'people': ['moe', 'larry', 'curly'] });
@@ -3706,26 +3706,31 @@
* // => '<b>&lt;script></b>'
*
* // using the internal `print` function in "evaluate" delimiters
* _.template('<% print("Hello " + epithet); %>.', { 'epithet': 'stooge' });
* // => 'Hello stooge.'
* _.template('<% print("hello " + epithet); %>!', { 'epithet': 'stooge' });
* // => 'hello stooge!'
*
* // using custom template delimiter settings
* _.templateSettings = {
* 'interpolate': /\{\{([\s\S]+?)\}\}/g
* };
*
* _.template('Hello {{ name }}!', { 'name': 'Mustache' });
* // => 'Hello Mustache!'
* _.template('hello {{ name }}!', { 'name': 'mustache' });
* // => 'hello mustache!'
*
* // using the `variable` option to ensure a with-statement isn't used in the compiled template
* var compiled = _.template('hello: <%= data.name %>', null, { 'variable': 'data' });
* var compiled = _.template('hello <%= data.name %>!', null, { 'variable': 'data' });
* compiled.source;
* // => function(data) {
* var __t, __p = '', __e = _.escape;
* __p += 'hello: ' + ((__t = ( data.name )) == null ? '' : __t);
* __p += 'hello ' + ((__t = ( data.name )) == null ? '' : __t) + '!';
* return __p;
* }
*
* // using the `sourceURL` option to specify a custom sourceURL for the template
* var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
* compiled(data);
* // => find the source of "greeting.jst" under the sources tab or resources panel of the web inspector
*
* // using the `source` property to inline compiled templates for meaningful
* // line numbers in error messages and a stack trace
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\
@@ -3810,7 +3815,7 @@
// use a sourceURL for easier debugging
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
var sourceURL = useSourceURL
? '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']'
? '\n//@ sourceURL=' + (options.sourceURL || '/lodash/template/source[' + (templateCounter++) + ']')
: '';
try {