handlebars-source 1.0.0.rc4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of handlebars-source might be problematic. Click here for more details.
- data/dist/handlebars.js +1122 -1441
- data/dist/handlebars.runtime.js +87 -191
- metadata +5 -5
data/dist/handlebars.runtime.js
CHANGED
@@ -1,66 +1,22 @@
|
|
1
|
-
/*
|
2
|
-
|
3
|
-
Copyright (C) 2011 by Yehuda Katz
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
22
|
-
|
23
|
-
*/
|
24
|
-
|
25
|
-
// lib/handlebars/browser-prefix.js
|
26
|
-
var Handlebars = {};
|
27
|
-
|
28
|
-
(function(Handlebars, undefined) {
|
29
|
-
;
|
30
1
|
// lib/handlebars/base.js
|
31
2
|
|
32
|
-
|
33
|
-
Handlebars
|
3
|
+
/*jshint eqnull:true*/
|
4
|
+
this.Handlebars = {};
|
34
5
|
|
35
|
-
Handlebars
|
36
|
-
|
37
|
-
|
38
|
-
3: '>= 1.0.0-rc.4'
|
39
|
-
};
|
6
|
+
(function(Handlebars) {
|
7
|
+
|
8
|
+
Handlebars.VERSION = "1.0.rc.1";
|
40
9
|
|
41
10
|
Handlebars.helpers = {};
|
42
11
|
Handlebars.partials = {};
|
43
12
|
|
44
|
-
var toString = Object.prototype.toString,
|
45
|
-
functionType = '[object Function]',
|
46
|
-
objectType = '[object Object]';
|
47
|
-
|
48
13
|
Handlebars.registerHelper = function(name, fn, inverse) {
|
49
|
-
if
|
50
|
-
|
51
|
-
Handlebars.Utils.extend(this.helpers, name);
|
52
|
-
} else {
|
53
|
-
if (inverse) { fn.not = inverse; }
|
54
|
-
this.helpers[name] = fn;
|
55
|
-
}
|
14
|
+
if(inverse) { fn.not = inverse; }
|
15
|
+
this.helpers[name] = fn;
|
56
16
|
};
|
57
17
|
|
58
18
|
Handlebars.registerPartial = function(name, str) {
|
59
|
-
|
60
|
-
Handlebars.Utils.extend(this.partials, name);
|
61
|
-
} else {
|
62
|
-
this.partials[name] = str;
|
63
|
-
}
|
19
|
+
this.partials[name] = str;
|
64
20
|
};
|
65
21
|
|
66
22
|
Handlebars.registerHelper('helperMissing', function(arg) {
|
@@ -71,9 +27,13 @@ Handlebars.registerHelper('helperMissing', function(arg) {
|
|
71
27
|
}
|
72
28
|
});
|
73
29
|
|
30
|
+
var toString = Object.prototype.toString, functionType = "[object Function]";
|
31
|
+
|
74
32
|
Handlebars.registerHelper('blockHelperMissing', function(context, options) {
|
75
33
|
var inverse = options.inverse || function() {}, fn = options.fn;
|
76
34
|
|
35
|
+
|
36
|
+
var ret = "";
|
77
37
|
var type = toString.call(context);
|
78
38
|
|
79
39
|
if(type === functionType) { context = context.call(this); }
|
@@ -102,53 +62,22 @@ Handlebars.createFrame = Object.create || function(object) {
|
|
102
62
|
return obj;
|
103
63
|
};
|
104
64
|
|
105
|
-
Handlebars.logger = {
|
106
|
-
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
107
|
-
|
108
|
-
methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
|
109
|
-
|
110
|
-
// can be overridden in the host environment
|
111
|
-
log: function(level, obj) {
|
112
|
-
if (Handlebars.logger.level <= level) {
|
113
|
-
var method = Handlebars.logger.methodMap[level];
|
114
|
-
if (typeof console !== 'undefined' && console[method]) {
|
115
|
-
console[method].call(console, obj);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
};
|
120
|
-
|
121
|
-
Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
|
122
|
-
|
123
65
|
Handlebars.registerHelper('each', function(context, options) {
|
124
66
|
var fn = options.fn, inverse = options.inverse;
|
125
|
-
var
|
67
|
+
var ret = "", data;
|
126
68
|
|
127
69
|
if (options.data) {
|
128
70
|
data = Handlebars.createFrame(options.data);
|
129
71
|
}
|
130
72
|
|
131
|
-
if(context &&
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
ret = ret + fn(context[i], { data: data });
|
136
|
-
}
|
137
|
-
} else {
|
138
|
-
for(var key in context) {
|
139
|
-
if(context.hasOwnProperty(key)) {
|
140
|
-
if(data) { data.key = key; }
|
141
|
-
ret = ret + fn(context[key], {data: data});
|
142
|
-
i++;
|
143
|
-
}
|
144
|
-
}
|
73
|
+
if(context && context.length > 0) {
|
74
|
+
for(var i=0, j=context.length; i<j; i++) {
|
75
|
+
if (data) { data.index = i; }
|
76
|
+
ret = ret + fn(context[i], { data: data });
|
145
77
|
}
|
146
|
-
}
|
147
|
-
|
148
|
-
if(i === 0){
|
78
|
+
} else {
|
149
79
|
ret = inverse(this);
|
150
80
|
}
|
151
|
-
|
152
81
|
return ret;
|
153
82
|
});
|
154
83
|
|
@@ -164,29 +93,32 @@ Handlebars.registerHelper('if', function(context, options) {
|
|
164
93
|
});
|
165
94
|
|
166
95
|
Handlebars.registerHelper('unless', function(context, options) {
|
167
|
-
|
96
|
+
var fn = options.fn, inverse = options.inverse;
|
97
|
+
options.fn = inverse;
|
98
|
+
options.inverse = fn;
|
99
|
+
|
100
|
+
return Handlebars.helpers['if'].call(this, context, options);
|
168
101
|
});
|
169
102
|
|
170
103
|
Handlebars.registerHelper('with', function(context, options) {
|
171
|
-
|
104
|
+
return options.fn(context);
|
172
105
|
});
|
173
106
|
|
174
|
-
Handlebars.registerHelper('log', function(context
|
175
|
-
|
176
|
-
Handlebars.log(level, context);
|
107
|
+
Handlebars.registerHelper('log', function(context) {
|
108
|
+
Handlebars.log(context);
|
177
109
|
});
|
110
|
+
|
111
|
+
}(this.Handlebars));
|
178
112
|
;
|
179
113
|
// lib/handlebars/utils.js
|
180
|
-
|
181
|
-
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
182
|
-
|
183
114
|
Handlebars.Exception = function(message) {
|
184
115
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
185
116
|
|
186
|
-
|
187
|
-
|
188
|
-
this[errorProps[idx]] = tmp[errorProps[idx]];
|
117
|
+
for (var p in tmp) {
|
118
|
+
if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
|
189
119
|
}
|
120
|
+
|
121
|
+
this.message = tmp.message;
|
190
122
|
};
|
191
123
|
Handlebars.Exception.prototype = new Error();
|
192
124
|
|
@@ -198,61 +130,52 @@ Handlebars.SafeString.prototype.toString = function() {
|
|
198
130
|
return this.string.toString();
|
199
131
|
};
|
200
132
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
var
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
133
|
+
(function() {
|
134
|
+
var escape = {
|
135
|
+
"&": "&",
|
136
|
+
"<": "<",
|
137
|
+
">": ">",
|
138
|
+
'"': """,
|
139
|
+
"'": "'",
|
140
|
+
"`": "`"
|
141
|
+
};
|
142
|
+
|
143
|
+
var badChars = /[&<>"'`]/g;
|
144
|
+
var possible = /[&<>"'`]/;
|
145
|
+
|
146
|
+
var escapeChar = function(chr) {
|
147
|
+
return escape[chr] || "&";
|
148
|
+
};
|
149
|
+
|
150
|
+
Handlebars.Utils = {
|
151
|
+
escapeExpression: function(string) {
|
152
|
+
// don't escape SafeStrings, since they're already safe
|
153
|
+
if (string instanceof Handlebars.SafeString) {
|
154
|
+
return string.toString();
|
155
|
+
} else if (string == null || string === false) {
|
156
|
+
return "";
|
222
157
|
}
|
223
|
-
}
|
224
|
-
},
|
225
|
-
|
226
|
-
escapeExpression: function(string) {
|
227
|
-
// don't escape SafeStrings, since they're already safe
|
228
|
-
if (string instanceof Handlebars.SafeString) {
|
229
|
-
return string.toString();
|
230
|
-
} else if (string == null || string === false) {
|
231
|
-
return "";
|
232
|
-
}
|
233
|
-
|
234
|
-
// Force a string conversion as this will be done by the append regardless and
|
235
|
-
// the regex test will do this transparently behind the scenes, causing issues if
|
236
|
-
// an object's to string has escaped characters in it.
|
237
|
-
string = string.toString();
|
238
158
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
159
|
+
if(!possible.test(string)) { return string; }
|
160
|
+
return string.replace(badChars, escapeChar);
|
161
|
+
},
|
162
|
+
|
163
|
+
isEmpty: function(value) {
|
164
|
+
if (typeof value === "undefined") {
|
165
|
+
return true;
|
166
|
+
} else if (value === null) {
|
167
|
+
return true;
|
168
|
+
} else if (value === false) {
|
169
|
+
return true;
|
170
|
+
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
171
|
+
return true;
|
172
|
+
} else {
|
173
|
+
return false;
|
174
|
+
}
|
250
175
|
}
|
251
|
-
}
|
252
|
-
}
|
253
|
-
;
|
176
|
+
};
|
177
|
+
})();;
|
254
178
|
// lib/handlebars/runtime.js
|
255
|
-
|
256
179
|
Handlebars.VM = {
|
257
180
|
template: function(templateSpec) {
|
258
181
|
// Just add water
|
@@ -263,63 +186,39 @@ Handlebars.VM = {
|
|
263
186
|
program: function(i, fn, data) {
|
264
187
|
var programWrapper = this.programs[i];
|
265
188
|
if(data) {
|
266
|
-
|
267
|
-
} else if
|
268
|
-
programWrapper
|
189
|
+
return Handlebars.VM.program(fn, data);
|
190
|
+
} else if(programWrapper) {
|
191
|
+
return programWrapper;
|
192
|
+
} else {
|
193
|
+
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
194
|
+
return programWrapper;
|
269
195
|
}
|
270
|
-
return programWrapper;
|
271
196
|
},
|
272
197
|
programWithDepth: Handlebars.VM.programWithDepth,
|
273
|
-
noop: Handlebars.VM.noop
|
274
|
-
compilerInfo: null
|
198
|
+
noop: Handlebars.VM.noop
|
275
199
|
};
|
276
200
|
|
277
201
|
return function(context, options) {
|
278
202
|
options = options || {};
|
279
|
-
|
280
|
-
|
281
|
-
var compilerInfo = container.compilerInfo || [],
|
282
|
-
compilerRevision = compilerInfo[0] || 1,
|
283
|
-
currentRevision = Handlebars.COMPILER_REVISION;
|
284
|
-
|
285
|
-
if (compilerRevision !== currentRevision) {
|
286
|
-
if (compilerRevision < currentRevision) {
|
287
|
-
var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
|
288
|
-
compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
|
289
|
-
throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
|
290
|
-
"Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
|
291
|
-
} else {
|
292
|
-
// Use the embedded version info since the runtime doesn't know about this revision yet
|
293
|
-
throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
|
294
|
-
"Please update your runtime to a newer version ("+compilerInfo[1]+").";
|
295
|
-
}
|
296
|
-
}
|
297
|
-
|
298
|
-
return result;
|
203
|
+
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
299
204
|
};
|
300
205
|
},
|
301
206
|
|
302
|
-
programWithDepth: function(
|
303
|
-
var args = Array.prototype.slice.call(arguments,
|
207
|
+
programWithDepth: function(fn, data, $depth) {
|
208
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
304
209
|
|
305
|
-
|
210
|
+
return function(context, options) {
|
306
211
|
options = options || {};
|
307
212
|
|
308
213
|
return fn.apply(this, [context, options.data || data].concat(args));
|
309
214
|
};
|
310
|
-
program.program = i;
|
311
|
-
program.depth = args.length;
|
312
|
-
return program;
|
313
215
|
},
|
314
|
-
program: function(
|
315
|
-
|
216
|
+
program: function(fn, data) {
|
217
|
+
return function(context, options) {
|
316
218
|
options = options || {};
|
317
219
|
|
318
220
|
return fn(context, options.data || data);
|
319
221
|
};
|
320
|
-
program.program = i;
|
321
|
-
program.depth = 0;
|
322
|
-
return program;
|
323
222
|
},
|
324
223
|
noop: function() { return ""; },
|
325
224
|
invokePartial: function(partial, name, context, helpers, partials, data) {
|
@@ -340,6 +239,3 @@ Handlebars.VM = {
|
|
340
239
|
|
341
240
|
Handlebars.template = Handlebars.VM.template;
|
342
241
|
;
|
343
|
-
// lib/handlebars/browser-suffix.js
|
344
|
-
})(Handlebars);
|
345
|
-
;
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebars-source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Yehuda Katz
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Handlebars.js source code wrapper for (pre)compilation gems.
|
15
15
|
email:
|
@@ -36,9 +36,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
38
38
|
requirements:
|
39
|
-
- - ! '
|
39
|
+
- - ! '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
44
|
rubygems_version: 1.8.24
|