handlebars-source-machty 1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,316 @@
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
+ // lib/handlebars/base.js
31
+
32
+ Handlebars.VERSION = "1.0.0-rc.3";
33
+ Handlebars.COMPILER_REVISION = 2;
34
+
35
+ Handlebars.REVISION_CHANGES = {
36
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
+ 2: '>= 1.0.0-rc.3'
38
+ };
39
+
40
+ Handlebars.helpers = {};
41
+ Handlebars.partials = {};
42
+
43
+ Handlebars.registerHelper = function(name, fn, inverse) {
44
+ if(inverse) { fn.not = inverse; }
45
+ this.helpers[name] = fn;
46
+ };
47
+
48
+ Handlebars.registerPartial = function(name, str) {
49
+ this.partials[name] = str;
50
+ };
51
+
52
+ Handlebars.registerHelper('helperMissing', function(arg) {
53
+ if(arguments.length === 2) {
54
+ return undefined;
55
+ } else {
56
+ throw new Error("Could not find property '" + arg + "'");
57
+ }
58
+ });
59
+
60
+ var toString = Object.prototype.toString, functionType = "[object Function]";
61
+
62
+ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
63
+ var inverse = options.inverse || function() {}, fn = options.fn;
64
+
65
+ var type = toString.call(context);
66
+
67
+ if(type === functionType) { context = context.call(this); }
68
+
69
+ if(context === true) {
70
+ return fn(this);
71
+ } else if(context === false || context == null) {
72
+ return inverse(this);
73
+ } else if(type === "[object Array]") {
74
+ if(context.length > 0) {
75
+ return Handlebars.helpers.each(context, options);
76
+ } else {
77
+ return inverse(this);
78
+ }
79
+ } else {
80
+ return fn(context);
81
+ }
82
+ });
83
+
84
+ Handlebars.K = function() {};
85
+
86
+ Handlebars.createFrame = Object.create || function(object) {
87
+ Handlebars.K.prototype = object;
88
+ var obj = new Handlebars.K();
89
+ Handlebars.K.prototype = null;
90
+ return obj;
91
+ };
92
+
93
+ Handlebars.logger = {
94
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
95
+
96
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
97
+
98
+ // can be overridden in the host environment
99
+ log: function(level, obj) {
100
+ if (Handlebars.logger.level <= level) {
101
+ var method = Handlebars.logger.methodMap[level];
102
+ if (typeof console !== 'undefined' && console[method]) {
103
+ console[method].call(console, obj);
104
+ }
105
+ }
106
+ }
107
+ };
108
+
109
+ Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
110
+
111
+ Handlebars.registerHelper('each', function(context, options) {
112
+ var fn = options.fn, inverse = options.inverse;
113
+ var i = 0, ret = "", data;
114
+
115
+ if (options.data) {
116
+ data = Handlebars.createFrame(options.data);
117
+ }
118
+
119
+ if(context && typeof context === 'object') {
120
+ if(context instanceof Array){
121
+ for(var j = context.length; i<j; i++) {
122
+ if (data) { data.index = i; }
123
+ ret = ret + fn(context[i], { data: data });
124
+ }
125
+ } else {
126
+ for(var key in context) {
127
+ if(context.hasOwnProperty(key)) {
128
+ if(data) { data.key = key; }
129
+ ret = ret + fn(context[key], {data: data});
130
+ i++;
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ if(i === 0){
137
+ ret = inverse(this);
138
+ }
139
+
140
+ return ret;
141
+ });
142
+
143
+ Handlebars.registerHelper('if', function(context, options) {
144
+ var type = toString.call(context);
145
+ if(type === functionType) { context = context.call(this); }
146
+
147
+ if(!context || Handlebars.Utils.isEmpty(context)) {
148
+ return options.inverse(this);
149
+ } else {
150
+ return options.fn(this);
151
+ }
152
+ });
153
+
154
+ Handlebars.registerHelper('unless', function(context, options) {
155
+ return Handlebars.helpers['if'].call(this, context, {fn: options.inverse, inverse: options.fn});
156
+ });
157
+
158
+ Handlebars.registerHelper('with', function(context, options) {
159
+ return options.fn(context);
160
+ });
161
+
162
+ Handlebars.registerHelper('log', function(context, options) {
163
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
164
+ Handlebars.log(level, context);
165
+ });
166
+ ;
167
+ // lib/handlebars/utils.js
168
+
169
+ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
170
+
171
+ Handlebars.Exception = function(message) {
172
+ var tmp = Error.prototype.constructor.apply(this, arguments);
173
+
174
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
175
+ for (var idx = 0; idx < errorProps.length; idx++) {
176
+ this[errorProps[idx]] = tmp[errorProps[idx]];
177
+ }
178
+ };
179
+ Handlebars.Exception.prototype = new Error();
180
+
181
+ // Build out our basic SafeString type
182
+ Handlebars.SafeString = function(string) {
183
+ this.string = string;
184
+ };
185
+ Handlebars.SafeString.prototype.toString = function() {
186
+ return this.string.toString();
187
+ };
188
+
189
+ var escape = {
190
+ "&": "&amp;",
191
+ "<": "&lt;",
192
+ ">": "&gt;",
193
+ '"': "&quot;",
194
+ "'": "&#x27;",
195
+ "`": "&#x60;"
196
+ };
197
+
198
+ var badChars = /[&<>"'`]/g;
199
+ var possible = /[&<>"'`]/;
200
+
201
+ var escapeChar = function(chr) {
202
+ return escape[chr] || "&amp;";
203
+ };
204
+
205
+ Handlebars.Utils = {
206
+ escapeExpression: function(string) {
207
+ // don't escape SafeStrings, since they're already safe
208
+ if (string instanceof Handlebars.SafeString) {
209
+ return string.toString();
210
+ } else if (string == null || string === false) {
211
+ return "";
212
+ }
213
+
214
+ if(!possible.test(string)) { return string; }
215
+ return string.replace(badChars, escapeChar);
216
+ },
217
+
218
+ isEmpty: function(value) {
219
+ if (!value && value !== 0) {
220
+ return true;
221
+ } else if(toString.call(value) === "[object Array]" && value.length === 0) {
222
+ return true;
223
+ } else {
224
+ return false;
225
+ }
226
+ }
227
+ };
228
+ ;
229
+ // lib/handlebars/runtime.js
230
+
231
+ Handlebars.VM = {
232
+ template: function(templateSpec) {
233
+ // Just add water
234
+ var container = {
235
+ escapeExpression: Handlebars.Utils.escapeExpression,
236
+ invokePartial: Handlebars.VM.invokePartial,
237
+ programs: [],
238
+ program: function(i, fn, data) {
239
+ var programWrapper = this.programs[i];
240
+ if(data) {
241
+ return Handlebars.VM.program(fn, data);
242
+ } else if(programWrapper) {
243
+ return programWrapper;
244
+ } else {
245
+ programWrapper = this.programs[i] = Handlebars.VM.program(fn);
246
+ return programWrapper;
247
+ }
248
+ },
249
+ programWithDepth: Handlebars.VM.programWithDepth,
250
+ noop: Handlebars.VM.noop,
251
+ compilerInfo: null
252
+ };
253
+
254
+ return function(context, options) {
255
+ options = options || {};
256
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
257
+
258
+ var compilerInfo = container.compilerInfo || [],
259
+ compilerRevision = compilerInfo[0] || 1,
260
+ currentRevision = Handlebars.COMPILER_REVISION;
261
+
262
+ if (compilerRevision !== currentRevision) {
263
+ if (compilerRevision < currentRevision) {
264
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
265
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
266
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
267
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
268
+ } else {
269
+ // Use the embedded version info since the runtime doesn't know about this revision yet
270
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
271
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
272
+ }
273
+ }
274
+
275
+ return result;
276
+ };
277
+ },
278
+
279
+ programWithDepth: function(fn, data, $depth) {
280
+ var args = Array.prototype.slice.call(arguments, 2);
281
+
282
+ return function(context, options) {
283
+ options = options || {};
284
+
285
+ return fn.apply(this, [context, options.data || data].concat(args));
286
+ };
287
+ },
288
+ program: function(fn, data) {
289
+ return function(context, options) {
290
+ options = options || {};
291
+
292
+ return fn(context, options.data || data);
293
+ };
294
+ },
295
+ noop: function() { return ""; },
296
+ invokePartial: function(partial, name, context, helpers, partials, data) {
297
+ var options = { helpers: helpers, partials: partials, data: data };
298
+
299
+ if(partial === undefined) {
300
+ throw new Handlebars.Exception("The partial " + name + " could not be found");
301
+ } else if(partial instanceof Function) {
302
+ return partial(context, options);
303
+ } else if (!Handlebars.compile) {
304
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
305
+ } else {
306
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
307
+ return partials[name](context, options);
308
+ }
309
+ }
310
+ };
311
+
312
+ Handlebars.template = Handlebars.VM.template;
313
+ ;
314
+ // lib/handlebars/browser-suffix.js
315
+ })(Handlebars);
316
+ ;
@@ -0,0 +1,11 @@
1
+ module Handlebars
2
+ module Source
3
+ def self.bundled_path
4
+ File.expand_path("../../../dist/handlebars.js", __FILE__)
5
+ end
6
+
7
+ def self.runtime_bundled_path
8
+ File.expand_path("../../../dist/handlebars.runtime.js", __FILE__)
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: handlebars-source-machty
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.rc1
5
+ prerelease: 4
6
+ platform: ruby
7
+ authors:
8
+ - Yehuda Katz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Handlebars.js source code wrapper for (pre)compilation gems.
15
+ email:
16
+ - wycats@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - dist/handlebars.js
22
+ - dist/handlebars.runtime.js
23
+ - lib/handlebars/source.rb
24
+ homepage: https://github.com/wycats/handlebars.js/
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>'
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.1
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Handlebars.js source code wrapper
48
+ test_files: []
49
+ has_rdoc: