documentcloud/underscore — pull request #488 by satchmorun (2012-02-23 18:06:02+00:00)
Title: Rework _.template with ideas from doT

1. The `print` function is no longer declared as a function.
It's just a regex inside evaluated blocks of a template.

2. The `with` statement has been removed. Inside a template,
the data object can be referenced with `o`:

```javascript
var hello = _.template('Hello <%= o.name %>!');
hello({name: 'Ponce de Leon'}) //=> 'Hello Ponce de Leon!'
```

3. Now uses string concatenation instead of Array.join.

As a result, it's now much faster. The hello template from the
example above now benches at ~20,000,000 ops/sec on my machine,
where the current _.template got ~600,000.

It's not quite as fast as doT (which gets about 30,000,000) on
the same template, but that seems to be mostly due to the
overhead of wrapping the template function. In any case, this
version should still be a lot faster than most anything other
than doT.

NOTE: I've modified all the template tests so that they pass,
and added one for the `print` function.