vendor/optional/lodash-0.3.2.js
function template(text, data, options) {
    options || (options = {});

    var result,
        defaults = lodash.templateSettings,
        escapeDelimiter = options.escape,
        evaluateDelimiter = options.evaluate,
        interpolateDelimiter = options.interpolate,
        variable = options.variable;

    // use template defaults if no option is provided
    if (escapeDelimiter == null) {
      escapeDelimiter = defaults.escape;
    }
    if (evaluateDelimiter == null) {
      evaluateDelimiter = defaults.evaluate;
    }
    if (interpolateDelimiter == null) {
      interpolateDelimiter = defaults.interpolate;
    }

    // tokenize delimiters to avoid escaping them
    if (escapeDelimiter) {
      text = text.replace(escapeDelimiter, tokenizeEscape);
    }
    if (interpolateDelimiter) {
      text = text.replace(interpolateDelimiter, tokenizeInterpolate);
    }
    if (evaluateDelimiter) {
      text = text.replace(evaluateDelimiter, tokenizeEvaluate);
    }

    // escape characters that cannot be included in string literals and
    // detokenize delimiter code snippets
    text = "__p='" + text
      .replace(reUnescapedString, escapeStringChar)
      .replace(reToken, detokenize) + "';\n";

    // clear stored code snippets
    tokenized.length = 0;

    // if `options.variable` is not specified, add `data` to the top of the scope chain
    if (!variable) {
      variable = defaults.variable;
      text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n';
    }

    text = 'function(' + variable + ') {\n' +
      'var __p, __t, __j = Array.prototype.join;\n' +
      'function print() { __p += __j.call(arguments, \'\') }\n' +
      text +
      'return __p\n}';

    // add a sourceURL for easier debugging
    // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
    if (useSourceURL) {
      text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
    }

    result = Function('_', 'return ' + text)(lodash);

    if (data) {
      return result(data);
    }
    // provide the compiled function's source via its `toString()` method, in
    // supported environments, or the `source` property as a convenience for
    // build time precompilation
    result.source = text;
    return result;
  }
function template(text, data, options) {
    options || (options = {});

    var result,
        defaults = lodash.templateSettings,
        escapeDelimiter = options.escape,
        evaluateDelimiter = options.evaluate,
        interpolateDelimiter = options.interpolate,
        variable = options.variable;

    // use template defaults if no option is provided
    if (escapeDelimiter == null) {
      escapeDelimiter = defaults.escape;
    }
    if (evaluateDelimiter == null) {
      evaluateDelimiter = defaults.evaluate;
    }
    if (interpolateDelimiter == null) {
      interpolateDelimiter = defaults.interpolate;
    }

    // tokenize delimiters to avoid escaping them
    if (escapeDelimiter) {
      text = text.replace(escapeDelimiter, tokenizeEscape);
    }
    if (interpolateDelimiter) {
      text = text.replace(interpolateDelimiter, tokenizeInterpolate);
    }
    if (evaluateDelimiter) {
      text = text.replace(evaluateDelimiter, tokenizeEvaluate);
    }

    // escape characters that cannot be included in string literals and
    // detokenize delimiter code snippets
    text = "__p='" + text
      .replace(reUnescapedString, escapeStringChar)
      .replace(reToken, detokenize) + "';\n";

    // clear stored code snippets
    tokenized.length = 0;

    // if `options.variable` is not specified, add `data` to the top of the scope chain
    if (!variable) {
      variable = defaults.variable;
      text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n';
    }

    text = 'function(' + variable + ') {\n' +
      'var __p, __t, __j = Array.prototype.join;\n' +
      'function print() { __p += __j.call(arguments, \'\') }\n' +
      text +
      'return __p\n}';

    // add a sourceURL for easier debugging
    // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
    if (useSourceURL) {
      text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
    }

    result = Function('_', 'return ' + text)(lodash);

    if (data) {
      return result(data);
    }
    // provide the compiled function's source via its `toString()` method, in
    // supported environments, or the `source` property as a convenience for
    // build time precompilation
    result.source = text;
    return result;
  }
function template ( text , data , options ) { options || ( options = { } ) ; var result , defaults = lodash . templateSettings , escapeDelimiter = options . escape , evaluateDelimiter = options . evaluate , interpolateDelimiter = options . interpolate , variable = options . variable ; // use template defaults if no option is provided if ( escapeDelimiter == null ) { escapeDelimiter = defaults . escape ; } if ( evaluateDelimiter == null ) { evaluateDelimiter = defaults . evaluate ; } if ( interpolateDelimiter == null ) { interpolateDelimiter = defaults . interpolate ; } // tokenize delimiters to avoid escaping them if ( escapeDelimiter ) { text = text . replace ( escapeDelimiter , tokenizeEscape ) ; } if ( interpolateDelimiter ) { text = text . replace ( interpolateDelimiter , tokenizeInterpolate ) ; } if ( evaluateDelimiter ) { text = text . replace ( evaluateDelimiter , tokenizeEvaluate ) ; } // escape characters that cannot be included in string literals and // detokenize delimiter code snippets text = "__p='" + text . replace ( reUnescapedString , escapeStringChar ) . replace ( reToken , detokenize ) + "';\n" ; // clear stored code snippets tokenized . length = 0 ; // if `options.variable` is not specified, add `data` to the top of the scope chain if ( ! variable ) { variable = defaults . variable ; text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n' ; } text = 'function(' + variable + ') {\n' + 'var __p, __t, __j = Array.prototype.join;\n' + 'function print() { __p += __j.call(arguments, \'\') }\n' + text + 'return __p\n}' ; // add a sourceURL for easier debugging // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl if ( useSourceURL ) { text += '\n//@ sourceURL=/lodash/template/source[' + ( templateCounter ++ ) + ']' ; } result = Function ( '_' , 'return ' + text ) ( lodash ) ; if ( data ) { return result ( data ) ; } // provide the compiled function's source via its `toString()` method, in // supported environments, or the `source` property as a convenience for // build time precompilation result . source = text ; return result ; }
A micro-templating method, similar to John Resig's implementation.
Lo-Dash templating handles arbitrary delimiters, preserves whitespace, and
correctly escapes quotes within interpolated code.

@static
@memberOf _
@category Utilities
@param {String} text The template text.
@param {Obect} data The data object used to populate the text.
@param {Object} options The options object.
@returns {Function|String} Returns a compiled function when no `data` object
is given, else it returns the interpolated text.
@example

// using compiled template
var compiled = _.template('hello: <%= name %>');
compiled({ 'name': 'moe' });
// => 'hello: moe'

var list = '<% _.forEach(people, function(name) { %> <li><%= name %></li> <% }); %>';
_.template(list, { 'people': ['moe', 'curly', 'larry'] });
// => '<li>moe</li><li>curly</li><li>larry</li>'

var template = _.template('<b><%- value %></b>');
template({ 'value': '<script>' });
// => '<b>&lt;script></b>'

// using `print`
var compiled = _.template('<% print("Hello " + epithet); %>');
compiled({ 'epithet': 'stooge' });
// => 'Hello stooge.'

// using custom template settings
_.templateSettings = {
'interpolate': /\{\{(.+?)\}\}/g
};

var template = _.template('Hello {{ name }}!');
template({ 'name': 'Mustache' });
// => 'Hello Mustache!'

// using the `variable` option
_.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' });
// => 'no'

// using the `source` property
<script>
JST.project = <%= _.template(jstText).source %>;
</script>
A micro - templating method similar to John Resig s implementation . Lo - Dash templating handles arbitrary delimiters preserves whitespace and correctly escapes quotes within interpolated code .