Skip to content

Commit f85bf03

Browse files
committed
Use blueimp+jsdoc+prettier config for eslint.
Move eslint configs to package.json. Use package.json files property instead of .npmignore.
1 parent 7037b86 commit f85bf03

File tree

11 files changed

+1974
-100
lines changed

11 files changed

+1974
-100
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
.DS_Store
21
node_modules

.npmignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

js/compile.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
* https://opensource.org/licenses/MIT
1111
*/
1212

13-
;(function () {
13+
/* eslint-disable strict */
14+
/* eslint-disable no-console */
15+
16+
;(function() {
1417
'use strict'
1518
var path = require('path')
1619
var tmpl = require(path.join(__dirname, 'tmpl.js'))
@@ -28,7 +31,7 @@
2831
var list = []
2932
var code
3033
// Extend the Templating engine with a print method for the generated functions:
31-
tmpl.print = function (str) {
34+
tmpl.print = function(str) {
3235
// Only add helper functions if they are used inside of the template:
3336
var helper = helperRegexp.test(str) ? tmpl.helper : ''
3437
var body = str.replace(tmpl.regexp, tmpl.func)
@@ -46,7 +49,7 @@
4649
)
4750
}
4851
// Loop through the command line arguments:
49-
process.argv.forEach(function (file, index) {
52+
process.argv.forEach(function(file, index) {
5053
var listLength = list.length
5154
var stats
5255
var content
@@ -60,6 +63,7 @@
6063
return
6164
}
6265
content = fs.readFileSync(file, 'utf8')
66+
// eslint-disable-next-line no-constant-condition
6367
while (true) {
6468
// Find templates in script tags:
6569
result = regexp.exec(content)

js/demo/demo.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
/* global tmpl */
1313

14-
;(function () {
14+
/* eslint-disable strict */
15+
16+
;(function() {
1517
'use strict'
1618

1719
var templateInput = document.getElementById('template')
@@ -20,14 +22,22 @@
2022
var templateDemoNode = document.getElementById('tmpl-demo')
2123
var templateDataNode = document.getElementById('tmpl-data')
2224

23-
function renderError (title, error) {
24-
resultNode.innerHTML = tmpl(
25-
'tmpl-error',
26-
{title: title, error: error}
27-
)
25+
/**
26+
* Renders error messages
27+
*
28+
* @param {string} title Error title
29+
* @param {Error} error Error object
30+
*/
31+
function renderError(title, error) {
32+
resultNode.innerHTML = tmpl('tmpl-error', { title: title, error: error })
2833
}
2934

30-
function render (event) {
35+
/**
36+
* Renders the templating result
37+
*
38+
* @param {event} event Click event
39+
*/
40+
function render(event) {
3141
event.preventDefault()
3242
var data
3343
try {
@@ -37,32 +47,43 @@
3747
return
3848
}
3949
try {
40-
resultNode.innerHTML = tmpl(
41-
templateInput.value,
42-
data
43-
)
50+
resultNode.innerHTML = tmpl(templateInput.value, data)
4451
} catch (e) {
4552
renderError('Template rendering failed', e)
4653
}
4754
}
4855

49-
function empty (node) {
56+
/**
57+
* Removes all child elements from a Node
58+
*
59+
* @param {HTMLElement} node HTML element node
60+
*/
61+
function empty(node) {
5062
while (node.lastChild) {
5163
node.removeChild(node.lastChild)
5264
}
5365
}
5466

55-
function init (event) {
67+
/**
68+
* Initialization function
69+
*
70+
* @param {event} [event] Initialixation event
71+
*/
72+
function init(event) {
5673
if (event) {
5774
event.preventDefault()
5875
}
59-
templateInput.value = templateDemoNode.innerHTML.trim()
60-
dataInput.value = templateDataNode.innerHTML.trim()
76+
templateInput.value = templateDemoNode.innerHTML
77+
dataInput.value = JSON.stringify(
78+
JSON.parse(templateDataNode.innerHTML),
79+
null,
80+
2
81+
)
6182
empty(resultNode)
6283
}
6384

6485
document.getElementById('render').addEventListener('click', render)
6586
document.getElementById('reset').addEventListener('click', init)
6687

6788
init()
68-
}())
89+
})()

js/runtime.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111

1212
/* global define */
1313

14-
;(function ($) {
14+
/* eslint-disable strict */
15+
16+
;(function($) {
1517
'use strict'
16-
var tmpl = function (id, data) {
18+
var tmpl = function(id, data) {
1719
var f = tmpl.cache[id]
1820
return data
1921
? f(data, tmpl)
20-
: function (data) {
21-
return f(data, tmpl)
22-
}
22+
: function(data) {
23+
return f(data, tmpl)
24+
}
2325
}
2426
tmpl.cache = {}
2527
tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
@@ -30,13 +32,14 @@
3032
'"': '&quot;',
3133
"'": '&#39;'
3234
}
33-
tmpl.encode = function (s) {
34-
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
35+
tmpl.encode = function(s) {
36+
// eslint-disable-next-line eqeqeq
37+
return (s == null ? '' : '' + s).replace(tmpl.encReg, function(c) {
3538
return tmpl.encMap[c] || ''
3639
})
3740
}
3841
if (typeof define === 'function' && define.amd) {
39-
define(function () {
42+
define(function() {
4043
return tmpl
4144
})
4245
} else if (typeof module === 'object' && module.exports) {

js/tmpl.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,33 @@
1414

1515
/* global define */
1616

17-
;(function ($) {
17+
/* eslint-disable strict */
18+
19+
;(function($) {
1820
'use strict'
19-
var tmpl = function (str, data) {
21+
var tmpl = function(str, data) {
2022
var f = !/[^\w\-.:]/.test(str)
2123
? (tmpl.cache[str] = tmpl.cache[str] || tmpl(tmpl.load(str)))
2224
: new Function( // eslint-disable-line no-new-func
23-
tmpl.arg + ',tmpl',
24-
'var _e=tmpl.encode' +
25+
tmpl.arg + ',tmpl',
26+
'var _e=tmpl.encode' +
2527
tmpl.helper +
2628
",_s='" +
2729
str.replace(tmpl.regexp, tmpl.func) +
2830
"';return _s;"
29-
)
31+
)
3032
return data
3133
? f(data, tmpl)
32-
: function (data) {
33-
return f(data, tmpl)
34-
}
34+
: function(data) {
35+
return f(data, tmpl)
36+
}
3537
}
3638
tmpl.cache = {}
37-
tmpl.load = function (id) {
39+
tmpl.load = function(id) {
3840
return document.getElementById(id).innerHTML
3941
}
4042
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g
41-
tmpl.func = function (s, p1, p2, p3, p4, p5) {
43+
tmpl.func = function(s, p1, p2, p3, p4, p5) {
4244
if (p1) {
4345
// whitespace, quote and backspace in HTML context
4446
return (
@@ -74,8 +76,9 @@
7476
'"': '&quot;',
7577
"'": '&#39;'
7678
}
77-
tmpl.encode = function (s) {
78-
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
79+
tmpl.encode = function(s) {
80+
// eslint-disable-next-line eqeqeq
81+
return (s == null ? '' : '' + s).replace(tmpl.encReg, function(c) {
7982
return tmpl.encMap[c] || ''
8083
})
8184
}
@@ -84,7 +87,7 @@
8487
",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
8588
',include=function(s,d){_s+=tmpl(s,d);}'
8689
if (typeof define === 'function' && define.amd) {
87-
define(function () {
90+
define(function() {
8891
return tmpl
8992
})
9093
} else if (typeof module === 'object' && module.exports) {

0 commit comments

Comments
 (0)