aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-09 03:51:12 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-09 03:51:12 -0400
commitfd0050d21c132f1c6cc2673ce1cc964d448b70c3 (patch)
treefa4008c333b772a61f0ee410e5b8098f6adbe4f6
parent2cff700e3e59adc2bfcd4b2c536675dfdeb96312 (diff)
downloadluigi-template-fd0050d21c132f1c6cc2673ce1cc964d448b70c3.tar.bz2
luigi-template-fd0050d21c132f1c6cc2673ce1cc964d448b70c3.zip
js: add FILTERS.u, fix error conditions and messages
-rw-r--r--js/luigi-template.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/js/luigi-template.js b/js/luigi-template.js
index 91b9303..d48d668 100644
--- a/js/luigi-template.js
+++ b/js/luigi-template.js
@@ -173,6 +173,12 @@ LuigiTemplate = (function() {
};
})(),
+ u: function(s) {
+ return encodeURIComponent(s || '').replace('%20', '+').replace(/[!'()*]/g, function(c) {
+ return '%' + c.charCodeAt(0).toString(16);
+ });
+ },
+
json: function(v) {
return JSON.stringify(v);
},
@@ -247,10 +253,15 @@ LuigiTemplate = (function() {
if (row.type == 'text') {
return row.text;
} else if (row.type == 'action') {
- if (!row.key in o)
- throw new Error('missing key: ' + row.key)
+ if (!(row.key in o)) {
+ throw new Error('unknown key: ' + row.key);
+ }
return reduce(row.filters, function(r, f) {
+ if (!(f.name in me.filters)) {
+ throw new Error('unknown filter: ' + f.name);
+ }
+
return me.filters[f.name](r, f.args, o, me);
}, o[row.key]);
} else {
@@ -295,7 +306,7 @@ LuigiTemplate = (function() {
// get source from inline script tag
s = get_inline_template(key);
} else {
- throw new Error('unknown key: ' + key);
+ throw new Error('unknown template: ' + key);
}
// cache template