mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
better default multiline-aware templates
This commit is contained in:
@@ -30,5 +30,12 @@
|
|||||||
find the intersection of two thousand-element arrays in one second.
|
find the intersection of two thousand-element arrays in one second.
|
||||||
</h2>
|
</h2>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
<script type="text/html" id="template">
|
||||||
|
<%
|
||||||
|
if (data) { data += 12345; }; %>
|
||||||
|
<li><%= data %></li>
|
||||||
|
</script>a
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ $(document).ready(function() {
|
|||||||
var withNewlinesAndTabs = _.template('This\n\t\tis: <%= x %>.\n\tok.\nend.');
|
var withNewlinesAndTabs = _.template('This\n\t\tis: <%= x %>.\n\tok.\nend.');
|
||||||
equals(withNewlinesAndTabs({x: 'that'}), 'This\n\t\tis: that.\n\tok.\nend.');
|
equals(withNewlinesAndTabs({x: 'that'}), 'This\n\t\tis: that.\n\tok.\nend.');
|
||||||
|
|
||||||
|
var fromHTML = _.template($('#template').html());
|
||||||
|
equals(fromHTML({data : 12345}).replace(/\s/g, ''), '<li>24690</li>');
|
||||||
|
|
||||||
_.templateSettings = {
|
_.templateSettings = {
|
||||||
evaluate : /\{\{(.+?)\}\}/g,
|
evaluate : /\{\{(.+?)\}\}/g,
|
||||||
interpolate : /\{\{=(.+?)\}\}/g
|
interpolate : /\{\{=(.+?)\}\}/g
|
||||||
|
|||||||
@@ -623,8 +623,8 @@
|
|||||||
// By default, Underscore uses ERB-style template delimiters, change the
|
// By default, Underscore uses ERB-style template delimiters, change the
|
||||||
// following template settings to use alternative delimiters.
|
// following template settings to use alternative delimiters.
|
||||||
_.templateSettings = {
|
_.templateSettings = {
|
||||||
evaluate : /<%(.+?)%>/gm,
|
evaluate : /<%([\s\S]+?)%>/g,
|
||||||
interpolate : /<%=(.+?)%>/gm
|
interpolate : /<%=([\s\S]+?)%>/g
|
||||||
};
|
};
|
||||||
|
|
||||||
// JavaScript templating a-la ERB, pilfered from John Resig's
|
// JavaScript templating a-la ERB, pilfered from John Resig's
|
||||||
|
|||||||
Reference in New Issue
Block a user