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.
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Dotjs
3
- VERSION = "1.1.3"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -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
- var global = (function(){ return this || (0,eval)('this'); }());
5
+ (function() {
6
+ "use strict";
30
7
 
31
- if (typeof module !== 'undefined' && module.exports) {
32
- module.exports = doT;
33
- } else if (typeof define === 'function' && define.amd) {
34
- define(function(){return doT;});
35
- } else {
36
- global.doT = doT;
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
- function encodeHTMLSource() {
40
- var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': '&#34;', "'": '&#39;', "/": '&#47;' },
41
- matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g;
42
- return function(code) {
43
- return code ? code.toString().replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : code;
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
- var startend = {
49
- append: { start: "'+(", end: ")+'", startencode: "'+encodeHTML(" },
50
- split: { start: "';out+=(", end: ");out+='", startencode: "';out+=encodeHTML("}
51
- }, skip = /$^/;
37
+ function encodeHTMLSource() {
38
+ var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': '&#34;', "'": '&#39;', "/": '&#47;' },
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
- function resolveDefs(c, block, def) {
54
- return ((typeof block === 'string') ? new String(block) : new String(block.toString()))
55
- .replace(c.define || skip, function(m, code, assign, value) {
56
- if (code.indexOf('def.') === 0) {
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
- function unescape(code) {
73
- return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, ' ');
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
- doT.template = function(tmpl, c, def) {
77
- c = c || doT.templateSettings;
78
- var cse = c.append ? startend.append : startend.split, str, needhtmlencode, sid=0, indv;
83
+ function unescape(code) {
84
+ return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, ' ');
85
+ }
79
86
 
80
- if (c.use || c.define) {
81
- var olddef = global.def; global.def = def || {}; // workaround minifiers
82
- str = resolveDefs(c, tmpl, global.def);
83
- global.def = olddef;
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
- str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,' ')
87
- .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,''): str)
88
- .replace(/'|\\/g, '\\$&')
89
- .replace(c.interpolate || skip, function(m, code) {
90
- return cse.start + unescape(code) + cse.end;
91
- })
92
- .replace(c.encode || skip, function(m, code) {
93
- needhtmlencode = true;
94
- return cse.startencode + unescape(code) + cse.end;
95
- })
96
- .replace(c.conditional || skip, function(m, elsecase, code) {
97
- return elsecase ?
98
- (code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
99
- (code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
100
- })
101
- .replace(c.iterate || skip, function(m, iterate, vname, iname) {
102
- if (!iterate) return "';} } out+='";
103
- sid+=1; indv=iname || "i"+sid; iterate=unescape(iterate);
104
- return "';var arr"+sid+"="+iterate+";if(arr"+sid+"){var "+vname+","+indv+"=-1,l"+sid+"=arr"+sid+".length-1;while("+indv+"<l"+sid+"){"
105
- +vname+"=arr"+sid+"["+indv+"+=1];out+='";
106
- })
107
- .replace(c.evaluate || skip, function(m, code) {
108
- return "';" + unescape(code) + "out+='";
109
- })
110
- + "';return out;")
111
- .replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
112
- .replace(/(\s|;|}|^|{)out\+='';/g, '$1').replace(/\+''/g, '')
113
- .replace(/(\s|;|}|^|{)out\+=''\+/g,'$1out+=');
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
- if (needhtmlencode && c.selfcontained) {
116
- str = "var encodeHTML=(" + encodeHTMLSource.toString() + "());" + str;
117
- }
118
- try {
119
- return new Function(c.varname, str);
120
- } catch (e) {
121
- if (typeof console !== 'undefined') console.log("Could not create a template function: " + str);
122
- throw e;
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
- doT.compile = function(tmpl, def) {
127
- return doT.template(tmpl, null, def);
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: 1.1.3
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: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets