1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var has = Object.prototype.hasOwnProperty;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function require(path, parent, orig) {
|
18 | var resolved = require.resolve(path);
|
19 |
|
20 |
|
21 | if (null == resolved) {
|
22 | orig = orig || path;
|
23 | parent = parent || 'root';
|
24 | var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
|
25 | err.path = orig;
|
26 | err.parent = parent;
|
27 | err.require = true;
|
28 | throw err;
|
29 | }
|
30 |
|
31 | var module = require.modules[resolved];
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | if (!module.exports) {
|
37 | module.exports = {};
|
38 | module.client = module.component = true;
|
39 | module.call(this, module.exports, require.relative(resolved), module);
|
40 | }
|
41 |
|
42 | return module.exports;
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | require.modules = {};
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | require.aliases = {};
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | require.resolve = function(path) {
|
72 | if (path.charAt(0) === '/') path = path.slice(1);
|
73 | var index = path + '/index.js';
|
74 |
|
75 | var paths = [
|
76 | path,
|
77 | path + '.js',
|
78 | path + '.json',
|
79 | path + '/index.js',
|
80 | path + '/index.json'
|
81 | ];
|
82 |
|
83 | for (var i = 0; i < paths.length; i++) {
|
84 | var path = paths[i];
|
85 | if (has.call(require.modules, path)) return path;
|
86 | }
|
87 |
|
88 | if (has.call(require.aliases, index)) {
|
89 | return require.aliases[index];
|
90 | }
|
91 | };
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | require.normalize = function(curr, path) {
|
103 | var segs = [];
|
104 |
|
105 | if ('.' != path.charAt(0)) return path;
|
106 |
|
107 | curr = curr.split('/');
|
108 | path = path.split('/');
|
109 |
|
110 | for (var i = 0; i < path.length; ++i) {
|
111 | if ('..' == path[i]) {
|
112 | curr.pop();
|
113 | } else if ('.' != path[i] && '' != path[i]) {
|
114 | segs.push(path[i]);
|
115 | }
|
116 | }
|
117 |
|
118 | return curr.concat(segs).join('/');
|
119 | };
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | require.register = function(path, definition) {
|
130 | require.modules[path] = definition;
|
131 | };
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | require.alias = function(from, to) {
|
142 | if (!has.call(require.modules, from)) {
|
143 | throw new Error('Failed to alias "' + from + '", it does not exist');
|
144 | }
|
145 | require.aliases[to] = from;
|
146 | };
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | require.relative = function(parent) {
|
157 | var p = require.normalize(parent, '..');
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 | function lastIndexOf(arr, obj) {
|
164 | var i = arr.length;
|
165 | while (i--) {
|
166 | if (arr[i] === obj) return i;
|
167 | }
|
168 | return -1;
|
169 | }
|
170 |
|
171 | |
172 |
|
173 |
|
174 |
|
175 | function localRequire(path) {
|
176 | var resolved = localRequire.resolve(path);
|
177 | return require(resolved, parent, path);
|
178 | }
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 | localRequire.resolve = function(path) {
|
185 | var c = path.charAt(0);
|
186 | if ('/' == c) return path.slice(1);
|
187 | if ('.' == c) return require.normalize(p, path);
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | var segs = parent.split('/');
|
193 | var i = lastIndexOf(segs, 'deps') + 1;
|
194 | if (!i) i = 0;
|
195 | path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
|
196 | return path;
|
197 | };
|
198 |
|
199 | |
200 |
|
201 |
|
202 |
|
203 | localRequire.exists = function(path) {
|
204 | return has.call(require.modules, localRequire.resolve(path));
|
205 | };
|
206 |
|
207 | return localRequire;
|
208 | };
|
209 | require.register("example/index.js", function(exports, require, module){
|
210 |
|
211 | var template = require('./template');
|
212 |
|
213 |
|
214 | exports.foo = function (locals) {
|
215 | return '\n' + template(locals);
|
216 | };
|
217 | });
|
218 | require.register("example/template.js", function(exports, require, module){
|
219 | module.exports =function anonymous(locals, attrs, escape, rethrow, merge) {
|
220 | attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
|
221 | var buf = [];
|
222 | with (locals || {}) {
|
223 | var interp;
|
224 | buf.push('<!DOCTYPE html><html lang="en"><head><title>');
|
225 | var __val__ = pageTitle
|
226 | buf.push(escape(null == __val__ ? "" : __val__));
|
227 | buf.push('</title><script type="text/javascript">if (foo) {\n bar()\n}</script></head><body><h1>Jade - node template engine</h1><div id="container">');
|
228 | if ( youAreUsingJade)
|
229 | {
|
230 | buf.push('<p>You are amazing</p>');
|
231 | }
|
232 | else
|
233 | {
|
234 | buf.push('<p>Get on it!</p>');
|
235 | }
|
236 | buf.push('</div></body></html>');
|
237 | }
|
238 | return buf.join("");
|
239 | }
|
240 | });
|
241 | require.alias("example/index.js", "example/index.js");
|
242 |
|