handlebars-source 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of handlebars-source might be problematic. Click here for more details.
- data/dist/handlebars.js +1992 -0
- data/dist/handlebars.runtime.js +271 -0
- data/lib/handlebars/source.rb +11 -0
- metadata +49 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
// lib/handlebars/base.js
|
2
|
+
|
3
|
+
/*jshint eqnull:true*/
|
4
|
+
this.Handlebars = {};
|
5
|
+
|
6
|
+
(function(Handlebars) {
|
7
|
+
|
8
|
+
Handlebars.VERSION = "1.0.rc.1";
|
9
|
+
|
10
|
+
Handlebars.helpers = {};
|
11
|
+
Handlebars.partials = {};
|
12
|
+
|
13
|
+
Handlebars.registerHelper = function(name, fn, inverse) {
|
14
|
+
if(inverse) { fn.not = inverse; }
|
15
|
+
this.helpers[name] = fn;
|
16
|
+
};
|
17
|
+
|
18
|
+
Handlebars.registerPartial = function(name, str) {
|
19
|
+
this.partials[name] = str;
|
20
|
+
};
|
21
|
+
|
22
|
+
Handlebars.registerHelper('helperMissing', function(arg) {
|
23
|
+
if(arguments.length === 2) {
|
24
|
+
return undefined;
|
25
|
+
} else {
|
26
|
+
throw new Error("Could not find property '" + arg + "'");
|
27
|
+
}
|
28
|
+
});
|
29
|
+
|
30
|
+
var toString = Object.prototype.toString, functionType = "[object Function]";
|
31
|
+
|
32
|
+
Handlebars.registerHelper('blockHelperMissing', function(context, options) {
|
33
|
+
var inverse = options.inverse || function() {}, fn = options.fn;
|
34
|
+
|
35
|
+
|
36
|
+
var ret = "";
|
37
|
+
var type = toString.call(context);
|
38
|
+
|
39
|
+
if(type === functionType) { context = context.call(this); }
|
40
|
+
|
41
|
+
if(context === true) {
|
42
|
+
return fn(this);
|
43
|
+
} else if(context === false || context == null) {
|
44
|
+
return inverse(this);
|
45
|
+
} else if(type === "[object Array]") {
|
46
|
+
if(context.length > 0) {
|
47
|
+
return Handlebars.helpers.each(context, options);
|
48
|
+
} else {
|
49
|
+
return inverse(this);
|
50
|
+
}
|
51
|
+
} else {
|
52
|
+
return fn(context);
|
53
|
+
}
|
54
|
+
});
|
55
|
+
|
56
|
+
Handlebars.K = function() {};
|
57
|
+
|
58
|
+
Handlebars.createFrame = Object.create || function(object) {
|
59
|
+
Handlebars.K.prototype = object;
|
60
|
+
var obj = new Handlebars.K();
|
61
|
+
Handlebars.K.prototype = null;
|
62
|
+
return obj;
|
63
|
+
};
|
64
|
+
|
65
|
+
Handlebars.logger = {
|
66
|
+
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
67
|
+
|
68
|
+
methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
|
69
|
+
|
70
|
+
// can be overridden in the host environment
|
71
|
+
log: function(level, obj) {
|
72
|
+
if (Handlebars.logger.level <= level) {
|
73
|
+
var method = Handlebars.logger.methodMap[level];
|
74
|
+
if (typeof console !== 'undefined' && console[method]) {
|
75
|
+
console[method].call(console, obj);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
|
82
|
+
|
83
|
+
Handlebars.registerHelper('each', function(context, options) {
|
84
|
+
var fn = options.fn, inverse = options.inverse;
|
85
|
+
var i = 0, ret = "", data;
|
86
|
+
|
87
|
+
if (options.data) {
|
88
|
+
data = Handlebars.createFrame(options.data);
|
89
|
+
}
|
90
|
+
|
91
|
+
if(context && typeof context === 'object') {
|
92
|
+
if(context instanceof Array){
|
93
|
+
for(var j = context.length; i<j; i++) {
|
94
|
+
if (data) { data.index = i; }
|
95
|
+
ret = ret + fn(context[i], { data: data });
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
for(var key in context) {
|
99
|
+
if(context.hasOwnProperty(key)) {
|
100
|
+
if(data) { data.key = key; }
|
101
|
+
ret = ret + fn(context[key], {data: data});
|
102
|
+
i++;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
if(i === 0){
|
109
|
+
ret = inverse(this);
|
110
|
+
}
|
111
|
+
|
112
|
+
return ret;
|
113
|
+
});
|
114
|
+
|
115
|
+
Handlebars.registerHelper('if', function(context, options) {
|
116
|
+
var type = toString.call(context);
|
117
|
+
if(type === functionType) { context = context.call(this); }
|
118
|
+
|
119
|
+
if(!context || Handlebars.Utils.isEmpty(context)) {
|
120
|
+
return options.inverse(this);
|
121
|
+
} else {
|
122
|
+
return options.fn(this);
|
123
|
+
}
|
124
|
+
});
|
125
|
+
|
126
|
+
Handlebars.registerHelper('unless', function(context, options) {
|
127
|
+
var fn = options.fn, inverse = options.inverse;
|
128
|
+
options.fn = inverse;
|
129
|
+
options.inverse = fn;
|
130
|
+
|
131
|
+
return Handlebars.helpers['if'].call(this, context, options);
|
132
|
+
});
|
133
|
+
|
134
|
+
Handlebars.registerHelper('with', function(context, options) {
|
135
|
+
return options.fn(context);
|
136
|
+
});
|
137
|
+
|
138
|
+
Handlebars.registerHelper('log', function(context, options) {
|
139
|
+
var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
|
140
|
+
Handlebars.log(level, context);
|
141
|
+
});
|
142
|
+
|
143
|
+
}(this.Handlebars));
|
144
|
+
;
|
145
|
+
// lib/handlebars/utils.js
|
146
|
+
|
147
|
+
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
148
|
+
|
149
|
+
Handlebars.Exception = function(message) {
|
150
|
+
var tmp = Error.prototype.constructor.apply(this, arguments);
|
151
|
+
|
152
|
+
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
153
|
+
for (var idx = 0; idx < errorProps.length; idx++) {
|
154
|
+
this[errorProps[idx]] = tmp[errorProps[idx]];
|
155
|
+
}
|
156
|
+
};
|
157
|
+
Handlebars.Exception.prototype = new Error();
|
158
|
+
|
159
|
+
// Build out our basic SafeString type
|
160
|
+
Handlebars.SafeString = function(string) {
|
161
|
+
this.string = string;
|
162
|
+
};
|
163
|
+
Handlebars.SafeString.prototype.toString = function() {
|
164
|
+
return this.string.toString();
|
165
|
+
};
|
166
|
+
|
167
|
+
(function() {
|
168
|
+
var escape = {
|
169
|
+
"&": "&",
|
170
|
+
"<": "<",
|
171
|
+
">": ">",
|
172
|
+
'"': """,
|
173
|
+
"'": "'",
|
174
|
+
"`": "`"
|
175
|
+
};
|
176
|
+
|
177
|
+
var badChars = /[&<>"'`]/g;
|
178
|
+
var possible = /[&<>"'`]/;
|
179
|
+
|
180
|
+
var escapeChar = function(chr) {
|
181
|
+
return escape[chr] || "&";
|
182
|
+
};
|
183
|
+
|
184
|
+
Handlebars.Utils = {
|
185
|
+
escapeExpression: function(string) {
|
186
|
+
// don't escape SafeStrings, since they're already safe
|
187
|
+
if (string instanceof Handlebars.SafeString) {
|
188
|
+
return string.toString();
|
189
|
+
} else if (string == null || string === false) {
|
190
|
+
return "";
|
191
|
+
}
|
192
|
+
|
193
|
+
if(!possible.test(string)) { return string; }
|
194
|
+
return string.replace(badChars, escapeChar);
|
195
|
+
},
|
196
|
+
|
197
|
+
isEmpty: function(value) {
|
198
|
+
if (!value && value !== 0) {
|
199
|
+
return true;
|
200
|
+
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
201
|
+
return true;
|
202
|
+
} else {
|
203
|
+
return false;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
};
|
207
|
+
})();;
|
208
|
+
// lib/handlebars/runtime.js
|
209
|
+
Handlebars.VM = {
|
210
|
+
template: function(templateSpec) {
|
211
|
+
// Just add water
|
212
|
+
var container = {
|
213
|
+
escapeExpression: Handlebars.Utils.escapeExpression,
|
214
|
+
invokePartial: Handlebars.VM.invokePartial,
|
215
|
+
programs: [],
|
216
|
+
program: function(i, fn, data) {
|
217
|
+
var programWrapper = this.programs[i];
|
218
|
+
if(data) {
|
219
|
+
return Handlebars.VM.program(fn, data);
|
220
|
+
} else if(programWrapper) {
|
221
|
+
return programWrapper;
|
222
|
+
} else {
|
223
|
+
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
224
|
+
return programWrapper;
|
225
|
+
}
|
226
|
+
},
|
227
|
+
programWithDepth: Handlebars.VM.programWithDepth,
|
228
|
+
noop: Handlebars.VM.noop
|
229
|
+
};
|
230
|
+
|
231
|
+
return function(context, options) {
|
232
|
+
options = options || {};
|
233
|
+
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
234
|
+
};
|
235
|
+
},
|
236
|
+
|
237
|
+
programWithDepth: function(fn, data, $depth) {
|
238
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
239
|
+
|
240
|
+
return function(context, options) {
|
241
|
+
options = options || {};
|
242
|
+
|
243
|
+
return fn.apply(this, [context, options.data || data].concat(args));
|
244
|
+
};
|
245
|
+
},
|
246
|
+
program: function(fn, data) {
|
247
|
+
return function(context, options) {
|
248
|
+
options = options || {};
|
249
|
+
|
250
|
+
return fn(context, options.data || data);
|
251
|
+
};
|
252
|
+
},
|
253
|
+
noop: function() { return ""; },
|
254
|
+
invokePartial: function(partial, name, context, helpers, partials, data) {
|
255
|
+
var options = { helpers: helpers, partials: partials, data: data };
|
256
|
+
|
257
|
+
if(partial === undefined) {
|
258
|
+
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
259
|
+
} else if(partial instanceof Function) {
|
260
|
+
return partial(context, options);
|
261
|
+
} else if (!Handlebars.compile) {
|
262
|
+
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
|
263
|
+
} else {
|
264
|
+
partials[name] = Handlebars.compile(partial, {data: data !== undefined});
|
265
|
+
return partials[name](context, options);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
};
|
269
|
+
|
270
|
+
Handlebars.template = Handlebars.VM.template;
|
271
|
+
;
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handlebars-source
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.rc1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yehuda Katz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-21 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:
|