summaryrefslogtreecommitdiff
path: root/htdocs/js/luigi-template-0.4.1.min.js
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2017-11-07 20:44:10 -0500
committerPaul Duncan <pabs@pablotron.org>2017-11-07 20:44:10 -0500
commit074c8ca2a16bc4849e8ecea5a123d4d9a2995898 (patch)
treeae2597166fb9da56ff34bf8abafc59548bc0cad5 /htdocs/js/luigi-template-0.4.1.min.js
downloadmathy-074c8ca2a16bc4849e8ecea5a123d4d9a2995898.tar.bz2
mathy-074c8ca2a16bc4849e8ecea5a123d4d9a2995898.zip
initial commit
Diffstat (limited to 'htdocs/js/luigi-template-0.4.1.min.js')
-rw-r--r--htdocs/js/luigi-template-0.4.1.min.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/htdocs/js/luigi-template-0.4.1.min.js b/htdocs/js/luigi-template-0.4.1.min.js
new file mode 100644
index 0000000..2dad2ee
--- /dev/null
+++ b/htdocs/js/luigi-template-0.4.1.min.js
@@ -0,0 +1,20 @@
+
+LuigiTemplate=(function(){"use strict";var VERSION='0.4.1';var each=(function(){if(Array.prototype.forEach){return function(a,fn){a.forEach(fn);};}else{return function(a,fn){var i,l;for(i=0,l=a.length;i<l;i++)
+fn(a[i],i,a);};}})();var map=(function(){if(Array.prototype.map){return function(a,fn){return a.map(fn);};}else{return function(a,fn){var r=new Array(a.length);each(a,function(v,i){r[i]=v;});return r;};}})();var reduce=(function(){if(Array.prototype.reduce){return function(a,fn,iv){return a.reduce(fn,iv);};}else{return function(a,fn,r){each(a,function(v,i){r=fn(r,v,i,a);});return r;};}})();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,'');};}})();function scan(s,re,fn){var m;if(!re.global)
+throw'non-global regex';while((m=re.exec(s))!==null)
+fn(m);}
+var FILTERS={uc:function(v){return(v||'').toUpperCase();},lc:function(v){return(v||'').toLowerCase();},s:function(v){return(v==1)?'':'s';},length:function(v){return(v||'').length;},trim:function(v){return trim(v);},h:(function(){var LUT={'"':'&quot;',"'":'&apos;','>':'&gt;','<':'&lt;','&':'&amp;'};return function(v){if(v===undefined||v===null)
+return'';return v.toString().replace(/(['"<>&])/g,function(s){return LUT[s];});};})()};var RES={actions:/%\{\s*([^\s\|\}]+)\s*((\s*\|(\s*[^\s\|\}]+)+)*)\s*\}|([^%]+|%)/g,filter:/(\S+)((\s*\S+)*)\s*/,delim_filters:/\s*\|\s*/,delim_args:/\s+/};function parse_template(s){var r=[];scan(s,RES.actions,function(m){if(m[1]){r.push({type:'action',key:m[1],filters:parse_filters(m[2])});}else{r.push({type:'text',text:m[5]});}});return r;}
+function parse_filters(filters){var r=[];each(filters.split(RES.delim_filters),function(f){f=trim(f);if(!f)
+return;var m=f.match(RES.filter);if(!m)
+throw new Error('invalid filter: '+f);var as=trim(m[2]);r.push({name:m[1],args:as.length?as.split(RES.delim_args):[]});});return r;}
+function init(s,filters){this.s=s;this.filters=filters||FILTERS;this.actions=parse_template(s);};function run(o){var i,l,f,fs,me=this;return map(this.actions,function(row){if(row.type=='text'){return row.text;}else if(row.type=='action'){if(!row.key in o)
+throw new Error('missing key: '+row.key)
+return reduce(row.filters,function(r,f){return me.filters[f.name](r,f.args,o,me);},o[row.key]);}else{throw new Error('BUG: invalid type: '+row.type);}}).join('');}
+function get_inline_template(key){var e=document.getElementById(key);if(!e)
+throw new Error('unknown inline template key: '+key);return e.innerText||'';}
+var T=init;T.prototype.run=run;T.Cache=function(templates,try_dom){this.templates=templates;this.try_dom=!!try_dom;this.cache={};};T.Cache.prototype.run=function(key,args){if(!(key in this.cache)){var s=null;if(key in this.templates){s=this.templates[key].join('');}else if(this.try_dom){s=get_inline_template(key);}else{throw new Error('unknown key: '+key);}
+this.cache[key]=new T(s);}
+return this.cache[key].run(args);};T.DOMCache=function(){this.cache={};};T.DOMCache.prototype.run=function(key,args){if(!(key in this.cache))
+this.cache[key]=new T(get_inline_template(key));return this.cache[key].run(args);};T.dom=new T.DOMCache();T.FILTERS=FILTERS;T.VERSION=VERSION;T.run=function(s,o,f){return new T(s,f).run(o);}
+return T;}()); \ No newline at end of file