Actualización

This commit is contained in:
Xes
2025-04-10 11:37:29 +02:00
parent 4bfeadb360
commit 8969cc929d
39112 changed files with 975884 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
#!/usr/bin/env node
/*
* JavaScript Templates Compiler
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* eslint-disable strict */
/* eslint-disable no-console */
;(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')
// eslint-disable-next-line no-constant-condition
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))
}
}
})
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)
})()

View File

@@ -0,0 +1,93 @@
/*
* JavaScript Templates Demo
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* global tmpl */
/* eslint-disable strict */
;(function () {
'use strict'
var templateInput = document.getElementById('template')
var dataInput = document.getElementById('data')
var resultNode = document.getElementById('result')
var templateDemoNode = document.getElementById('tmpl-demo')
var templateDataNode = document.getElementById('tmpl-data')
/**
* Renders error messages
*
* @param {string} title Error title
* @param {Error} error Error object
*/
function renderError(title, error) {
resultNode.innerHTML = tmpl('tmpl-error', { title: title, error: error })
}
/**
* Renders the templating result
*
* @param {event} event Click event
*/
function render(event) {
event.preventDefault()
var data
try {
data = JSON.parse(dataInput.value)
} catch (e) {
renderError('JSON parsing failed', e)
return
}
try {
resultNode.innerHTML = tmpl(templateInput.value, data)
} catch (e) {
renderError('Template rendering failed', e)
}
}
/**
* Removes all child elements from a Node
*
* @param {HTMLElement} node HTML element node
*/
function empty(node) {
while (node.lastChild) {
node.removeChild(node.lastChild)
}
}
/**
* Initialization function
*
* @param {event} [event] Initialixation event
*/
function init(event) {
if (event) {
event.preventDefault()
}
templateInput.value = templateDemoNode.innerHTML.replace(
// Replace unnecessary whitespace:
/^\n|\s+$| {6}/g,
''
)
dataInput.value = JSON.stringify(
JSON.parse(templateDataNode.innerHTML),
null,
2
)
empty(resultNode)
}
document.getElementById('render').addEventListener('click', render)
document.getElementById('reset').addEventListener('click', init)
init()
})()

View File

@@ -0,0 +1,50 @@
/*
* JavaScript Templates Runtime
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* global define */
/* eslint-disable strict */
;(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) {
// eslint-disable-next-line eqeqeq
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)

View File

@@ -0,0 +1,98 @@
/*
* JavaScript Templates
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*
* Inspired by John Resig's JavaScript Micro-Templating:
* http://ejohn.org/blog/javascript-micro-templating/
*/
/* global define */
/* eslint-disable strict */
;(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
)
}
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) {
// eslint-disable-next-line eqeqeq
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)

View File

@@ -0,0 +1,2 @@
!function(e){"use strict";var r=function(e,n){var t=/[^\w\-.:]/.test(e)?new Function(r.arg+",tmpl","var _e=tmpl.encode"+r.helper+",_s='"+e.replace(r.regexp,r.func)+"';return _s;"):r.cache[e]=r.cache[e]||r(r.load(e));return n?t(n,r):function(e){return t(e,r)}};r.cache={},r.load=function(e){return document.getElementById(e).innerHTML},r.regexp=/([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,r.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},r.encReg=/[<>&"'\x00]/g,r.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},r.encode=function(e){return(null==e?"":""+e).replace(r.encReg,function(e){return r.encMap[e]||""})},r.arg="o",r.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 r}):"object"==typeof module&&module.exports?module.exports=r:e.tmpl=r}(this);
//# sourceMappingURL=tmpl.min.js.map

View File

@@ -0,0 +1 @@
{"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":"CAkBC,SAAWA,gBAEV,IAAIC,EAAO,SAAUC,EAAKC,GACxB,IAAIC,EAAK,YAAYC,KAAKH,GAEtB,IAAII,SACFL,EAAKM,IAAM,QACX,qBACEN,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,GACR,OAAOC,EAAED,EAAMF,KAGvBA,EAAKW,MAAQ,GACbX,EAAKY,KAAO,SAAUC,GACpB,OAAOC,SAASC,eAAeF,GAAIG,WAErChB,EAAKS,OAAS,2EACdT,EAAKU,KAAO,SAAUO,EAAGC,EAAIC,EAAIC,EAAIC,EAAIC,GACvC,OAAIJ,EAGA,CACEK,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,OAAS,CACZC,IAAK,OACLC,IAAK,OACLC,IAAK,QACLC,IAAK,SACLC,IAAK,SAEPjC,EAAKkC,OAAS,SAAUjB,GAEtB,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,EA7EZ,CA+EEwC"}