From 4cd4d8f31ab64345f1bdd16fd8156df307059f45 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 11 Oct 2012 22:13:42 -0700 Subject: [PATCH] Add `sourceURL` template option. [closes #90] Former-commit-id: 5db79c6b08aa7c8b2925db70d86dde75298da4c4 --- lodash.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lodash.js b/lodash.js index 411ce2c23..6408ae748 100644 --- a/lodash.js +++ b/lodash.js @@ -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) { %>
  • <%= name %>
  • <% }); %>'; * _.template(list, { 'people': ['moe', 'larry', 'curly'] }); @@ -3706,26 +3706,31 @@ * // => '<script>' * * // 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 {