Add backload
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* Inspired by John Resig's JavaScript Micro-Templating:
|
||||
* http://ejohn.org/blog/javascript-micro-templating/
|
||||
*/
|
||||
|
||||
/*global document, define, module */
|
||||
|
||||
;(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
|
||||
tmpl.encMap = {
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'&': '&',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
}
|
||||
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))
|
||||
@@ -0,0 +1,2 @@
|
||||
!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"," ":" "}[n]||"\\"+n:t?"="===t?"'+_e("+r+")+'":"'+("+r+"==null?'':"+r+")+'":c?"';":u?"_s+='":void 0},n.encReg=/[<>&"'\x00]/g,n.encMap={"<":"<",">":">","&":"&",'"':""","'":"'"},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
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "blueimp-tmpl",
|
||||
"version": "3.4.0",
|
||||
"title": "JavaScript Templates",
|
||||
"description": "1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like Node.js, module loaders like RequireJS, Browserify or webpack and all web browsers.",
|
||||
"keywords": [
|
||||
"javascript",
|
||||
"templates",
|
||||
"templating"
|
||||
],
|
||||
"homepage": "https://github.com/blueimp/JavaScript-Templates",
|
||||
"author": {
|
||||
"name": "Sebastian Tschan",
|
||||
"url": "https://blueimp.net"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/blueimp/JavaScript-Templates.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"expect.js": "0.3.1",
|
||||
"mocha": "2.3.4",
|
||||
"standard": "6.0.7",
|
||||
"uglify-js": "2.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard js/*.js test/*.js && mocha",
|
||||
"build": "cd js && uglifyjs tmpl.js -c -m -o tmpl.min.js --source-map tmpl.min.js.map",
|
||||
"preversion": "npm test",
|
||||
"version": "npm run build && git add -A js",
|
||||
"postversion": "git push --tags origin master master:gh-pages && npm publish"
|
||||
},
|
||||
"bin": {
|
||||
"tmpl.js": "js/compile.js"
|
||||
},
|
||||
"main": "js/tmpl.js"
|
||||
}
|
||||
Reference in New Issue
Block a user