diff options
author | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:17:01 -0500 |
---|---|---|
committer | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:17:01 -0500 |
commit | 0b64486ad55e00fd8483778c08c7c07904d38d51 (patch) | |
tree | 38b5da202f0e4ac49c01c1351ece20c2e582c169 | |
parent | f86aa9c2582a3448c7f954ebd20b23cbe3a96995 (diff) | |
download | luigi-template-0b64486ad55e00fd8483778c08c7c07904d38d51.tar.bz2 luigi-template-0b64486ad55e00fd8483778c08c7c07904d38d51.zip |
add trim polyfill
-rw-r--r-- | luigi-template.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/luigi-template.js b/luigi-template.js index 09cbc39..721b9ac 100644 --- a/luigi-template.js +++ b/luigi-template.js @@ -128,6 +128,21 @@ LuigiTemplate = (function() { } })(); + // String.trim polyfill + var trim = (function() { + if (String.prototype.trim) { + return function(s) { + return s.trim(); + }; + } else { + var re = /^\s+|\s+$/g; + + return function(s) { + (s || '').replace(re, ''); + }; + } + })(); + // String.scan polyfill function scan(s, re, fn) { var m; @@ -158,7 +173,7 @@ LuigiTemplate = (function() { }, trim: function(v) { - return (v || '').replace(/^\s+|\s+$/g, ''); + return trim(v); }, h: (function() { @@ -188,8 +203,7 @@ LuigiTemplate = (function() { delim_args: /\s+/, run: /%\{\s*(\w+)((\s*\|\s*\w+\s*(\([\w\s,-]+\))?)*)\}/g, - old_filter: /(\w+)\s*(\(([\w\s,-]+)\))?/, - trim: /^\s+|\s+$/ + old_filter: /(\w+)\s*(\(([\w\s,-]+)\))?/ }; function parse_template(s) { @@ -218,7 +232,7 @@ LuigiTemplate = (function() { var r = []; each(filters.split(RES.delim_filters), function(f) { - f = f.trim(); + f = trim(f); if (!f) return; @@ -228,7 +242,7 @@ LuigiTemplate = (function() { r.push({ name: m[1], - args: FILTERS.trim(md[2] || '').split(RES.delim_args) + args: trim(md[2]).split(RES.delim_args) }); }); |