From fd0050d21c132f1c6cc2673ce1cc964d448b70c3 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 9 Sep 2018 03:51:12 -0400 Subject: js: add FILTERS.u, fix error conditions and messages --- js/luigi-template.js | 17 ++++++++++++++--- 1 file 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 -- cgit v1.2.3