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,14 @@
{
"name": "blueimp-tmpl",
"homepage": "https://github.com/blueimp/JavaScript-Templates",
"version": "3.17.0",
"_release": "3.17.0",
"_resolution": {
"type": "version",
"tag": "v3.17.0",
"commit": "2a2b01890b42158d404e86ac2ec133d6cc500557"
},
"_source": "https://github.com/blueimp/JavaScript-Templates.git",
"_target": ">=2.5.4",
"_originalSource": "blueimp-tmpl"
}

View File

@@ -0,0 +1 @@
github: [blueimp]

View File

@@ -0,0 +1,25 @@
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm test
env:
CI: true

1
web/assets/blueimp-tmpl/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -0,0 +1,20 @@
MIT License
Copyright © 2011 Sebastian Tschan, https://blueimp.net
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,436 @@
# JavaScript Templates
## Contents
- [Demo](https://blueimp.github.io/JavaScript-Templates/)
- [Description](#description)
- [Usage](#usage)
- [Client-side](#client-side)
- [Server-side](#server-side)
- [Requirements](#requirements)
- [API](#api)
- [tmpl() function](#tmpl-function)
- [Templates cache](#templates-cache)
- [Output encoding](#output-encoding)
- [Local helper variables](#local-helper-variables)
- [Template function argument](#template-function-argument)
- [Template parsing](#template-parsing)
- [Templates syntax](#templates-syntax)
- [Interpolation](#interpolation)
- [Evaluation](#evaluation)
- [Compiled templates](#compiled-templates)
- [Tests](#tests)
- [License](#license)
## Description
1KB lightweight, fast & powerful JavaScript templating engine with zero
dependencies.
Compatible with server-side environments like [Node.js](https://nodejs.org/),
module loaders like [RequireJS](https://requirejs.org/) or
[webpack](https://webpack.js.org/) and all web browsers.
## Usage
### Client-side
Install the **blueimp-tmpl** package with [NPM](https://www.npmjs.org/):
```sh
npm install blueimp-tmpl
```
Include the (minified) JavaScript Templates script in your HTML markup:
```html
<script src="js/tmpl.min.js"></script>
```
Add a script section with type **"text/x-tmpl"**, a unique **id** property and
your template definition as content:
```html
<script type="text/x-tmpl" id="tmpl-demo">
<h3>{%=o.title%}</h3>
<p>Released under the
<a href="{%=o.license.url%}">{%=o.license.name%}</a>.</p>
<h4>Features</h4>
<ul>
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% } %}
</ul>
</script>
```
**"o"** (the lowercase letter) is a reference to the data parameter of the
template function (see the API section on how to modify this identifier).
In your application code, create a JavaScript object to use as data for the
template:
```js
var data = {
title: 'JavaScript Templates',
license: {
name: 'MIT license',
url: 'https://opensource.org/licenses/MIT'
},
features: ['lightweight & fast', 'powerful', 'zero dependencies']
}
```
In a real application, this data could be the result of retrieving a
[JSON](https://json.org/) resource.
Render the result by calling the **tmpl()** method with the id of the template
and the data object as arguments:
```js
document.getElementById('result').innerHTML = tmpl('tmpl-demo', data)
```
### Server-side
The following is an example how to use the JavaScript Templates engine on the
server-side with [Node.js](https://nodejs.org/).
Install the **blueimp-tmpl** package with [NPM](https://www.npmjs.org/):
```sh
npm install blueimp-tmpl
```
Add a file **template.html** with the following content:
```html
<!DOCTYPE HTML>
<title>{%=o.title%}</title>
<h3><a href="{%=o.url%}">{%=o.title%}</a></h3>
<h4>Features</h4>
<ul>
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% } %}
</ul>
```
Add a file **server.js** with the following content:
```js
require('http')
.createServer(function (req, res) {
var fs = require('fs'),
// The tmpl module exports the tmpl() function:
tmpl = require('./tmpl'),
// Use the following version if you installed the package with npm:
// tmpl = require("blueimp-tmpl"),
// Sample data:
data = {
title: 'JavaScript Templates',
url: 'https://github.com/blueimp/JavaScript-Templates',
features: ['lightweight & fast', 'powerful', 'zero dependencies']
}
// Override the template loading method:
tmpl.load = function (id) {
var filename = id + '.html'
console.log('Loading ' + filename)
return fs.readFileSync(filename, 'utf8')
}
res.writeHead(200, { 'Content-Type': 'text/x-tmpl' })
// Render the content:
res.end(tmpl('template', data))
})
.listen(8080, 'localhost')
console.log('Server running at http://localhost:8080/')
```
Run the application with the following command:
```sh
node server.js
```
## Requirements
The JavaScript Templates script has zero dependencies.
## API
### tmpl() function
The **tmpl()** function is added to the global **window** object and can be
called as global function:
```js
var result = tmpl('tmpl-demo', data)
```
The **tmpl()** function can be called with the id of a template, or with a
template string:
```js
var result = tmpl('<h3>{%=o.title%}</h3>', data)
```
If called without second argument, **tmpl()** returns a reusable template
function:
```js
var func = tmpl('<h3>{%=o.title%}</h3>')
document.getElementById('result').innerHTML = func(data)
```
### Templates cache
Templates loaded by id are cached in the map **tmpl.cache**:
```js
var func = tmpl('tmpl-demo'), // Loads and parses the template
cached = typeof tmpl.cache['tmpl-demo'] === 'function', // true
result = tmpl('tmpl-demo', data) // Uses cached template function
tmpl.cache['tmpl-demo'] = null
result = tmpl('tmpl-demo', data) // Loads and parses the template again
```
### Output encoding
The method **tmpl.encode** is used to escape HTML special characters in the
template output:
```js
var output = tmpl.encode('<>&"\'\x00') // Renders "&lt;&gt;&amp;&quot;&#39;"
```
**tmpl.encode** makes use of the regular expression **tmpl.encReg** and the
encoding map **tmpl.encMap** to match and replace special characters, which can
be modified to change the behavior of the output encoding.
Strings matched by the regular expression, but not found in the encoding map are
removed from the output. This allows for example to automatically trim input
values (removing whitespace from the start and end of the string):
```js
tmpl.encReg = /(^\s+)|(\s+$)|[<>&"'\x00]/g
var output = tmpl.encode(' Banana! ') // Renders "Banana" (without whitespace)
```
### Local helper variables
The local variables available inside the templates are the following:
- **o**: The data object given as parameter to the template function (see the
next section on how to modify the parameter name).
- **tmpl**: A reference to the **tmpl** function object.
- **\_s**: The string for the rendered result content.
- **\_e**: A reference to the **tmpl.encode** method.
- **print**: Helper function to add content to the rendered result string.
- **include**: Helper function to include the return value of a different
template in the result.
To introduce additional local helper variables, the string **tmpl.helper** can
be extended. The following adds a convenience function for _console.log_ and a
streaming function, that streams the template rendering result back to the
callback argument (note the comma at the beginning of each variable
declaration):
```js
tmpl.helper +=
',log=function(){console.log.apply(console, arguments)}' +
",st='',stream=function(cb){var l=st.length;st=_s;cb( _s.slice(l));}"
```
Those new helper functions could be used to stream the template contents to the
console output:
```html
<script type="text/x-tmpl" id="tmpl-demo">
<h3>{%=o.title%}</h3>
{% stream(log); %}
<p>Released under the
<a href="{%=o.license.url%}">{%=o.license.name%}</a>.</p>
{% stream(log); %}
<h4>Features</h4>
<ul>
{% stream(log); %}
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% stream(log); %}
{% } %}
</ul>
{% stream(log); %}
</script>
```
### Template function argument
The generated template functions accept one argument, which is the data object
given to the **tmpl(id, data)** function. This argument is available inside the
template definitions as parameter **o** (the lowercase letter).
The argument name can be modified by overriding **tmpl.arg**:
```js
tmpl.arg = 'p'
// Renders "<h3>JavaScript Templates</h3>":
var result = tmpl('<h3>{%=p.title%}</h3>', { title: 'JavaScript Templates' })
```
### Template parsing
The template contents are matched and replaced using the regular expression
**tmpl.regexp** and the replacement function **tmpl.func**. The replacement
function operates based on the
[parenthesized submatch strings](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter).
To use different tags for the template syntax, override **tmpl.regexp** with a
modified regular expression, by exchanging all occurrences of "{%" and "%}",
e.g. with "[%" and "%]":
```js
tmpl.regexp = /([\s'\\])(?!(?:[^[]|\[(?!%))*%\])|(?:\[%(=|#)([\s\S]+?)%\])|(\[%)|(%\])/g
```
By default, the plugin preserves whitespace (newlines, carriage returns, tabs
and spaces). To strip unnecessary whitespace, you can override the **tmpl.func**
function, e.g. with the following code:
```js
var originalFunc = tmpl.func
tmpl.func = function (s, p1, p2, p3, p4, p5, offset, str) {
if (p1 && /\s/.test(p1)) {
if (
!offset ||
/\s/.test(str.charAt(offset - 1)) ||
/^\s+$/g.test(str.slice(offset))
) {
return ''
}
return ' '
}
return originalFunc.apply(tmpl, arguments)
}
```
## Templates syntax
### Interpolation
Print variable with HTML special characters escaped:
```html
<h3>{%=o.title%}</h3>
```
Print variable without escaping:
```html
<h3>{%#o.user_id%}</h3>
```
Print output of function calls:
```html
<a href="{%=encodeURI(o.url)%}">Website</a>
```
Use dot notation to print nested properties:
```html
<strong>{%=o.author.name%}</strong>
```
### Evaluation
Use **print(str)** to add escaped content to the output:
```html
<span>Year: {% var d=new Date(); print(d.getFullYear()); %}</span>
```
Use **print(str, true)** to add unescaped content to the output:
```html
<span>{% print("Fast &amp; powerful", true); %}</span>
```
Use **include(str, obj)** to include content from a different template:
```html
<div>
{% include('tmpl-link', {name: "Website", url: "https://example.org"}); %}
</div>
```
**If else condition**:
```html
{% if (o.author.url) { %}
<a href="{%=encodeURI(o.author.url)%}">{%=o.author.name%}</a>
{% } else { %}
<em>No author url.</em>
{% } %}
```
**For loop**:
```html
<ul>
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% } %}
</ul>
```
## Compiled templates
The JavaScript Templates project comes with a compilation script, that allows
you to compile your templates into JavaScript code and combine them with a
minimal Templates runtime into one combined JavaScript file.
The compilation script is built for [Node.js](https://nodejs.org/).
To use it, first install the JavaScript Templates project via
[NPM](https://www.npmjs.org/):
```sh
npm install blueimp-tmpl
```
This will put the executable **tmpl.js** into the folder **node_modules/.bin**.
It will also make it available on your PATH if you install the package globally
(by adding the **-g** flag to the install command).
The **tmpl.js** executable accepts the paths to one or multiple template files
as command line arguments and prints the generated JavaScript code to the
console output. The following command line shows you how to store the generated
code in a new JavaScript file that can be included in your project:
```sh
tmpl.js index.html > tmpl.js
```
The files given as command line arguments to **tmpl.js** can either be pure
template files or HTML documents with embedded template script sections. For the
pure template files, the file names (without extension) serve as template ids.
The generated file can be included in your project as a replacement for the
original **tmpl.js** runtime. It provides you with the same API and provides a
**tmpl(id, data)** function that accepts the id of one of your templates as
first and a data object as optional second parameter.
## Tests
The JavaScript Templates project comes with
[Unit Tests](https://en.wikipedia.org/wiki/Unit_testing).
There are two different ways to run the tests:
- Open test/index.html in your browser or
- run `npm test` in the Terminal in the root path of the repository package.
The first one tests the browser integration, the second one the
[Node.js](https://nodejs.org/) integration.
## License
The JavaScript Templates script is released under the
[MIT license](https://opensource.org/licenses/MIT).

View File

@@ -0,0 +1,136 @@
/*
* JavaScript Templates Demo CSS
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
body {
max-width: 990px;
margin: 0 auto;
padding: 1em;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue',
Arial, sans-serif;
-webkit-text-size-adjust: 100%;
line-height: 1.4;
background: #212121;
color: #dedede;
}
a {
color: #61afef;
text-decoration: none;
}
a:visited {
color: #56b6c2;
}
a:hover {
color: #98c379;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 1.5em;
margin-bottom: 0.5em;
}
h1 {
margin-top: 0.5em;
}
label {
display: inline-block;
margin-bottom: 0.25em;
}
button,
select,
input,
textarea,
div.result {
-webkit-appearance: none;
box-sizing: border-box;
margin: 0;
padding: 0.5em 0.75em;
font-family: inherit;
font-size: 100%;
line-height: 1.4;
background: #414141;
color: #dedede;
border: 1px solid #363636;
border-radius: 5px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.07);
}
input,
textarea,
div.result {
width: 100%;
box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.07);
}
textarea {
display: block;
overflow: auto;
}
button {
background: #3c76a7;
background: linear-gradient(180deg, #3c76a7, #225c8d);
border-color: #225c8d;
color: #fff;
}
button[type='submit'] {
background: #6fa349;
background: linear-gradient(180deg, #6fa349, #568a30);
border-color: #568a30;
}
button[type='reset'] {
background: #d79435;
background: linear-gradient(180deg, #d79435, #be7b1c);
border-color: #be7b1c;
}
button:active {
box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5);
}
pre,
textarea.code {
font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
}
@media (prefers-color-scheme: light) {
body {
background: #ececec;
color: #212121;
}
a {
color: #225c8d;
}
a:visited {
color: #378f9a;
}
a:hover {
color: #6fa349;
}
input,
textarea,
div.result {
background: #fff;
border-color: #d1d1d1;
color: #212121;
}
}
@media (min-width: 540px) {
#navigation {
list-style: none;
padding: 0;
}
#navigation li {
display: inline-block;
}
#navigation li:not(:first-child)::before {
content: ' | ';
}
}

View File

@@ -0,0 +1,107 @@
<!DOCTYPE html>
<!--
/*
* JavaScript Templates Demo
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
-->
<html lang="en">
<head>
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<![endif]-->
<meta charset="utf-8" />
<title>JavaScript Templates Demo</title>
<meta
name="description"
content="1KB lightweight, fast &amp; 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."
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/demo.css" />
</head>
<body>
<h1>JavaScript Templates Demo</h1>
<p>
<strong>1KB</strong> lightweight, fast &amp; powerful
<a href="https://developer.mozilla.org/en/JavaScript/">JavaScript</a>
templating engine with zero dependencies.<br />
Compatible with server-side environments like
<a href="https://nodejs.org/">Node.js</a>, module loaders like
<a href="https://requirejs.org/">RequireJS</a> or
<a href="https://webpack.js.org/">webpack</a> and all web browsers.
</p>
<ul id="navigation">
<li>
<a href="https://github.com/blueimp/JavaScript-Templates/releases"
>Download</a
>
</li>
<li>
<a href="https://github.com/blueimp/JavaScript-Templates"
>Source Code</a
>
</li>
<li>
<a
href="https://github.com/blueimp/JavaScript-Templates/blob/master/README.md"
>Documentation</a
>
</li>
<li><a href="test/">Test</a></li>
<li><a href="https://blueimp.net">&copy; Sebastian Tschan</a></li>
</ul>
<form>
<p>
<label for="template">Template</label>
<textarea rows="12" id="template" class="code"></textarea>
</p>
<p>
<label for="data">Data (JSON)</label>
<textarea rows="14" id="data" class="code"></textarea>
</p>
<p>
<button type="submit" id="render">Render</button>
<button type="reset" id="reset">Reset</button>
</p>
<h2>Result</h2>
<div id="result" class="result"></div>
</form>
<script type="text/x-tmpl" id="tmpl-demo">
<h3>{%=o.title%}</h3>
<p>Released under the
<a href="{%=o.license.url%}">{%=o.license.name%}</a>.</p>
<h4>Features</h4>
<ul>
{% for (var i=0; i<o.features.length; i++) { %}
<li>{%=o.features[i]%}</li>
{% } %}
</ul>
</script>
<script type="text/x-tmpl" id="tmpl-data">
{
"title": "JavaScript Templates",
"license": {
"name": "MIT license",
"url": "https://opensource.org/licenses/MIT"
},
"features": [
"lightweight & fast",
"powerful",
"zero dependencies"
]
}
</script>
<script type="text/x-tmpl" id="tmpl-error">
<h5>{%=o.title%}</h5>
<pre>{%=o.error.toString()%}</pre>
</script>
<script src="js/tmpl.js"></script>
<script src="js/demo/demo.js"></script>
</body>
</html>

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"}

2061
web/assets/blueimp-tmpl/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,71 @@
{
"name": "blueimp-tmpl",
"version": "3.17.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": {
"chai": "4",
"eslint": "7",
"eslint-config-blueimp": "2",
"eslint-config-prettier": "6",
"eslint-plugin-jsdoc": "25",
"eslint-plugin-prettier": "3",
"mocha": "7",
"prettier": "2",
"uglify-js": "3"
},
"eslintConfig": {
"extends": [
"blueimp",
"plugin:jsdoc/recommended",
"plugin:prettier/recommended"
],
"env": {
"browser": true,
"node": true
}
},
"eslintIgnore": [
"js/*.min.js",
"test/vendor"
],
"prettier": {
"arrowParens": "avoid",
"proseWrap": "always",
"semi": false,
"singleQuote": true,
"trailingComma": "none"
},
"scripts": {
"lint": "eslint .",
"unit": "mocha",
"test": "npm run lint && npm run unit",
"build": "cd js && uglifyjs tmpl.js -c -m -o tmpl.min.js --source-map url=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"
},
"files": [
"js/*.js",
"js/*.js.map"
],
"main": "js/tmpl.js"
}