coolerator.vision 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,466 @@
1
+ function module(name, definition) {
2
+ var current_constructor;
3
+
4
+ if (!window[name]) {
5
+ window[name] = {};
6
+ }
7
+ var module_stack = [window[name]];
8
+
9
+ function current_module() {
10
+ return module_stack[module_stack.length -1];
11
+ }
12
+
13
+ function push_module(name) {
14
+ if (!current_module()[name]) {
15
+ current_module()[name] = {};
16
+ }
17
+ var module = current_module()[name];
18
+ module_stack.push(module);
19
+ return module;
20
+ }
21
+
22
+ function pop_module() {
23
+ module_stack.pop();
24
+ }
25
+
26
+ var keywords = {
27
+ module: function(name, definition) {
28
+ var module = push_module(name);
29
+ definition.call(module);
30
+ pop_module();
31
+ },
32
+
33
+ constructor: function(name, definition) {
34
+ current_constructor = function() {
35
+ if (this.initialize) {
36
+ this.initialize.apply(this, arguments);
37
+ }
38
+ };
39
+ definition.call(current_constructor);
40
+ current_module()[name] = current_constructor;
41
+ current_constructor = undefined;
42
+ },
43
+
44
+ include: function(mixin) {
45
+ for (var slot_name in mixin) {
46
+ current_constructor.prototype[slot_name] = mixin[slot_name];
47
+ }
48
+ },
49
+
50
+ def: function(name, fn) {
51
+ if(current_constructor) {
52
+ current_constructor.prototype[name] = fn;
53
+ } else {
54
+ current_module()[name] = fn;
55
+ }
56
+ }
57
+ }
58
+
59
+ definition.call(current_module(), keywords);
60
+ }
61
+
62
+ function throw_june_unimplemented(object, method){
63
+ throw new Error("June.UnimplementedException: '" + method + "' was not implemented by: " + object);
64
+ }
65
+
66
+ module("Prez", function(c) { with(c) {
67
+ constructor("Builder", function() {
68
+
69
+ var supported_tags = [
70
+ 'a', 'acronym', 'address', 'area', 'b', 'base', 'bdo', 'big', 'blockquote', 'body',
71
+ 'br', 'button', 'caption', 'cite', 'code', 'dd', 'del', 'div', 'dl', 'dt', 'em',
72
+ 'fieldset', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i',
73
+ 'img', 'iframe', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'map',
74
+ 'meta', 'noframes', 'noscript', 'ol', 'optgroup', 'option', 'p', 'param', 'pre',
75
+ 'samp', 'script', 'select', 'small', 'span', 'strong', 'style', 'sub', 'sup',
76
+ 'table', 'tbody', 'td', 'textarea', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var'
77
+ ];
78
+
79
+ var event_types = [
80
+ "blur", "change", "click", "dblclick", "error", "focus", "keydown", "keypress",
81
+ "keyup", "load", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup",
82
+ "resize", "scroll", "select", "submit", "unload"
83
+ ];
84
+
85
+
86
+ function generate_tag_method(tag_name) {
87
+ def(tag_name, function() {
88
+ return this.tag_with_array_args(tag_name, arguments);
89
+ });
90
+ }
91
+
92
+ function generate_event_handler_method(event_type) {
93
+ def(event_type, function(fn) {
94
+ this.doc.push(new Prez.PostProcessorInstruction('bind', [event_type, null, fn]));
95
+ });
96
+ }
97
+
98
+ jQuery.each(supported_tags, function() {
99
+ generate_tag_method(this);
100
+ });
101
+
102
+ jQuery.each(event_types, function() {
103
+ generate_event_handler_method(this);
104
+ });
105
+
106
+
107
+ def("initialize", function() {
108
+ this.doc = [];
109
+ });
110
+
111
+ def("tag", function() {
112
+ if(arguments.length > 3) {
113
+ throw("XmlBulider#tag does not accept more than three arguments");
114
+ }
115
+ var tag_name, attributes, value;
116
+ tag_name = arguments[0];
117
+
118
+ var arg1 = arguments[1];
119
+ if(typeof arg1 == 'object') {
120
+ attributes = arg1;
121
+ var arg2 = arguments[2];
122
+ if(typeof arg2 == 'function' || typeof arg2 == 'string'){
123
+ value = arg2;
124
+ };
125
+ } else if(typeof arg1 == 'function' || typeof arg1 == 'string'){
126
+ value = arg1;
127
+ var arg2 = arguments[2];
128
+ if(typeof arg2 == 'object') {
129
+ attributes = arg2;
130
+ }
131
+ };
132
+
133
+ if (this.is_self_closing(tag_name)) {
134
+ this.doc.push(new Prez.SelfClosingTag(tag_name, attributes));
135
+ } else {
136
+ this.doc.push(new Prez.OpenTag(tag_name, attributes));
137
+ if(typeof value == 'function') {
138
+ value.call(this);
139
+ } else if(typeof value == 'string') {
140
+ this.doc.push(new Prez.Text(value));
141
+ }
142
+ this.doc.push(new Prez.CloseTag(tag_name));
143
+ }
144
+
145
+ return this;
146
+ });
147
+
148
+ def("self_closing_tag_hash", { 'br': 1, 'hr': 1, 'input': 1, 'img': 1 });
149
+
150
+ def("is_self_closing", function(tag_name){
151
+ return this.self_closing_tag_hash[tag_name];
152
+ });
153
+
154
+ def("tag_with_array_args", function(tag, args) {
155
+ if(!args) return this.tag(tag);
156
+
157
+ var new_arguments = [tag];
158
+ for(var i=0; i < args.length; i++) {
159
+ new_arguments.push(args[i]);
160
+ }
161
+ return this.tag.apply(this, new_arguments);
162
+ });
163
+
164
+ def("rawtext", function(value) {
165
+ this.doc.push(new Prez.Text(value));
166
+ });
167
+
168
+ def("text", function(value) {
169
+ var html = this.escape_html(value);
170
+ this.doc.push(new Prez.Text(html));
171
+ });
172
+
173
+ def("escape_html", function(html) {
174
+ return html.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;")
175
+ });
176
+
177
+ def("subview", function(name, template, initial_attributes) {
178
+ this.doc.push(new Prez.PostProcessorInstruction('open_subview', [name]))
179
+ template.content(this, initial_attributes);
180
+ this.doc.push(new Prez.PostProcessorInstruction('close_view', [template, initial_attributes]))
181
+ });
182
+
183
+ def("keyed_subview", function(name, key, template, initial_attributes) {
184
+ this.doc.push(new Prez.PostProcessorInstruction('open_subview', [name, key]))
185
+ template.content(this, initial_attributes);
186
+ this.doc.push(new Prez.PostProcessorInstruction('close_view', [template, initial_attributes]))
187
+ });
188
+
189
+ def("bind", function() {
190
+ var type = arguments[0];
191
+ if (arguments.length > 2) {
192
+ var data = arguments[1];
193
+ var fn = arguments[2];
194
+ } else {
195
+ var data = null;
196
+ var fn = arguments[1];
197
+ }
198
+
199
+ this.doc.push(new Prez.PostProcessorInstruction('bind', [type, data, fn]));
200
+ });
201
+
202
+ def("to_string", function() {
203
+ var output = "";
204
+ for(var i=0; i < this.doc.length; i++) {
205
+ var element = this.doc[i];
206
+ output += element.to_string();
207
+ }
208
+ return output;
209
+ });
210
+
211
+ def("to_view", function(template, initial_attributes) {
212
+ var string = this.to_string();
213
+ if (string == "") return "";
214
+ var post_processor = new Prez.PostProcessor($(string));
215
+ for(var i=0; i < this.doc.length; i++) {
216
+ var element = this.doc[i];
217
+ element.post_process(post_processor);
218
+ }
219
+ post_processor.close_view(template, initial_attributes);
220
+ return post_processor.root_view;
221
+ });
222
+ });
223
+ }});
224
+ module("Prez", function(c) { with(c) {
225
+ constructor("PostProcessor", function() {
226
+ def("initialize", function(root_view) {
227
+ this.root_view = root_view;
228
+ this.view_stack = [root_view];
229
+ this.selector_stack = [0];
230
+ });
231
+
232
+ def("push", function() {
233
+ this.add_child();
234
+ this.selector_stack.push(0);
235
+ });
236
+
237
+ def("add_child", function() {
238
+ if (!this.selector_stack.length == 0) {
239
+ this.selector_stack[this.selector_stack.length - 1]++;
240
+ }
241
+ });
242
+
243
+ def("pop", function() {
244
+ this.selector_stack.pop();
245
+ });
246
+
247
+ def("open_subview", function(name, key) {
248
+ var view = this.next_element();
249
+ var current_view = this.current_view();
250
+ if (!key) {
251
+ current_view[name] = view;
252
+ } else {
253
+ if (!current_view[name]) {
254
+ current_view[name] = {};
255
+ }
256
+ current_view[name][key] = view;
257
+ }
258
+ view.parent = current_view;
259
+ this.view_stack.push(view);
260
+ });
261
+
262
+ def("close_view", function(template, initial_attributes) {
263
+ var current_view = this.current_view();
264
+ if (template && template.methods) {
265
+ $.extend(current_view, template.methods);
266
+ }
267
+ if (template && template.configuration) {
268
+ current_view.configuration = template.configuration;
269
+ }
270
+ if (initial_attributes) {
271
+ $.extend(current_view, initial_attributes);
272
+ }
273
+ if (current_view.initialize) {
274
+ current_view.initialize();
275
+ }
276
+ this.view_stack.pop();
277
+ });
278
+
279
+ def("bind", function(type, data, fn) {
280
+ var view = this.current_view();
281
+ this.previous_element().bind(type, data, function(event) {
282
+ fn(event, view);
283
+ });
284
+ });
285
+
286
+ def("next_element", function() {
287
+ return this.find_element(this.next_selector());
288
+ });
289
+
290
+ def("previous_element", function() {
291
+ if(this.selector_stack.length == 1) {
292
+ if (this.root_view.length == 1) {
293
+ return this.root_view;
294
+ } else {
295
+ return this.root_view.eq(this.num_root_children() - 1);
296
+ }
297
+ } else {
298
+ return this.find_element(this.previous_selector());
299
+ }
300
+ });
301
+
302
+ def("find_element", function(selector) {
303
+ if(this.root_view.length == 1) {
304
+ return this.root_view.find(selector);
305
+ } else {
306
+ return this.root_view.eq(this.num_root_children() - 1).find(selector);
307
+ }
308
+ });
309
+
310
+ def("num_root_children", function() {
311
+ return this.selector_stack[0];
312
+ });
313
+
314
+ def("next_selector", function() {
315
+ return this.selector(true)
316
+ });
317
+
318
+ def("previous_selector", function() {
319
+ return this.selector(false)
320
+ });
321
+
322
+ def("selector", function(next) {
323
+ var selectors = [];
324
+ for(var i = 1; i < this.selector_stack.length; i++) {
325
+ if (i == this.selector_stack.length - 1) {
326
+ var index = next ? this.selector_stack[i] + 1 : this.selector_stack[i];
327
+ selectors.push(":nth-child(" + index + ")")
328
+ } else {
329
+ selectors.push(":nth-child(" + this.selector_stack[i] + ")")
330
+ }
331
+ }
332
+ return "> " + selectors.join(" > ");
333
+ });
334
+
335
+ def("current_view", function() {
336
+ return this.view_stack[this.view_stack.length - 1];
337
+ });
338
+ });
339
+ }});
340
+ module("Prez", function(c) { with(c) {
341
+ constructor("OpenTag", function() {
342
+ def("initialize", function(tag_name, attributes) {
343
+ this.tag_name = tag_name;
344
+ this.attributes = attributes;
345
+ });
346
+
347
+ def("to_string", function() {
348
+ var serialized_attributes = [];
349
+ for(var attributeName in this.attributes) {
350
+ serialized_attributes.push(attributeName + '="' + this.attributes[attributeName] + '"');
351
+ }
352
+ if(serialized_attributes.length > 0) {
353
+ return "<" + this.tag_name + " " + serialized_attributes.join(" ") + ">";
354
+ } else {
355
+ return "<" + this.tag_name + ">";
356
+ }
357
+ })
358
+
359
+ def("post_process", function(processor) {
360
+ processor.push();
361
+ });
362
+ });
363
+ }});
364
+ module("Prez", function(c) { with(c) {
365
+ constructor("CloseTag", function() {
366
+ def("initialize", function(tag_name) {
367
+ this.tag_name = tag_name;
368
+ });
369
+
370
+ def("to_string", function() {
371
+ return "</" + this.tag_name + ">";
372
+ });
373
+
374
+ def("post_process", function(processor) {
375
+ processor.pop();
376
+ });
377
+ });
378
+ }});
379
+ module("Prez", function(c) { with(c) {
380
+ constructor("SelfClosingTag", function() {
381
+ def("initialize", function(tag_name, attributes) {
382
+ this.tag_name = tag_name;
383
+ this.attributes = attributes;
384
+ });
385
+
386
+ def('to_string', function() {
387
+ var serialized_attributes = [];
388
+ for(var attributeName in this.attributes) {
389
+ serialized_attributes.push(attributeName + '="' + this.attributes[attributeName] + '"');
390
+ }
391
+ if(serialized_attributes.length > 0) {
392
+ return "<" + this.tag_name + " " + serialized_attributes.join(" ") + " />";
393
+ } else {
394
+ return "<" + this.tag_name + " />";
395
+ }
396
+ });
397
+
398
+ def('post_process', function(processor) {
399
+ processor.push(); // we increase the parent's number of children
400
+ processor.pop(); // but then remove this child -- it can have no children itself. Parent's child count remains incremented.
401
+ });
402
+ });
403
+ }});
404
+ module("Prez", function(c) { with(c) {
405
+ constructor("Text", function() {
406
+ def("initialize", function(value) {
407
+ this.value = value;
408
+ });
409
+
410
+
411
+ def("to_string", function() {
412
+ return this.value;
413
+ });
414
+
415
+ def("post_process", function(processor) {
416
+ });
417
+ });
418
+ }});
419
+ module("Prez", function(c) { with(c) {
420
+ constructor("PostProcessorInstruction", function() {
421
+ def("initialize", function(function_name, arguments) {
422
+ this.function_name = function_name;
423
+ this.arguments = arguments;
424
+ });
425
+
426
+ def("to_string", function() {
427
+ return "";
428
+ });
429
+
430
+ def("post_process", function(processor) {
431
+ processor[this.function_name].apply(processor, this.arguments);
432
+ });
433
+ });
434
+ }});
435
+
436
+ module("Prez", function(c) { with(c) {
437
+ def("build", function(fn_or_template, initial_attributes) {
438
+ var builder = new Prez.Builder();
439
+
440
+ if (fn_or_template instanceof Function) {
441
+ fn_or_template(builder, initial_attributes);
442
+ } else {
443
+ fn_or_template.content(builder, initial_attributes);
444
+ }
445
+
446
+ return builder.to_view(fn_or_template, initial_attributes);
447
+ });
448
+
449
+ def("inherit", function(layout, template) {
450
+ var merged_template = $.extend(true, {}, layout, template);
451
+
452
+ merged_template.methods = merged_template.methods || {};
453
+
454
+ merged_template.methods.initialize = function() {
455
+ if(layout.methods && layout.methods.initialize) {
456
+ layout.methods.initialize.call(this);
457
+ }
458
+ if(template.methods && template.methods.initialize) {
459
+ template.methods.initialize.call(this);
460
+ }
461
+ };
462
+
463
+ return merged_template;
464
+ });
465
+ }});
466
+