From 348147d8fbd53619ee4951df4bc0c3d5df6faea5 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 5 Oct 2010 17:10:44 -0400 Subject: [PATCH] better default multiline-aware templates --- test/test.html | 7 +++++++ test/utility.js | 3 +++ underscore.js | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/test.html b/test/test.html index c174ea0a6..1ac56f9be 100644 --- a/test/test.html +++ b/test/test.html @@ -30,5 +30,12 @@ find the intersection of two thousand-element arrays in one second.
+ + a + diff --git a/test/utility.js b/test/utility.js index 94f225a80..fdd9b5cec 100644 --- a/test/utility.js +++ b/test/utility.js @@ -87,6 +87,9 @@ $(document).ready(function() { var withNewlinesAndTabs = _.template('This\n\t\tis: <%= x %>.\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, ''), '
  • 24690
  • '); + _.templateSettings = { evaluate : /\{\{(.+?)\}\}/g, interpolate : /\{\{=(.+?)\}\}/g diff --git a/underscore.js b/underscore.js index 3c1d4d844..31b0b060e 100644 --- a/underscore.js +++ b/underscore.js @@ -623,8 +623,8 @@ // By default, Underscore uses ERB-style template delimiters, change the // following template settings to use alternative delimiters. _.templateSettings = { - evaluate : /<%(.+?)%>/gm, - interpolate : /<%=(.+?)%>/gm + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g }; // JavaScript templating a-la ERB, pilfered from John Resig's