[Pkg-javascript-commits] [leaflet] 268/301: Revert "'#1968 compiled interpolation'"

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 4a0beebde38129e9ee3ee4cbe9a0f039dbce4070
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Wed Nov 20 15:42:06 2013 -0500

    Revert "'#1968 compiled interpolation'"
---
 spec/suites/core/UtilSpec.js | 37 ++-----------------------------------
 src/core/Util.js             | 23 +++++++++--------------
 2 files changed, 11 insertions(+), 49 deletions(-)

diff --git a/spec/suites/core/UtilSpec.js b/spec/suites/core/UtilSpec.js
index f4b0b53..3e7d3ec 100644
--- a/spec/suites/core/UtilSpec.js
+++ b/spec/suites/core/UtilSpec.js
@@ -188,48 +188,15 @@ describe('Util', function () {
 
 	describe('#template', function () {
 		it('evaluates templates with a given data object', function () {
-			var tpl = 'Hello {foo} and {baz }!';
+			var tpl = 'Hello {foo} and {bar}!';
 
 			var str = L.Util.template(tpl, {
 				foo: 'Vlad',
-				bar: 'Dave',
-				baz: function (o) {
-					return o.bar;
-				}
-			});
-
-			expect(str).to.eql('Hello Vlad and Dave!');
-		});
-
-		it('check the cache', function () {
-			var tpl = 'Hello {foo} and {baz }!';
-
-			var str = L.Util._templateCache[tpl]({
-				foo: 'ladies',
-				baz: function () {
-					return 'gentlemen';
-				}
-			});
-
-			expect(str).to.eql('Hello ladies and gentlemen!');
-		});
-
-		it('evaluates templates with a function', function () {
-			var tpl = L.Util.compileTemplate('Hello { foo } and { bar}!', {});
-
-			var str1 = tpl({
-				foo: 'Vlad',
 				bar: 'Dave'
 			});
-			var str2 = tpl({
-				foo: '{Calvin}',
-				bar: '{Simon}'
-			});
 
-			expect(str1).to.eql('Hello Vlad and Dave!');
-			expect(str2).to.eql('Hello {Calvin} and {Simon}!');
+			expect(str).to.eql('Hello Vlad and Dave!');
 		});
-
 		it('does not modify text without a token variable', function () {
 			expect(L.Util.template('foo', {})).to.eql('foo');
 		});
diff --git a/src/core/Util.js b/src/core/Util.js
index 5e67b17..b903098 100644
--- a/src/core/Util.js
+++ b/src/core/Util.js
@@ -104,21 +104,16 @@ L.Util = {
 		}
 		return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
 	},
-
-	compileTemplate: function (str, data) {
-		// based on https://gist.github.com/padolsey/6008842
-		str = str.replace(/"/g, '\\\"');
-		str = str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
-			return '" + o["' + key + '"]' + (typeof data[key] === 'function' ? '(o)' : '') + ' + "';
-		});
-		// jshint evil: true
-		return new Function('o', 'return "' + str + '";');
-	},
-
 	template: function (str, data) {
-		var cache = L.Util._templateCache = L.Util._templateCache || {};
-		cache[str] = cache[str] || L.Util.compileTemplate(str, data);
-		return cache[str](data);
+		return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
+			var value = data[key];
+			if (value === undefined) {
+				throw new Error('No value provided for variable ' + str);
+			} else if (typeof value === 'function') {
+				value = value(data);
+			}
+			return value;
+		});
 	},
 
 	isArray: Array.isArray || function (obj) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list