sprockets-dotjs 1.1.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sprockets-dotjs/version.rb +1 -1
- data/lib/support/doT.js +121 -115
- metadata +2 -2
data/lib/support/doT.js
CHANGED
@@ -1,129 +1,135 @@
|
|
1
1
|
// doT.js
|
2
2
|
// 2011, Laura Doktorova, https://github.com/olado/doT
|
3
|
-
//
|
4
|
-
// doT.js is an open source component of http://bebedo.com
|
5
3
|
// Licensed under the MIT license.
|
6
|
-
//
|
7
|
-
(function() {
|
8
|
-
"use strict";
|
9
|
-
|
10
|
-
var doT = {
|
11
|
-
version: '0.2.0',
|
12
|
-
templateSettings: {
|
13
|
-
evaluate: /\{\{([\s\S]+?)\}\}/g,
|
14
|
-
interpolate: /\{\{=([\s\S]+?)\}\}/g,
|
15
|
-
encode: /\{\{!([\s\S]+?)\}\}/g,
|
16
|
-
use: /\{\{#([\s\S]+?)\}\}/g,
|
17
|
-
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
|
18
|
-
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
|
19
|
-
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
|
20
|
-
varname: 'it',
|
21
|
-
strip: true,
|
22
|
-
append: true,
|
23
|
-
selfcontained: false
|
24
|
-
},
|
25
|
-
template: undefined, //fn, compile template
|
26
|
-
compile: undefined //fn, for express
|
27
|
-
};
|
28
4
|
|
29
|
-
|
5
|
+
(function() {
|
6
|
+
"use strict";
|
30
7
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
8
|
+
var doT = {
|
9
|
+
version: '1.0.0',
|
10
|
+
templateSettings: {
|
11
|
+
evaluate: /\{\{([\s\S]+?\}?)\}\}/g,
|
12
|
+
interpolate: /\{\{=([\s\S]+?)\}\}/g,
|
13
|
+
encode: /\{\{!([\s\S]+?)\}\}/g,
|
14
|
+
use: /\{\{#([\s\S]+?)\}\}/g,
|
15
|
+
useParams: /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,
|
16
|
+
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
|
17
|
+
defineParams:/^\s*([\w$]+):([\s\S]+)/,
|
18
|
+
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
|
19
|
+
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
|
20
|
+
varname: 'it',
|
21
|
+
strip: true,
|
22
|
+
append: true,
|
23
|
+
selfcontained: false
|
24
|
+
},
|
25
|
+
template: undefined, //fn, compile template
|
26
|
+
compile: undefined //fn, for express
|
27
|
+
};
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
global.encodeHTML = encodeHTMLSource();
|
29
|
+
if (typeof module !== 'undefined' && module.exports) {
|
30
|
+
module.exports = doT;
|
31
|
+
} else if (typeof define === 'function' && define.amd) {
|
32
|
+
define(function(){return doT;});
|
33
|
+
} else {
|
34
|
+
(function(){ return this || (0,eval)('this'); }()).doT = doT;
|
35
|
+
}
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
function encodeHTMLSource() {
|
38
|
+
var encodeHTMLRules = { "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' },
|
39
|
+
matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g;
|
40
|
+
return function() {
|
41
|
+
return this ? this.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : this;
|
42
|
+
};
|
43
|
+
}
|
44
|
+
String.prototype.encodeHTML = encodeHTMLSource();
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
code = code.substring(4);
|
58
|
-
}
|
59
|
-
if (assign === ':') {
|
60
|
-
def[code]= value;
|
61
|
-
} else {
|
62
|
-
eval("def['"+code+"']=" + value);
|
63
|
-
}
|
64
|
-
return '';
|
65
|
-
})
|
66
|
-
.replace(c.use || skip, function(m, code) {
|
67
|
-
var v = eval(code);
|
68
|
-
return v ? resolveDefs(c, v, def) : v;
|
69
|
-
});
|
70
|
-
}
|
46
|
+
var startend = {
|
47
|
+
append: { start: "'+(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" },
|
48
|
+
split: { start: "';out+=(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"}
|
49
|
+
}, skip = /$^/;
|
71
50
|
|
72
|
-
|
73
|
-
|
74
|
-
|
51
|
+
function resolveDefs(c, block, def) {
|
52
|
+
return ((typeof block === 'string') ? block : block.toString())
|
53
|
+
.replace(c.define || skip, function(m, code, assign, value) {
|
54
|
+
if (code.indexOf('def.') === 0) {
|
55
|
+
code = code.substring(4);
|
56
|
+
}
|
57
|
+
if (!(code in def)) {
|
58
|
+
if (assign === ':') {
|
59
|
+
if (c.defineParams) value.replace(c.defineParams, function(m, param, v) {
|
60
|
+
def[code] = {arg: param, text: v};
|
61
|
+
});
|
62
|
+
if (!(code in def)) def[code]= value;
|
63
|
+
} else {
|
64
|
+
new Function("def", "def['"+code+"']=" + value)(def);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
return '';
|
68
|
+
})
|
69
|
+
.replace(c.use || skip, function(m, code) {
|
70
|
+
if (c.useParams) code = code.replace(c.useParams, function(m, s, d, param) {
|
71
|
+
if (def[d] && def[d].arg && param) {
|
72
|
+
var rw = (d+":"+param).replace(/'|\\/g, '_');
|
73
|
+
def.__exp = def.__exp || {};
|
74
|
+
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
75
|
+
return s + "def.__exp['"+rw+"']";
|
76
|
+
}
|
77
|
+
});
|
78
|
+
var v = new Function("def", "return " + code)(def);
|
79
|
+
return v ? resolveDefs(c, v, def) : v;
|
80
|
+
});
|
81
|
+
}
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
83
|
+
function unescape(code) {
|
84
|
+
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, ' ');
|
85
|
+
}
|
79
86
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
} else str = tmpl;
|
87
|
+
doT.template = function(tmpl, c, def) {
|
88
|
+
c = c || doT.templateSettings;
|
89
|
+
var cse = c.append ? startend.append : startend.split, needhtmlencode, sid = 0, indv,
|
90
|
+
str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl;
|
85
91
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
92
|
+
str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,' ')
|
93
|
+
.replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,''): str)
|
94
|
+
.replace(/'|\\/g, '\\$&')
|
95
|
+
.replace(c.interpolate || skip, function(m, code) {
|
96
|
+
return cse.start + unescape(code) + cse.end;
|
97
|
+
})
|
98
|
+
.replace(c.encode || skip, function(m, code) {
|
99
|
+
needhtmlencode = true;
|
100
|
+
return cse.start + unescape(code) + cse.endencode;
|
101
|
+
})
|
102
|
+
.replace(c.conditional || skip, function(m, elsecase, code) {
|
103
|
+
return elsecase ?
|
104
|
+
(code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
|
105
|
+
(code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
|
106
|
+
})
|
107
|
+
.replace(c.iterate || skip, function(m, iterate, vname, iname) {
|
108
|
+
if (!iterate) return "';} } out+='";
|
109
|
+
sid+=1; indv=iname || "i"+sid; iterate=unescape(iterate);
|
110
|
+
return "';var arr"+sid+"="+iterate+";if(arr"+sid+"){var "+vname+","+indv+"=-1,l"+sid+"=arr"+sid+".length-1;while("+indv+"<l"+sid+"){"
|
111
|
+
+vname+"=arr"+sid+"["+indv+"+=1];out+='";
|
112
|
+
})
|
113
|
+
.replace(c.evaluate || skip, function(m, code) {
|
114
|
+
return "';" + unescape(code) + "out+='";
|
115
|
+
})
|
116
|
+
+ "';return out;")
|
117
|
+
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
|
118
|
+
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '')
|
119
|
+
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');
|
114
120
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
if (needhtmlencode && c.selfcontained) {
|
122
|
+
str = "String.prototype.encodeHTML=(" + encodeHTMLSource.toString() + "());" + str;
|
123
|
+
}
|
124
|
+
try {
|
125
|
+
return new Function(c.varname, str);
|
126
|
+
} catch (e) {
|
127
|
+
if (typeof console !== 'undefined') console.log("Could not create a template function: " + str);
|
128
|
+
throw e;
|
129
|
+
}
|
130
|
+
};
|
125
131
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}());
|
132
|
+
doT.compile = function(tmpl, def) {
|
133
|
+
return doT.template(tmpl, null, def);
|
134
|
+
};
|
135
|
+
}());
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-dotjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|