Commit 176115d2 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1779037: upgrade javascript-templates library to v3.11.0"

parents 1b6da243 133a0f14
......@@ -2,10 +2,10 @@ Javascript Templates
====================
Website: https://github.com/blueimp/JavaScript-Templates
Version: 2.4.1
Version: 3.11.0
Javascript Templates is a lightweight, fast & powerful JavaScript templating engine with zero
dependencies.
Changes:
* none
\ No newline at end of file
* none
#!/usr/bin/env node
/*
* JavaScript Templates Compiler 2.4.0
* JavaScript Templates Compiler
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* https://opensource.org/licenses/MIT
*/
/*jslint nomen: true, stupid: true */
/*global require, __dirname, process, console */
(function () {
"use strict";
var tmpl = require("./tmpl.js").tmpl,
fs = require("fs"),
path = require("path"),
uglifyJS = require("uglify-js"),
// Retrieve the content of the minimal runtime:
runtime = fs.readFileSync(__dirname + "/runtime.js", "utf8"),
// A regular expression to parse templates from script tags in a HTML page:
regexp = /<script( id="([\w\-]+)")? type="text\/x-tmpl"( id="([\w\-]+)")?>([\s\S]+?)<\/script>/gi,
// A regular expression to match the helper function names:
helperRegexp = new RegExp(
tmpl.helper.match(/\w+(?=\s*=\s*function\s*\()/g).join("\\s*\\(|") + "\\s*\\("
),
// A list to store the function bodies:
list = [],
code;
// Extend the Templating engine with a print method for the generated functions:
tmpl.print = function (str) {
// Only add helper functions if they are used inside of the template:
var helper = helperRegexp.test(str) ? tmpl.helper : "",
body = str.replace(tmpl.regexp, tmpl.func);
if (helper || (/_e\s*\(/.test(body))) {
helper = "_e=tmpl.encode" + helper + ",";
}
return "function(" + tmpl.arg + ",tmpl){" +
("var " + helper + "_s='" + body + "';return _s;")
.split("_s+='';").join("") + "}";
};
// Loop through the command line arguments:
process.argv.forEach(function (file, index) {
var listLength = list.length,
stats,
content,
result,
id;
// Skipt the first two arguments, which are "node" and the script:
if (index > 1) {
stats = fs.statSync(file);
if (!stats.isFile()) {
console.error(file + ' is not a file.');
return;
}
content = fs.readFileSync(file, "utf8");
while (true) {
// Find templates in script tags:
result = regexp.exec(content);
if (!result) {
break;
}
id = result[2] || result[4];
list.push("'" + id + "':" + tmpl.print(result[5]));
}
if (listLength === list.length) {
// No template script tags found, use the complete content:
id = path.basename(file, path.extname(file));
list.push("'" + id + "':" + tmpl.print(content));
}
;(function () {
'use strict'
var path = require('path')
var tmpl = require(path.join(__dirname, 'tmpl.js'))
var fs = require('fs')
// Retrieve the content of the minimal runtime:
var runtime = fs.readFileSync(path.join(__dirname, 'runtime.js'), 'utf8')
// A regular expression to parse templates from script tags in a HTML page:
var regexp = /<script( id="([\w-]+)")? type="text\/x-tmpl"( id="([\w-]+)")?>([\s\S]+?)<\/script>/gi
// A regular expression to match the helper function names:
var helperRegexp = new RegExp(
tmpl.helper.match(/\w+(?=\s*=\s*function\s*\()/g).join('\\s*\\(|') +
'\\s*\\('
)
// A list to store the function bodies:
var list = []
var code
// Extend the Templating engine with a print method for the generated functions:
tmpl.print = function (str) {
// Only add helper functions if they are used inside of the template:
var helper = helperRegexp.test(str) ? tmpl.helper : ''
var body = str.replace(tmpl.regexp, tmpl.func)
if (helper || /_e\s*\(/.test(body)) {
helper = '_e=tmpl.encode' + helper + ','
}
return (
'function(' +
tmpl.arg +
',tmpl){' +
('var ' + helper + "_s='" + body + "';return _s;")
.split("_s+='';")
.join('') +
'}'
)
}
// Loop through the command line arguments:
process.argv.forEach(function (file, index) {
var listLength = list.length
var stats
var content
var result
var id
// Skip the first two arguments, which are "node" and the script:
if (index > 1) {
stats = fs.statSync(file)
if (!stats.isFile()) {
console.error(file + ' is not a file.')
return
}
content = fs.readFileSync(file, 'utf8')
while (true) {
// Find templates in script tags:
result = regexp.exec(content)
if (!result) {
break
}
});
if (!list.length) {
console.error('Missing input file.');
return;
id = result[2] || result[4]
list.push("'" + id + "':" + tmpl.print(result[5]))
}
if (listLength === list.length) {
// No template script tags found, use the complete content:
id = path.basename(file, path.extname(file))
list.push("'" + id + "':" + tmpl.print(content))
}
}
// Combine the generated functions as cache of the minimal runtime:
code = runtime.replace("{}", "{" + list.join(",") + "}");
// Generate the minified code and print it to the console output:
console.log(uglifyJS.minify(code, {fromString: true}).code);
}());
})
if (!list.length) {
console.error('Missing input file.')
return
}
// Combine the generated functions as cache of the minimal runtime:
code = runtime.replace('{}', '{' + list.join(',') + '}')
// Print the resulting code to the console output:
console.log(code)
})()
/*
* JavaScript Templates Runtime 2.4.1
* JavaScript Templates Runtime
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* https://opensource.org/licenses/MIT
*/
/*jslint sloppy: true */
/*global define */
/* global define */
(function ($) {
var tmpl = function (id, data) {
var f = tmpl.cache[id];
return data ? f(data, tmpl) : function (data) {
return f(data, tmpl);
};
};
tmpl.cache = {};
tmpl.encReg = /[<>&"'\x00]/g;
tmpl.encMap = {
"<" : "&lt;",
">" : "&gt;",
"&" : "&amp;",
"\"" : "&quot;",
"'" : "&#39;"
};
tmpl.encode = function (s) {
/*jshint eqnull:true */
return (s == null ? "" : "" + s).replace(
tmpl.encReg,
function (c) {
return tmpl.encMap[c] || "";
}
);
};
if (typeof define === "function" && define.amd) {
define(function () {
return tmpl;
});
} else {
$.tmpl = tmpl;
}
}(this));
;(function ($) {
'use strict'
var tmpl = function (id, data) {
var f = tmpl.cache[id]
return data
? f(data, tmpl)
: function (data) {
return f(data, tmpl)
}
}
tmpl.cache = {}
tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
tmpl.encMap = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;',
"'": '&#39;'
}
tmpl.encode = function (s) {
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
return tmpl.encMap[c] || ''
})
}
if (typeof define === 'function' && define.amd) {
define(function () {
return tmpl
})
} else if (typeof module === 'object' && module.exports) {
module.exports = tmpl
} else {
$.tmpl = tmpl
}
})(this)
/*
* JavaScript Templates 2.4.1
* JavaScript Templates
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* https://opensource.org/licenses/MIT
*
* Inspired by John Resig's JavaScript Micro-Templating:
* http://ejohn.org/blog/javascript-micro-templating/
*/
/*jslint evil: true, regexp: true, unparam: true */
/*global document, define */
/* global define */
(function ($) {
"use strict";
var tmpl = function (str, data) {
var f = !/[^\w\-\.:]/.test(str) ? tmpl.cache[str] = tmpl.cache[str] ||
tmpl(tmpl.load(str)) :
new Function(
tmpl.arg + ',tmpl',
"var _e=tmpl.encode" + tmpl.helper + ",_s='" +
str.replace(tmpl.regexp, tmpl.func) +
"';return _s;"
);
return data ? f(data, tmpl) : function (data) {
return f(data, tmpl);
};
};
tmpl.cache = {};
tmpl.load = function (id) {
return document.getElementById(id).innerHTML;
};
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g;
tmpl.func = function (s, p1, p2, p3, p4, p5) {
if (p1) { // whitespace, quote and backspace in HTML context
return {
"\n": "\\n",
"\r": "\\r",
"\t": "\\t",
" " : " "
}[p1] || "\\" + p1;
}
if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
if (p2 === "=") {
return "'+_e(" + p3 + ")+'";
}
return "'+(" + p3 + "==null?'':" + p3 + ")+'";
}
if (p4) { // evaluation start tag: {%
return "';";
}
if (p5) { // evaluation end tag: %}
return "_s+='";
}
};
tmpl.encReg = /[<>&"'\x00]/g;
tmpl.encMap = {
"<" : "&lt;",
">" : "&gt;",
"&" : "&amp;",
"\"" : "&quot;",
"'" : "&#39;"
};
tmpl.encode = function (s) {
/*jshint eqnull:true */
return (s == null ? "" : "" + s).replace(
tmpl.encReg,
function (c) {
return tmpl.encMap[c] || "";
}
);
};
tmpl.arg = "o";
tmpl.helper = ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
",include=function(s,d){_s+=tmpl(s,d);}";
if (typeof define === "function" && define.amd) {
define(function () {
return tmpl;
});
} else {
$.tmpl = tmpl;
;(function ($) {
'use strict'
var tmpl = function (str, data) {
var f = !/[^\w\-.:]/.test(str)
? (tmpl.cache[str] = tmpl.cache[str] || tmpl(tmpl.load(str)))
: new Function( // eslint-disable-line no-new-func
tmpl.arg + ',tmpl',
'var _e=tmpl.encode' +
tmpl.helper +
",_s='" +
str.replace(tmpl.regexp, tmpl.func) +
"';return _s;"
)
return data
? f(data, tmpl)
: function (data) {
return f(data, tmpl)
}
}
tmpl.cache = {}
tmpl.load = function (id) {
return document.getElementById(id).innerHTML
}
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g
tmpl.func = function (s, p1, p2, p3, p4, p5) {
if (p1) {
// whitespace, quote and backspace in HTML context
return (
{
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
' ': ' '
}[p1] || '\\' + p1
)
}
}(this));
if (p2) {
// interpolation: {%=prop%}, or unescaped: {%#prop%}
if (p2 === '=') {
return "'+_e(" + p3 + ")+'"
}
return "'+(" + p3 + "==null?'':" + p3 + ")+'"
}
if (p4) {
// evaluation start tag: {%
return "';"
}
if (p5) {
// evaluation end tag: %}
return "_s+='"
}
}
tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
tmpl.encMap = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;',
"'": '&#39;'
}
tmpl.encode = function (s) {
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
return tmpl.encMap[c] || ''
})
}
tmpl.arg = 'o'
tmpl.helper =
",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
',include=function(s,d){_s+=tmpl(s,d);}'
if (typeof define === 'function' && define.amd) {
define(function () {
return tmpl
})
} else if (typeof module === 'object' && module.exports) {
module.exports = tmpl
} else {
$.tmpl = tmpl
}
})(this)
!function(a){"use strict";var b=function(a,c){var d=/[^\w\-\.:]/.test(a)?new Function(b.arg+",tmpl","var _e=tmpl.encode"+b.helper+",_s='"+a.replace(b.regexp,b.func)+"';return _s;"):b.cache[a]=b.cache[a]||b(b.load(a));return c?d(c,b):function(a){return d(a,b)}};b.cache={},b.load=function(a){return document.getElementById(a).innerHTML},b.regexp=/([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,b.func=function(a,b,c,d,e,f){return b?{"\n":"\\n","\r":"\\r"," ":"\\t"," ":" "}[b]||"\\"+b:c?"="===c?"'+_e("+d+")+'":"'+("+d+"==null?'':"+d+")+'":e?"';":f?"_s+='":void 0},b.encReg=/[<>&"'\x00]/g,b.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},b.encode=function(a){return(null==a?"":""+a).replace(b.encReg,function(a){return b.encMap[a]||""})},b.arg="o",b.helper=",print=function(s,e){_s+=e?(s==null?'':s):_e(s);},include=function(s,d){_s+=tmpl(s,d);}","function"==typeof define&&define.amd?define(function(){return b}):a.tmpl=b}(this);
\ No newline at end of file
!function(e){"use strict";var n=function(e,t){var r=/[^\w\-.:]/.test(e)?new Function(n.arg+",tmpl","var _e=tmpl.encode"+n.helper+",_s='"+e.replace(n.regexp,n.func)+"';return _s;"):n.cache[e]=n.cache[e]||n(n.load(e));return t?r(t,n):function(e){return r(e,n)}};n.cache={},n.load=function(e){return document.getElementById(e).innerHTML},n.regexp=/([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,n.func=function(e,n,t,r,c,u){return n?{"\n":"\\n","\r":"\\r","\t":"\\t"," ":" "}[n]||"\\"+n:t?"="===t?"'+_e("+r+")+'":"'+("+r+"==null?'':"+r+")+'":c?"';":u?"_s+='":void 0},n.encReg=/[<>&"'\x00]/g,n.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},n.encode=function(e){return(null==e?"":""+e).replace(n.encReg,function(e){return n.encMap[e]||""})},n.arg="o",n.helper=",print=function(s,e){_s+=e?(s==null?'':s):_e(s);},include=function(s,d){_s+=tmpl(s,d);}","function"==typeof define&&define.amd?define(function(){return n}):"object"==typeof module&&module.exports?module.exports=n:e.tmpl=n}(this);
//# sourceMappingURL=tmpl.min.js.map
\ No newline at end of file
{"version":3,"sources":["tmpl.js"],"names":["$","tmpl","str","data","f","test","Function","arg","helper","replace","regexp","func","cache","load","id","document","getElementById","innerHTML","s","p1","p2","p3","p4","p5","\n","\r","\t"," ","encReg","encMap","<",">","&","\"","'","encode","c","define","amd","module","exports","this"],"mappings":"CAgBC,SAAWA,GACV,aACA,IAAIC,EAAO,SAAUC,EAAKC,GACxB,IAAIC,EAAK,YAAYC,KAAKH,GAEtB,IAAII,SACJL,EAAKM,IAAM,QACX,qBACIN,EAAKO,OACL,QACAN,EAAIO,QAAQR,EAAKS,OAAQT,EAAKU,MAC9B,gBAPHV,EAAKW,MAAMV,GAAOD,EAAKW,MAAMV,IAAQD,EAAKA,EAAKY,KAAKX,IASzD,OAAOC,EACHC,EAAED,EAAMF,GACR,SAAUE,GACV,OAAOC,EAAED,EAAMF,KAGrBA,EAAKW,SACLX,EAAKY,KAAO,SAAUC,GACpB,OAAOC,SAASC,eAAeF,GAAIG,WAErChB,EAAKS,OAAS,2EACdT,EAAKU,KAAO,SAAUO,EAAGC,EAAIC,EAAIC,EAAIC,EAAIC,GACvC,OAAIJ,GAIEK,KAAM,MACNC,KAAM,MACNC,KAAM,MACNC,IAAK,KACLR,IAAO,KAAOA,EAGhBC,EAES,MAAPA,EACK,QAAUC,EAAK,MAEjB,MAAQA,EAAK,aAAeA,EAAK,MAEtCC,EAEK,KAELC,EAEK,aAFT,GAKFtB,EAAK2B,OAAS,eACd3B,EAAK4B,QACHC,IAAK,OACLC,IAAK,OACLC,IAAK,QACLC,IAAK,SACLC,IAAK,SAEPjC,EAAKkC,OAAS,SAAUjB,GACtB,OAAa,MAALA,EAAY,GAAK,GAAKA,GAAGT,QAAQR,EAAK2B,OAAQ,SAAUQ,GAC9D,OAAOnC,EAAK4B,OAAOO,IAAM,MAG7BnC,EAAKM,IAAM,IACXN,EAAKO,OACH,0FAEoB,mBAAX6B,QAAyBA,OAAOC,IACzCD,OAAO,WACL,OAAOpC,IAEkB,iBAAXsC,QAAuBA,OAAOC,QAC9CD,OAAOC,QAAUvC,EAEjBD,EAAEC,KAAOA,EA5EZ,CA8EEwC"}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment