1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function require(path, parent, orig) {
|
11 | var resolved = require.resolve(path);
|
12 |
|
13 |
|
14 | if (null == resolved) {
|
15 | orig = orig || path;
|
16 | parent = parent || 'root';
|
17 | var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
|
18 | err.path = orig;
|
19 | err.parent = parent;
|
20 | err.require = true;
|
21 | throw err;
|
22 | }
|
23 |
|
24 | var module = require.modules[resolved];
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | if (!module.exports) {
|
30 | module.exports = {};
|
31 | module.client = module.component = true;
|
32 | module.call(this, module.exports, require.relative(resolved), module);
|
33 | }
|
34 |
|
35 | return module.exports;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | require.modules = {};
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | require.aliases = {};
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | require.resolve = function(path) {
|
65 | if (path.charAt(0) === '/') path = path.slice(1);
|
66 | var index = path + '/index.js';
|
67 |
|
68 | var paths = [
|
69 | path,
|
70 | path + '.js',
|
71 | path + '.json',
|
72 | path + '/index.js',
|
73 | path + '/index.json'
|
74 | ];
|
75 |
|
76 | for (var i = 0; i < paths.length; i++) {
|
77 | var path = paths[i];
|
78 | if (require.modules.hasOwnProperty(path)) return path;
|
79 | }
|
80 |
|
81 | if (require.aliases.hasOwnProperty(index)) {
|
82 | return require.aliases[index];
|
83 | }
|
84 | };
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | require.normalize = function(curr, path) {
|
96 | var segs = [];
|
97 |
|
98 | if ('.' != path.charAt(0)) return path;
|
99 |
|
100 | curr = curr.split('/');
|
101 | path = path.split('/');
|
102 |
|
103 | for (var i = 0; i < path.length; ++i) {
|
104 | if ('..' == path[i]) {
|
105 | curr.pop();
|
106 | } else if ('.' != path[i] && '' != path[i]) {
|
107 | segs.push(path[i]);
|
108 | }
|
109 | }
|
110 |
|
111 | return curr.concat(segs).join('/');
|
112 | };
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | require.register = function(path, definition) {
|
123 | require.modules[path] = definition;
|
124 | };
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | require.alias = function(from, to) {
|
135 | if (!require.modules.hasOwnProperty(from)) {
|
136 | throw new Error('Failed to alias "' + from + '", it does not exist');
|
137 | }
|
138 | require.aliases[to] = from;
|
139 | };
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | require.relative = function(parent) {
|
150 | var p = require.normalize(parent, '..');
|
151 |
|
152 | |
153 |
|
154 |
|
155 |
|
156 | function lastIndexOf(arr, obj) {
|
157 | var i = arr.length;
|
158 | while (i--) {
|
159 | if (arr[i] === obj) return i;
|
160 | }
|
161 | return -1;
|
162 | }
|
163 |
|
164 | |
165 |
|
166 |
|
167 |
|
168 | function localRequire(path) {
|
169 | var resolved = localRequire.resolve(path);
|
170 | return require(resolved, parent, path);
|
171 | }
|
172 |
|
173 | |
174 |
|
175 |
|
176 |
|
177 | localRequire.resolve = function(path) {
|
178 | var c = path.charAt(0);
|
179 | if ('/' == c) return path.slice(1);
|
180 | if ('.' == c) return require.normalize(p, path);
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | var segs = parent.split('/');
|
186 | var i = lastIndexOf(segs, 'deps') + 1;
|
187 | if (!i) i = 0;
|
188 | path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
|
189 | return path;
|
190 | };
|
191 |
|
192 | |
193 |
|
194 |
|
195 |
|
196 | localRequire.exists = function(path) {
|
197 | return require.modules.hasOwnProperty(localRequire.resolve(path));
|
198 | };
|
199 |
|
200 | return localRequire;
|
201 | };
|
202 | require.register("example/index.js", function(exports, require, module){
|
203 | var template = require('./template')
|
204 | , html = template({ youAreUsingJade : true });
|
205 |
|
206 | document.body.innerHTML = html;
|
207 | });
|
208 | require.register("example/jade-runtime.js", function(exports, require, module){
|
209 |
|
210 | jade = (function(exports){
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | if (!Array.isArray) {
|
222 | Array.isArray = function(arr){
|
223 | return '[object Array]' == Object.prototype.toString.call(arr);
|
224 | };
|
225 | }
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | if (!Object.keys) {
|
232 | Object.keys = function(obj){
|
233 | var arr = [];
|
234 | for (var key in obj) {
|
235 | if (obj.hasOwnProperty(key)) {
|
236 | arr.push(key);
|
237 | }
|
238 | }
|
239 | return arr;
|
240 | }
|
241 | }
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | exports.merge = function merge(a, b) {
|
256 | var ac = a['class'];
|
257 | var bc = b['class'];
|
258 |
|
259 | if (ac || bc) {
|
260 | ac = ac || [];
|
261 | bc = bc || [];
|
262 | if (!Array.isArray(ac)) ac = [ac];
|
263 | if (!Array.isArray(bc)) bc = [bc];
|
264 | ac = ac.filter(nulls);
|
265 | bc = bc.filter(nulls);
|
266 | a['class'] = ac.concat(bc).join(' ');
|
267 | }
|
268 |
|
269 | for (var key in b) {
|
270 | if (key != 'class') {
|
271 | a[key] = b[key];
|
272 | }
|
273 | }
|
274 |
|
275 | return a;
|
276 | };
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 | function nulls(val) {
|
287 | return val != null;
|
288 | }
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | exports.attrs = function attrs(obj, escaped){
|
300 | var buf = []
|
301 | , terse = obj.terse;
|
302 |
|
303 | delete obj.terse;
|
304 | var keys = Object.keys(obj)
|
305 | , len = keys.length;
|
306 |
|
307 | if (len) {
|
308 | buf.push('');
|
309 | for (var i = 0; i < len; ++i) {
|
310 | var key = keys[i]
|
311 | , val = obj[key];
|
312 |
|
313 | if ('boolean' == typeof val || null == val) {
|
314 | if (val) {
|
315 | terse
|
316 | ? buf.push(key)
|
317 | : buf.push(key + '="' + key + '"');
|
318 | }
|
319 | } else if (0 == key.indexOf('data') && 'string' != typeof val) {
|
320 | buf.push(key + "='" + JSON.stringify(val) + "'");
|
321 | } else if ('class' == key && Array.isArray(val)) {
|
322 | buf.push(key + '="' + exports.escape(val.join(' ')) + '"');
|
323 | } else if (escaped && escaped[key]) {
|
324 | buf.push(key + '="' + exports.escape(val) + '"');
|
325 | } else {
|
326 | buf.push(key + '="' + val + '"');
|
327 | }
|
328 | }
|
329 | }
|
330 |
|
331 | return buf.join(' ');
|
332 | };
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | exports.escape = function escape(html){
|
343 | return String(html)
|
344 | .replace(/&(?!(\w+|\#\d+);)/g, '&')
|
345 | .replace(/</g, '<')
|
346 | .replace(/>/g, '>')
|
347 | .replace(/"/g, '"');
|
348 | };
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | exports.rethrow = function rethrow(err, filename, lineno){
|
361 | if (!filename) throw err;
|
362 |
|
363 | var context = 3
|
364 | , str = require('fs').readFileSync(filename, 'utf8')
|
365 | , lines = str.split('\n')
|
366 | , start = Math.max(lineno - context, 0)
|
367 | , end = Math.min(lines.length, lineno + context);
|
368 |
|
369 |
|
370 | var context = lines.slice(start, end).map(function(line, i){
|
371 | var curr = i + start + 1;
|
372 | return (curr == lineno ? ' > ' : ' ')
|
373 | + curr
|
374 | + '| '
|
375 | + line;
|
376 | }).join('\n');
|
377 |
|
378 |
|
379 | err.path = filename;
|
380 | err.message = (filename || 'Jade') + ':' + lineno
|
381 | + '\n' + context + '\n\n' + err.message;
|
382 | throw err;
|
383 | };
|
384 |
|
385 | return exports;
|
386 |
|
387 | })({});
|
388 | });
|
389 | require.register("example/template.js", function(exports, require, module){
|
390 | module.exports = function anonymous(locals, attrs, escape, rethrow, merge) {
|
391 | attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
|
392 | var buf = [];
|
393 | with (locals || {}) {
|
394 | var interp;
|
395 | buf.push('<h1>Jade - node template engine</h1><div id="container">');
|
396 | if ( youAreUsingJade)
|
397 | {
|
398 | buf.push('<p>You are amazing</p>');
|
399 | }
|
400 | else
|
401 | {
|
402 | buf.push('<p>Get on it!</p>');
|
403 | }
|
404 | buf.push('</div>');
|
405 | }
|
406 | return buf.join("");
|
407 | }
|
408 | });
|
409 | require.alias("example/index.js", "example/index.js");
|
410 |
|
411 | require("example/jade-runtime");
|