acts_as_dashboard 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/acts_as_dashboard.gemspec +166 -0
- data/generators/dashboard/USAGE +23 -0
- data/generators/dashboard/dashboard_generator.rb +105 -0
- data/generators/dashboard/templates/controller.erb +39 -0
- data/generators/dashboard/templates/dashboard.css +66 -0
- data/generators/dashboard/templates/dashboard.js +305 -0
- data/generators/dashboard/templates/jqplot-0.9.7/jquery.jqplot.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.js +404 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.js +200 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.js +232 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.js +408 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.js +238 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.js +812 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.js +313 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.js +203 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.js +359 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.js +434 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.js +595 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.js +308 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.js +343 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.js +333 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js +307 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js.orig +273 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.js +208 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.min.js +14 -0
- data/generators/dashboard/templates/jquery.jqplot.min.css +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/CHANGELOG +269 -0
- data/generators/dashboard/templates/js.class-2.1.4/MIT-LICENSE +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/README +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/command.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/comparable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/constant_scope.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/core.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/decorator.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/enumerable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/forwardable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/hash.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/linked_list.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/loader.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/method_chain.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/observable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/package.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/proxy.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/ruby.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/set.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stack_trace.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/state.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stdlib.js +16 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/command.js +93 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/comparable.js +37 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/constant_scope.js +48 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/core.js +1060 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/decorator.js +50 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/enumerable.js +505 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/forwardable.js +22 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/hash.js +334 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/linked_list.js +114 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/loader.js +458 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/method_chain.js +172 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/observable.js +55 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/package.js +377 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/proxy.js +58 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/ruby.js +44 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/set.js +332 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stack_trace.js +151 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/state.js +95 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stdlib.js +2517 -0
- data/generators/dashboard/templates/show.html.erb +67 -0
- data/lib/acts_as_dashboard/app/views/dashboards/show.html.erb +67 -0
- data/lib/acts_as_dashboard/class_methods.rb +58 -0
- data/lib/acts_as_dashboard/config.rb +25 -0
- data/lib/acts_as_dashboard/instance_methods.rb +32 -0
- data/lib/acts_as_dashboard/line_graph_widget.rb +68 -0
- data/lib/acts_as_dashboard/public/javascripts/dashboard.js +305 -0
- data/lib/acts_as_dashboard/public/stylesheets/dashboard.css +66 -0
- data/lib/acts_as_dashboard/short_messages_widget.rb +25 -0
- data/lib/acts_as_dashboard/widget.rb +55 -0
- data/lib/acts_as_dashboard.rb +17 -0
- data/spec/acts_as_dashboard/class_method_specs.rb +188 -0
- data/spec/acts_as_dashboard/config_spec.rb +57 -0
- data/spec/acts_as_dashboard/instance_methods_spec.rb +134 -0
- data/spec/acts_as_dashboard/line_graph_widget_spec.rb +165 -0
- data/spec/acts_as_dashboard/short_messages_widget_spec.rb +69 -0
- data/spec/acts_as_dashboard/widget_spec.rb +6 -0
- data/spec/acts_as_dashboard_spec.rb +15 -0
- data/spec/shared/widget_behaviours.rb +171 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/install.rake +8 -0
- data/tasks/install_javascript.rake +7 -0
- data/tasks/install_stylesheets.rake +7 -0
- metadata +209 -0
@@ -0,0 +1,377 @@
|
|
1
|
+
this.JS = this.JS || {};
|
2
|
+
|
3
|
+
JS.Package = function(loader) {
|
4
|
+
var Set = JS.Package.OrderedSet;
|
5
|
+
JS.Package._index(this);
|
6
|
+
|
7
|
+
this._loader = loader;
|
8
|
+
this._names = new Set();
|
9
|
+
this._deps = new Set();
|
10
|
+
this._uses = new Set();
|
11
|
+
this._observers = {};
|
12
|
+
this._events = {};
|
13
|
+
};
|
14
|
+
|
15
|
+
(function(klass) {
|
16
|
+
//================================================================
|
17
|
+
// Ordered list of unique elements, for storing dependencies
|
18
|
+
|
19
|
+
var Set = klass.OrderedSet = function(list, transform) {
|
20
|
+
this._members = this.list = [];
|
21
|
+
this._index = {};
|
22
|
+
if (!list) return;
|
23
|
+
|
24
|
+
for (var i = 0, n = list.length; i < n; i++)
|
25
|
+
this.push(transform ? transform(list[i]) : list[i]);
|
26
|
+
};
|
27
|
+
|
28
|
+
Set.prototype.push = function(item) {
|
29
|
+
var key = (item.id !== undefined) ? item.id : item,
|
30
|
+
index = this._index;
|
31
|
+
|
32
|
+
if (index.hasOwnProperty(key)) return;
|
33
|
+
index[key] = this._members.length;
|
34
|
+
this._members.push(item);
|
35
|
+
};
|
36
|
+
|
37
|
+
//================================================================
|
38
|
+
// Environment settings
|
39
|
+
|
40
|
+
klass._env = this;
|
41
|
+
|
42
|
+
if ((this.document || {}).getElementsByTagName) {
|
43
|
+
var script = document.getElementsByTagName('script')[0];
|
44
|
+
klass._isIE = (script.readyState !== undefined);
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
//================================================================
|
49
|
+
// Configuration methods, called by the DSL
|
50
|
+
|
51
|
+
var instance = klass.prototype;
|
52
|
+
|
53
|
+
instance.addDependency = function(pkg) {
|
54
|
+
this._deps.push(pkg);
|
55
|
+
};
|
56
|
+
|
57
|
+
instance.addSoftDependency = function(pkg) {
|
58
|
+
this._uses.push(pkg);
|
59
|
+
};
|
60
|
+
|
61
|
+
instance.addName = function(name) {
|
62
|
+
this._names.push(name);
|
63
|
+
klass.getFromCache(name).pkg = this;
|
64
|
+
};
|
65
|
+
|
66
|
+
instance.onload = function(block) {
|
67
|
+
this._onload = block;
|
68
|
+
};
|
69
|
+
|
70
|
+
//================================================================
|
71
|
+
// Event dispatchers, for communication between packages
|
72
|
+
|
73
|
+
instance.on = function(eventType, block, scope) {
|
74
|
+
if (this._events[eventType]) return block.call(scope);
|
75
|
+
var list = this._observers[eventType] = this._observers[eventType] || [];
|
76
|
+
list.push([block, scope]);
|
77
|
+
};
|
78
|
+
|
79
|
+
instance.fire = function(eventType) {
|
80
|
+
if (this._events[eventType]) return false;
|
81
|
+
this._events[eventType] = true;
|
82
|
+
|
83
|
+
var list = this._observers[eventType];
|
84
|
+
if (!list) return true;
|
85
|
+
delete this._observers[eventType];
|
86
|
+
|
87
|
+
for (var i = 0, n = list.length; i < n; i++)
|
88
|
+
list[i][0].call(list[i][1]);
|
89
|
+
|
90
|
+
return true;
|
91
|
+
};
|
92
|
+
|
93
|
+
//================================================================
|
94
|
+
// Loading frontend and other miscellany
|
95
|
+
|
96
|
+
instance.isLoaded = function(withExceptions) {
|
97
|
+
if (!withExceptions && this._isLoaded !== undefined) return this._isLoaded;
|
98
|
+
|
99
|
+
var names = this._names.list,
|
100
|
+
i = names.length,
|
101
|
+
name, object;
|
102
|
+
|
103
|
+
while (i--) { name = names[i];
|
104
|
+
object = klass.getObject(name);
|
105
|
+
if (object !== undefined) continue;
|
106
|
+
if (withExceptions)
|
107
|
+
throw new Error('Expected package at ' + this._loader + ' to define ' + name);
|
108
|
+
else
|
109
|
+
return this._isLoaded = false;
|
110
|
+
}
|
111
|
+
return this._isLoaded = true;
|
112
|
+
};
|
113
|
+
|
114
|
+
instance.load = function() {
|
115
|
+
if (!this.fire('request')) return;
|
116
|
+
|
117
|
+
var allDeps = this._deps.list.concat(this._uses.list),
|
118
|
+
startEvent = 'load', // could potentially use 'download' event in
|
119
|
+
listener = {}; // browsers that guarantee execution order
|
120
|
+
|
121
|
+
listener[startEvent] = this._deps.list;
|
122
|
+
|
123
|
+
klass.when(listener, function() {
|
124
|
+
klass.when({complete: allDeps, load: [this]}, function() {
|
125
|
+
this.fire('complete');
|
126
|
+
}, this);
|
127
|
+
|
128
|
+
var self = this, fireOnLoad = function() {
|
129
|
+
if (self._onload) self._onload();
|
130
|
+
self.isLoaded(true);
|
131
|
+
self.fire('load');
|
132
|
+
};
|
133
|
+
|
134
|
+
if (this.isLoaded()) {
|
135
|
+
this.fire('download');
|
136
|
+
return this.fire('load');
|
137
|
+
}
|
138
|
+
|
139
|
+
if (this._loader === undefined)
|
140
|
+
throw new Error('No load path found for ' + this._names.list[0]);
|
141
|
+
|
142
|
+
typeof this._loader === 'function'
|
143
|
+
? this._loader(fireOnLoad)
|
144
|
+
: klass.Loader.loadFile(this._loader, fireOnLoad);
|
145
|
+
|
146
|
+
this.fire('download');
|
147
|
+
}, this);
|
148
|
+
};
|
149
|
+
|
150
|
+
instance.toString = function() {
|
151
|
+
return 'Package:' + this._names.list.join(',');
|
152
|
+
};
|
153
|
+
|
154
|
+
//================================================================
|
155
|
+
// Class-level event API, handles group listeners
|
156
|
+
|
157
|
+
klass.when = function(eventTable, block, scope) {
|
158
|
+
var eventList = [], event, packages, i;
|
159
|
+
for (event in eventTable) {
|
160
|
+
if (!eventTable.hasOwnProperty(event)) continue;
|
161
|
+
packages = new klass.OrderedSet(eventTable[event], function(name) { return klass.getByName(name) });
|
162
|
+
i = packages.list.length;
|
163
|
+
while (i--) eventList.push([event, packages.list[i]]);
|
164
|
+
}
|
165
|
+
|
166
|
+
var waiting = i = eventList.length;
|
167
|
+
if (waiting === 0) return block && block.call(scope);
|
168
|
+
|
169
|
+
while (i--) {
|
170
|
+
eventList[i][1].on(eventList[i][0], function() {
|
171
|
+
waiting -= 1;
|
172
|
+
if (waiting === 0 && block) block.call(scope);
|
173
|
+
});
|
174
|
+
eventList[i][1].load();
|
175
|
+
}
|
176
|
+
};
|
177
|
+
|
178
|
+
//================================================================
|
179
|
+
// Indexes for fast lookup by path and name, and assigning IDs
|
180
|
+
|
181
|
+
klass._autoIncrement = 1;
|
182
|
+
klass._indexByPath = {};
|
183
|
+
klass._indexByName = {};
|
184
|
+
|
185
|
+
klass._index = function(pkg) {
|
186
|
+
pkg.id = this._autoIncrement;
|
187
|
+
this._autoIncrement += 1;
|
188
|
+
};
|
189
|
+
|
190
|
+
klass.getByPath = function(loader) {
|
191
|
+
var path = loader.toString();
|
192
|
+
return this._indexByPath[path] = this._indexByPath[path] || new this(loader);
|
193
|
+
};
|
194
|
+
|
195
|
+
klass.getByName = function(name) {
|
196
|
+
if (typeof name !== 'string') return name;
|
197
|
+
var cached = this.getFromCache(name);
|
198
|
+
if (cached.pkg) return cached.pkg;
|
199
|
+
|
200
|
+
var placeholder = new this();
|
201
|
+
placeholder.addName(name);
|
202
|
+
return placeholder;
|
203
|
+
};
|
204
|
+
|
205
|
+
//================================================================
|
206
|
+
// Cache for named packages and runtime objects
|
207
|
+
|
208
|
+
klass.getFromCache = function(name) {
|
209
|
+
return this._indexByName[name] = this._indexByName[name] || {};
|
210
|
+
};
|
211
|
+
|
212
|
+
klass.getObject = function(name) {
|
213
|
+
var cached = this.getFromCache(name);
|
214
|
+
if (cached.obj !== undefined) return cached.obj;
|
215
|
+
|
216
|
+
var object = this._env,
|
217
|
+
parts = name.split('.'), part;
|
218
|
+
|
219
|
+
while (part = parts.shift()) object = object && object[part];
|
220
|
+
|
221
|
+
return this.getFromCache(name).obj = object;
|
222
|
+
};
|
223
|
+
|
224
|
+
})(JS.Package);
|
225
|
+
|
226
|
+
|
227
|
+
JS.Package.DomLoader = {
|
228
|
+
usable: function() {
|
229
|
+
return !!JS.Package.getObject('window.document.getElementsByTagName');
|
230
|
+
},
|
231
|
+
|
232
|
+
__FILE__: function() {
|
233
|
+
var scripts = document.getElementsByTagName('script');
|
234
|
+
return scripts[scripts.length - 1].src;
|
235
|
+
},
|
236
|
+
|
237
|
+
loadFile: function(path, fireCallbacks) {
|
238
|
+
var self = this,
|
239
|
+
tag = document.createElement('script');
|
240
|
+
|
241
|
+
tag.type = 'text/javascript';
|
242
|
+
tag.src = path;
|
243
|
+
|
244
|
+
tag.onload = tag.onreadystatechange = function() {
|
245
|
+
var state = tag.readyState, status = tag.status;
|
246
|
+
if ( !state || state === 'loaded' || state === 'complete' || (state === 4 && status === 200) ) {
|
247
|
+
fireCallbacks();
|
248
|
+
tag.onload = tag.onreadystatechange = self._K;
|
249
|
+
tag = null;
|
250
|
+
}
|
251
|
+
};
|
252
|
+
|
253
|
+
if (window.console && console.info)
|
254
|
+
console.info('Loading ' + path);
|
255
|
+
|
256
|
+
document.getElementsByTagName('head')[0].appendChild(tag);
|
257
|
+
},
|
258
|
+
|
259
|
+
_K: function() {}
|
260
|
+
};
|
261
|
+
|
262
|
+
JS.Package.ServerLoader = {
|
263
|
+
usable: function() {
|
264
|
+
return typeof JS.Package.getObject('load') === 'function' &&
|
265
|
+
typeof JS.Package.getObject('version') === 'function';
|
266
|
+
},
|
267
|
+
|
268
|
+
setup: function() {
|
269
|
+
var self = this;
|
270
|
+
load = (function(origLoad) {
|
271
|
+
return function() {
|
272
|
+
self._currentPath = arguments[0];
|
273
|
+
return origLoad.apply(JS.Package._env, arguments);
|
274
|
+
};
|
275
|
+
})(load);
|
276
|
+
},
|
277
|
+
|
278
|
+
__FILE__: function() {
|
279
|
+
return this._currentPath;
|
280
|
+
},
|
281
|
+
|
282
|
+
loadFile: function(path, fireCallbacks) {
|
283
|
+
load(path);
|
284
|
+
fireCallbacks();
|
285
|
+
}
|
286
|
+
};
|
287
|
+
|
288
|
+
(function() {
|
289
|
+
var candidates = [ JS.Package.DomLoader,
|
290
|
+
JS.Package.ServerLoader ],
|
291
|
+
|
292
|
+
n = candidates.length,
|
293
|
+
i, candidate;
|
294
|
+
|
295
|
+
for (i = 0; i < n; i++) {
|
296
|
+
candidate = candidates[i];
|
297
|
+
if (candidate.usable()) {
|
298
|
+
JS.Package.Loader = candidate;
|
299
|
+
if (candidate.setup) candidate.setup();
|
300
|
+
break;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
})();
|
304
|
+
|
305
|
+
|
306
|
+
JS.Package.DSL = {
|
307
|
+
__FILE__: function() {
|
308
|
+
return JS.Package.Loader.__FILE__();
|
309
|
+
},
|
310
|
+
|
311
|
+
pkg: function(name, path) {
|
312
|
+
var pkg = path
|
313
|
+
? JS.Package.getByPath(path)
|
314
|
+
: JS.Package.getByName(name);
|
315
|
+
pkg.addName(name);
|
316
|
+
return new JS.Package.Description(pkg);
|
317
|
+
},
|
318
|
+
|
319
|
+
file: function(path) {
|
320
|
+
var pkg = JS.Package.getByPath(path);
|
321
|
+
return new JS.Package.Description(pkg);
|
322
|
+
},
|
323
|
+
|
324
|
+
load: function(path, fireCallbacks) {
|
325
|
+
JS.Package.Loader.loadFile(path, fireCallbacks);
|
326
|
+
}
|
327
|
+
};
|
328
|
+
|
329
|
+
JS.Package.Description = function(pkg) {
|
330
|
+
this._pkg = pkg;
|
331
|
+
};
|
332
|
+
|
333
|
+
(function(klass) {
|
334
|
+
|
335
|
+
klass._batch = function(method, args) {
|
336
|
+
var n = args.length, method = this._pkg[method], i;
|
337
|
+
for (i = 0; i < n; i++) method.call(this._pkg, args[i]);
|
338
|
+
return this;
|
339
|
+
};
|
340
|
+
|
341
|
+
klass.provides = function() {
|
342
|
+
return this._batch('addName', arguments);
|
343
|
+
};
|
344
|
+
|
345
|
+
klass.requires = function() {
|
346
|
+
return this._batch('addDependency', arguments);
|
347
|
+
};
|
348
|
+
|
349
|
+
klass.uses = function() {
|
350
|
+
return this._batch('addSoftDependency', arguments);
|
351
|
+
};
|
352
|
+
|
353
|
+
klass.setup = function(block) {
|
354
|
+
this._pkg.onload(block);
|
355
|
+
return this;
|
356
|
+
};
|
357
|
+
|
358
|
+
})(JS.Package.Description.prototype);
|
359
|
+
|
360
|
+
JS.Package.DSL.loader = JS.Package.DSL.file;
|
361
|
+
|
362
|
+
JS.Packages = function(declaration) {
|
363
|
+
declaration.call(JS.Package.DSL);
|
364
|
+
};
|
365
|
+
|
366
|
+
JS.require = function() {
|
367
|
+
var requirements = [], i = 0;
|
368
|
+
|
369
|
+
while (typeof arguments[i] === 'string'){
|
370
|
+
requirements.push(arguments[i]);
|
371
|
+
i += 1;
|
372
|
+
}
|
373
|
+
|
374
|
+
JS.Package.when({complete: requirements}, arguments[i], arguments[i+1]);
|
375
|
+
};
|
376
|
+
|
377
|
+
require = JS.require;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
if (JS.Proxy === undefined) JS.Proxy = {};
|
2
|
+
|
3
|
+
JS.Proxy.Virtual = new JS.Class('Proxy.Virtual', {
|
4
|
+
initialize: function(klass) {
|
5
|
+
var bridge = function() {},
|
6
|
+
proxy = new JS.Class(),
|
7
|
+
delegators = {},
|
8
|
+
method, func;
|
9
|
+
|
10
|
+
bridge.prototype = klass.prototype;
|
11
|
+
|
12
|
+
for (method in klass.prototype) {
|
13
|
+
func = klass.prototype[method];
|
14
|
+
if (JS.isFn(func) && func !== klass) func = this.klass.forward(method);
|
15
|
+
delegators[method] = func;
|
16
|
+
}
|
17
|
+
|
18
|
+
proxy.include({
|
19
|
+
initialize: function() {
|
20
|
+
var args = arguments,
|
21
|
+
subject = null;
|
22
|
+
|
23
|
+
this.__getSubject__ = function() {
|
24
|
+
subject = new bridge;
|
25
|
+
klass.apply(subject, args);
|
26
|
+
return (this.__getSubject__ = function() { return subject; })();
|
27
|
+
};
|
28
|
+
},
|
29
|
+
klass: klass,
|
30
|
+
constructor: klass
|
31
|
+
}, false);
|
32
|
+
|
33
|
+
proxy.include(new JS.Module(delegators), false);
|
34
|
+
proxy.include(this.klass.InstanceMethods, true);
|
35
|
+
return proxy;
|
36
|
+
},
|
37
|
+
|
38
|
+
extend: {
|
39
|
+
forward: function(name) {
|
40
|
+
return function() {
|
41
|
+
var subject = this.__getSubject__();
|
42
|
+
return subject[name].apply(subject, arguments);
|
43
|
+
};
|
44
|
+
},
|
45
|
+
|
46
|
+
InstanceMethods: new JS.Module({
|
47
|
+
extend: function(source) {
|
48
|
+
this.__getSubject__().extend(source);
|
49
|
+
var method, func;
|
50
|
+
for (method in source) {
|
51
|
+
func = source[method];
|
52
|
+
if (JS.isFn(func)) func = JS.Proxy.Virtual.forward(method);
|
53
|
+
this[method] = func;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
})
|
57
|
+
}
|
58
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
JS.Ruby = function(klass, define) {
|
2
|
+
define.call(new JS.Ruby.ClassBuilder(klass));
|
3
|
+
};
|
4
|
+
|
5
|
+
JS.extend(JS.Ruby, {
|
6
|
+
extendDSL: function(builder, source) {
|
7
|
+
for (var method in source) {
|
8
|
+
if (builder[method] || !JS.isFn(source[method])) continue;
|
9
|
+
this.addMethod(builder, source, method);
|
10
|
+
}
|
11
|
+
},
|
12
|
+
|
13
|
+
addMethod: function(builder, source, method) {
|
14
|
+
builder[method] = function() {
|
15
|
+
var result = source[method].apply(source, arguments);
|
16
|
+
JS.Ruby.extendDSL(builder, source);
|
17
|
+
return result;
|
18
|
+
};
|
19
|
+
},
|
20
|
+
|
21
|
+
alias: function(object, builder) {
|
22
|
+
return function(newName, oldName) {
|
23
|
+
var old = object[oldName];
|
24
|
+
if (old !== undefined) this.def(newName, old);
|
25
|
+
if (builder) JS.Ruby.extendDSL(builder, object);
|
26
|
+
};
|
27
|
+
},
|
28
|
+
|
29
|
+
ClassBuilder: function(klass) {
|
30
|
+
this.def = klass.method('define');
|
31
|
+
this.alias = JS.Ruby.alias(klass.prototype);
|
32
|
+
|
33
|
+
this.self = {
|
34
|
+
def: JS.bind(function(name, method) {
|
35
|
+
var def = {}; def[name] = method;
|
36
|
+
klass.extend(def);
|
37
|
+
JS.Ruby.extendDSL(this, klass);
|
38
|
+
}, this),
|
39
|
+
alias: JS.Ruby.alias(klass, this)
|
40
|
+
};
|
41
|
+
|
42
|
+
JS.Ruby.extendDSL(this, klass);
|
43
|
+
}
|
44
|
+
});
|