yhara-ticketmap 0.3.1
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.
- data/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/MANIFEST +29 -0
- data/README.rdoc +20 -0
- data/Rakefile +52 -0
- data/TODO +82 -0
- data/VERSION +1 -0
- data/controller/config.rb +9 -0
- data/controller/init.rb +7 -0
- data/controller/main.rb +11 -0
- data/controller/tickets.rb +49 -0
- data/db/migrate/001_create_tickets.rb +14 -0
- data/db/migrate/002_add_deleted_to_tickets.rb +13 -0
- data/db/migrate/003_add_timeouted_to_tickets.rb +13 -0
- data/main.rb +40 -0
- data/model/init.rb +32 -0
- data/model/ticket.rb +49 -0
- data/public/biwascheme/lib/biwascheme.js +106 -0
- data/public/biwascheme/lib/dumper.js +192 -0
- data/public/biwascheme/lib/extra_lib.js +534 -0
- data/public/biwascheme/lib/io.js +326 -0
- data/public/biwascheme/lib/prototype.js +4320 -0
- data/public/biwascheme/lib/r6rs_lib.js +2439 -0
- data/public/biwascheme/lib/stackbase.js +1697 -0
- data/public/biwascheme/lib/webscheme_lib.js +809 -0
- data/public/js/builder.js +136 -0
- data/public/js/controls.js +965 -0
- data/public/js/dragdrop.js +975 -0
- data/public/js/effects.js +1130 -0
- data/public/js/scriptaculous.js +60 -0
- data/public/js/slider.js +275 -0
- data/public/js/sound.js +55 -0
- data/public/js/unittest.js +568 -0
- data/public/scm/board.scm +23 -0
- data/public/scm/hand.scm +48 -0
- data/public/scm/main.scm +69 -0
- data/public/scm/server.scm +30 -0
- data/public/scm/ticket.scm +44 -0
- data/spec/config.rb +13 -0
- data/spec/helper.rb +2 -0
- data/spec/main.rb +13 -0
- data/spec/models.rb +34 -0
- data/spec/tickets.rb +65 -0
- data/ticketmap.gemspec +96 -0
- data/view/index.xhtml +63 -0
- data/view/track.xhtml +29 -0
- metadata +131 -0
@@ -0,0 +1,809 @@
|
|
1
|
+
|
2
|
+
if( typeof(BiwaScheme)!='object' ) BiwaScheme={}; with(BiwaScheme) {
|
3
|
+
define_libfunc("read-line", 0, 1, function(ar){
|
4
|
+
var port = ar[0] || Port.current_input;
|
5
|
+
assert_port(port);
|
6
|
+
return port.get_string();
|
7
|
+
});
|
8
|
+
|
9
|
+
//
|
10
|
+
// element
|
11
|
+
//
|
12
|
+
define_libfunc("element-clear!", 1, 1, function(ar){
|
13
|
+
return $(ar[0]).update();
|
14
|
+
});
|
15
|
+
define_libfunc("element-empty!", 1, 1, function(ar){
|
16
|
+
return $(ar[0]).update();
|
17
|
+
});
|
18
|
+
|
19
|
+
define_libfunc("element-visible?", 1, 1, function(ar){
|
20
|
+
return $(ar[0]).visible();
|
21
|
+
});
|
22
|
+
define_libfunc("element-toggle!", 1, 1, function(ar){
|
23
|
+
return $(ar[0]).toggle();
|
24
|
+
})
|
25
|
+
define_libfunc("element-hide!", 1, 1, function(ar){
|
26
|
+
return $(ar[0]).hide();
|
27
|
+
})
|
28
|
+
define_libfunc("element-show!", 1, 1, function(ar){
|
29
|
+
return $(ar[0]).show();
|
30
|
+
})
|
31
|
+
define_libfunc("element-remove!", 1, 1, function(ar){
|
32
|
+
return $(ar[0]).remove("");
|
33
|
+
})
|
34
|
+
define_libfunc("element-update!", 2, 2, function(ar){
|
35
|
+
return $(ar[0]).update(ar[1]);
|
36
|
+
})
|
37
|
+
define_libfunc("element-replace!", 2, 2, function(ar){
|
38
|
+
return $(ar[0]).replace(ar[1]);
|
39
|
+
});
|
40
|
+
define_libfunc("element-insert!", 2, 2, function(ar){
|
41
|
+
return $(ar[0]).insert(ar[1]);
|
42
|
+
});
|
43
|
+
define_libfunc("element-wrap!", 3, 3, function(ar){
|
44
|
+
throw new Bug("not yet implemented");
|
45
|
+
});
|
46
|
+
define_libfunc("element-ancestors", 1, 1, function(ar){
|
47
|
+
throw new Bug("not yet implemented");
|
48
|
+
});
|
49
|
+
define_libfunc("element-descendants", 1, 1, function(ar){
|
50
|
+
throw new Bug("not yet implemented");
|
51
|
+
});
|
52
|
+
define_libfunc("element-first-descendant", 1, 1, function(ar){
|
53
|
+
throw new Bug("not yet implemented");
|
54
|
+
});
|
55
|
+
define_libfunc("element-immediate-descendants", 1, 1, function(ar){
|
56
|
+
throw new Bug("not yet implemented");
|
57
|
+
});
|
58
|
+
define_libfunc("element-previous-sibling", 1, 1, function(ar){
|
59
|
+
throw new Bug("not yet implemented");
|
60
|
+
});
|
61
|
+
define_libfunc("element-next-sibling", 1, 1, function(ar){
|
62
|
+
throw new Bug("not yet implemented");
|
63
|
+
});
|
64
|
+
define_libfunc("element-siblings", 1, 1, function(ar){
|
65
|
+
throw new Bug("not yet implemented");
|
66
|
+
});
|
67
|
+
define_libfunc("element-match?", 2, 2, function(ar){
|
68
|
+
throw new Bug("not yet implemented");
|
69
|
+
});
|
70
|
+
define_libfunc("element-up", 3, 3, function(ar){
|
71
|
+
throw new Bug("not yet implemented");
|
72
|
+
});
|
73
|
+
define_libfunc("element-down", 3, 3, function(ar){
|
74
|
+
throw new Bug("not yet implemented");
|
75
|
+
});
|
76
|
+
define_libfunc("element-previous", 3, 3, function(ar){
|
77
|
+
throw new Bug("not yet implemented");
|
78
|
+
});
|
79
|
+
define_libfunc("element-next", 3, 3, function(ar){
|
80
|
+
throw new Bug("not yet implemented");
|
81
|
+
});
|
82
|
+
define_libfunc("element-select", 0, 0, function(ar){
|
83
|
+
throw new Bug("not yet implemented");
|
84
|
+
});
|
85
|
+
define_libfunc("element-adjacent", 0, 0, function(ar){
|
86
|
+
throw new Bug("not yet implemented");
|
87
|
+
});
|
88
|
+
define_libfunc("element-identify", 1, 1, function(ar){
|
89
|
+
throw new Bug("not yet implemented");
|
90
|
+
});
|
91
|
+
define_libfunc("element-read-attribute", 2, 2, function(ar){
|
92
|
+
assert_string(ar[1]);
|
93
|
+
return $(ar[0]).readAttribute(ar[1]);
|
94
|
+
});
|
95
|
+
define_libfunc("element-write-attribute", 3, 3, function(ar){
|
96
|
+
assert_string(ar[1]);
|
97
|
+
return $(ar[0]).readAttribute(ar[1], ar[2]);
|
98
|
+
});
|
99
|
+
define_libfunc("element-height", 1, 1, function(ar){
|
100
|
+
return $(ar[0]).getHeight();
|
101
|
+
});
|
102
|
+
define_libfunc("element-width", 1, 1, function(ar){
|
103
|
+
return $(ar[0]).getWidth();
|
104
|
+
});
|
105
|
+
define_libfunc("element-class-names", 1, 1, function(ar){
|
106
|
+
throw new Bug("not yet implemented");
|
107
|
+
});
|
108
|
+
define_libfunc("element-has-class-name?", 2, 2, function(ar){
|
109
|
+
throw new Bug("not yet implemented");
|
110
|
+
});
|
111
|
+
define_libfunc("element-add-class-name", 2, 2, function(ar){
|
112
|
+
throw new Bug("not yet implemented");
|
113
|
+
});
|
114
|
+
define_libfunc("element-remove-class-name", 2, 2, function(ar){
|
115
|
+
throw new Bug("not yet implemented");
|
116
|
+
});
|
117
|
+
define_libfunc("element-toggle-class-name", 2, 2, function(ar){
|
118
|
+
throw new Bug("not yet implemented");
|
119
|
+
});
|
120
|
+
define_libfunc("element-clean-whitespace!", 1, 1, function(ar){
|
121
|
+
throw new Bug("not yet implemented");
|
122
|
+
});
|
123
|
+
define_libfunc("element-empty?", 1, 1, function(ar){
|
124
|
+
throw new Bug("not yet implemented");
|
125
|
+
})
|
126
|
+
define_libfunc("element-descendant-of!", 2, 2, function(ar){
|
127
|
+
throw new Bug("not yet implemented");
|
128
|
+
})
|
129
|
+
define_libfunc("scroll-to-element!", 1, 1, function(ar){
|
130
|
+
throw new Bug("not yet implemented");
|
131
|
+
})
|
132
|
+
define_libfunc("element-style", 2, 2, function(ar){
|
133
|
+
throw new Bug("not yet implemented");
|
134
|
+
})
|
135
|
+
define_libfunc("element-opacity", 2, 2, function(ar){
|
136
|
+
throw new Bug("not yet implemented");
|
137
|
+
})
|
138
|
+
define_libfunc("element-style-set!", 2, 2, function(ar){
|
139
|
+
throw new Bug("not yet implemented");
|
140
|
+
})
|
141
|
+
define_libfunc("element-opacity-set!", 2, 2, function(ar){
|
142
|
+
throw new Bug("not yet implemented");
|
143
|
+
})
|
144
|
+
define_libfunc("element-dimensions", 1, 1, function(ar){
|
145
|
+
var dimensions = $(ar[0]).getDimensions();
|
146
|
+
return new Values(dimensions.width, dimensions.height);
|
147
|
+
})
|
148
|
+
define_libfunc("element-make-positioned!", 1, 1, function(ar){
|
149
|
+
throw new Bug("not yet implemented");
|
150
|
+
})
|
151
|
+
define_libfunc("element-undo-positioned!", 1, 1, function(ar){
|
152
|
+
throw new Bug("not yet implemented");
|
153
|
+
})
|
154
|
+
define_libfunc("element-make-clipping!", 1, 1, function(ar){
|
155
|
+
throw new Bug("not yet implemented");
|
156
|
+
})
|
157
|
+
define_libfunc("element-undo-clipping!", 1, 1, function(ar){
|
158
|
+
throw new Bug("not yet implemented");
|
159
|
+
})
|
160
|
+
define_libfunc("element-cumulative-offset", 1, 1, function(ar){
|
161
|
+
throw new Bug("not yet implemented");
|
162
|
+
})
|
163
|
+
define_libfunc("element-positioned-offset", 1, 1, function(ar){
|
164
|
+
throw new Bug("not yet implemented");
|
165
|
+
})
|
166
|
+
define_libfunc("element-absolutize!", 1, 1, function(ar){
|
167
|
+
throw new Bug("not yet implemented");
|
168
|
+
})
|
169
|
+
define_libfunc("element-relativize!", 1, 1, function(ar){
|
170
|
+
throw new Bug("not yet implemented");
|
171
|
+
})
|
172
|
+
define_libfunc("element-cumulative-scroll-offset", 1, 1, function(ar){
|
173
|
+
throw new Bug("not yet implemented");
|
174
|
+
})
|
175
|
+
define_libfunc("element-offset-parent", 1, 1, function(ar){
|
176
|
+
throw new Bug("not yet implemented");
|
177
|
+
})
|
178
|
+
define_libfunc("element-viewport-offset", 1, 1, function(ar){
|
179
|
+
throw new Bug("not yet implemented");
|
180
|
+
})
|
181
|
+
define_libfunc("element-clone-position!", 1, 1, function(ar){
|
182
|
+
throw new Bug("not yet implemented");
|
183
|
+
})
|
184
|
+
define_libfunc("element-absolutize!", 1, 1, function(ar){
|
185
|
+
throw new Bug("not yet implemented");
|
186
|
+
})
|
187
|
+
|
188
|
+
// usage:
|
189
|
+
// (element-new '(div "foo")) => <div>foo</div>
|
190
|
+
// (element-new '("div#main" "foo")) => <div id='main'>foo</div>
|
191
|
+
// (element-new '("div.red" "foo")) => <div class='red'>foo</div>
|
192
|
+
// (element-new '(div align right)) => <div align='right'>foo</div>
|
193
|
+
// (element-new '(div (span "foo")) => <div><span>foo</span></div>
|
194
|
+
//
|
195
|
+
|
196
|
+
// This function is not used; slower than by_string
|
197
|
+
BiwaScheme.create_elements_by_dom = function(spec){
|
198
|
+
var create_element = function(name, attrs, children){
|
199
|
+
var tag = new Element(name, attrs); //attrs is an Object
|
200
|
+
children.each(function(child){
|
201
|
+
tag.insert({bottom: child});
|
202
|
+
});
|
203
|
+
return tag;
|
204
|
+
};
|
205
|
+
var spec = spec.to_array();
|
206
|
+
var name = spec[0].name || spec[0]; // Symbol or String
|
207
|
+
var attrs = {};
|
208
|
+
var children = [];
|
209
|
+
for(var i=1; i<spec.length; i++){
|
210
|
+
if(spec[i] instanceof Symbol){ //attribute
|
211
|
+
attrs[ spec[i].name ] = spec[i+1];
|
212
|
+
i++;
|
213
|
+
}
|
214
|
+
else{
|
215
|
+
if(spec[i] instanceof Pair)
|
216
|
+
children.push(create_elements_by_dom(spec[i]));
|
217
|
+
else
|
218
|
+
children.push(spec[i].toString());
|
219
|
+
}
|
220
|
+
}
|
221
|
+
return create_element(name, attrs, children);
|
222
|
+
};
|
223
|
+
|
224
|
+
BiwaScheme.create_elements_by_string = function(spec){
|
225
|
+
var spec = spec.to_array();
|
226
|
+
var name = spec.shift();
|
227
|
+
if(name instanceof Symbol) name = name.name;
|
228
|
+
if(name.match(/(.*)\.(.*)/)){
|
229
|
+
name = RegExp.$1;
|
230
|
+
spec.unshift(Sym("class"), RegExp.$2);
|
231
|
+
}
|
232
|
+
if(name.match(/(.*)\#(.*)/)){
|
233
|
+
name = RegExp.$1;
|
234
|
+
spec.unshift(Sym("id"), RegExp.$2);
|
235
|
+
}
|
236
|
+
var children = [];
|
237
|
+
var s = ["<" + name];
|
238
|
+
for(var i=0; i<spec.length; i++){
|
239
|
+
if(spec[i] instanceof Symbol){
|
240
|
+
s.push(' ' + spec[i].name + '="' + spec[i+1] + '"');
|
241
|
+
i++;
|
242
|
+
}
|
243
|
+
else{
|
244
|
+
if(spec[i] instanceof Pair)
|
245
|
+
children.push(create_elements_by_string(spec[i]));
|
246
|
+
else
|
247
|
+
children.push(spec[i]); // String
|
248
|
+
}
|
249
|
+
}
|
250
|
+
s.push(">");
|
251
|
+
s.push( children.join("") );
|
252
|
+
s.push("</" + name + ">");
|
253
|
+
return s.join("");
|
254
|
+
}
|
255
|
+
BiwaScheme.tree_all = function(tree, pred){
|
256
|
+
if(tree === nil)
|
257
|
+
return true;
|
258
|
+
else if(pred(tree.car) === false)
|
259
|
+
return false;
|
260
|
+
else
|
261
|
+
return BiwaScheme.tree_all(tree.cdr, pred);
|
262
|
+
}
|
263
|
+
define_libfunc("element-new", 1, 1, function(ar){
|
264
|
+
var string_or_symbol = function(item){
|
265
|
+
return Object.isString(item) ||
|
266
|
+
(item instanceof Symbol) ||
|
267
|
+
(item instanceof Pair);
|
268
|
+
};
|
269
|
+
if(BiwaScheme.tree_all(ar[0], string_or_symbol)){
|
270
|
+
var div = new Element("div");
|
271
|
+
div.update( create_elements_by_string(ar[0]) );
|
272
|
+
return div.firstChild;
|
273
|
+
}
|
274
|
+
else
|
275
|
+
return nil //create_elements_by_dom(ar[0]);
|
276
|
+
});
|
277
|
+
define_libfunc("element-content", 1, 1, function(ar){
|
278
|
+
return ar[0].value || (ar[0].innerHTML).unescapeHTML();
|
279
|
+
});
|
280
|
+
|
281
|
+
//
|
282
|
+
// load from network
|
283
|
+
//
|
284
|
+
define_libfunc("load", 1, 1, function(ar, intp){
|
285
|
+
var path = ar[0];
|
286
|
+
assert_string(path);
|
287
|
+
return new BiwaScheme.Pause(function(pause){
|
288
|
+
new Ajax.Request(path, {
|
289
|
+
method: 'get',
|
290
|
+
evalJSON: false,
|
291
|
+
evalJS: false,
|
292
|
+
onSuccess: function(transport) {
|
293
|
+
// create new interpreter not to destroy current stack.
|
294
|
+
var local_intp = new Interpreter(intp.on_error);
|
295
|
+
local_intp.evaluate(transport.responseText,
|
296
|
+
function(){
|
297
|
+
return pause.resume(BiwaScheme.undef);
|
298
|
+
});
|
299
|
+
},
|
300
|
+
onFailure: function(transport){
|
301
|
+
throw new Error("load: network error: failed to load"+path);
|
302
|
+
}
|
303
|
+
});
|
304
|
+
});
|
305
|
+
})
|
306
|
+
|
307
|
+
// (js-load "lib/foo.js" "Foo")
|
308
|
+
define_libfunc("js-load", 2, 2, function(ar){
|
309
|
+
var path = ar[0];
|
310
|
+
var check = ar[1];
|
311
|
+
assert_string(path);
|
312
|
+
assert_string(check);
|
313
|
+
|
314
|
+
return new BiwaScheme.Pause(function(pause){
|
315
|
+
BiwaScheme.require(path, "window." + check, function(){
|
316
|
+
pause.resume(BiwaScheme.undef);
|
317
|
+
});
|
318
|
+
});
|
319
|
+
});
|
320
|
+
|
321
|
+
//
|
322
|
+
// html modification
|
323
|
+
//
|
324
|
+
|
325
|
+
BiwaScheme.getelem = function(ar){
|
326
|
+
var x = $(ar[0]);
|
327
|
+
if (x===undefined || x===null)
|
328
|
+
return false;
|
329
|
+
else
|
330
|
+
return x;
|
331
|
+
};
|
332
|
+
define_libfunc("$", 1, 1, BiwaScheme.getelem);
|
333
|
+
define_libfunc("getelem", 1, 1, BiwaScheme.getelem);
|
334
|
+
|
335
|
+
define_libfunc("set-style!", 3, 3, function(ar){
|
336
|
+
assert_string(ar[1]);
|
337
|
+
ar[0].style[ar[1]] = ar[2];
|
338
|
+
return BiwaScheme.undef;
|
339
|
+
});
|
340
|
+
define_libfunc("get-style", 2, 2, function(ar){
|
341
|
+
assert_string(ar[1]);
|
342
|
+
return ar[0].style[ar[1]];
|
343
|
+
});
|
344
|
+
define_libfunc("set-content!", 2, 2, function(ar){
|
345
|
+
assert_string(ar[1]);
|
346
|
+
var str = ar[1].replace(/\n/g,"<br>").replace(/\t/g," ");
|
347
|
+
ar[0].innerHTML = str;
|
348
|
+
return BiwaScheme.undef;
|
349
|
+
});
|
350
|
+
define_libfunc("get-content", 1, 1, function(ar){
|
351
|
+
return ar[0].value || (ar[0].innerHTML).unescapeHTML();
|
352
|
+
});
|
353
|
+
|
354
|
+
//
|
355
|
+
// timer, sleep, handlers
|
356
|
+
//
|
357
|
+
define_libfunc("timer", 2, 2, function(ar, intp){
|
358
|
+
var proc = ar[0], msec = ar[1];
|
359
|
+
setTimeout(function(){ (new Interpreter(intp.on_error)).invoke_closure(proc) }, msec);
|
360
|
+
return BiwaScheme.undef;
|
361
|
+
})
|
362
|
+
define_libfunc("set-timer!", 2, 2, function(ar, intp){
|
363
|
+
var proc = ar[0], msec = ar[1];
|
364
|
+
return setInterval(function(){ (new Interpreter(intp.on_error)).invoke_closure(proc) }, msec);
|
365
|
+
})
|
366
|
+
define_libfunc("clear-timer!", 1, 1, function(ar){
|
367
|
+
var timer_id = ar[0];
|
368
|
+
clearInterval(timer_id);
|
369
|
+
return BiwaScheme.undef;
|
370
|
+
})
|
371
|
+
|
372
|
+
define_libfunc("sleep", 1, 1, function(ar){
|
373
|
+
var msec = ar[0];
|
374
|
+
return new BiwaScheme.Pause(function(pause){
|
375
|
+
setTimeout(function(){ pause.resume(nil) }, msec);
|
376
|
+
});
|
377
|
+
});
|
378
|
+
|
379
|
+
define_libfunc("set-handler!", 3, 3, function(ar, intp){
|
380
|
+
throw new Error("set-handler! is obsolete, please use add-handler! instead");
|
381
|
+
})
|
382
|
+
define_libfunc("add-handler!", 3, 3, function(ar, intp){
|
383
|
+
var elem = ar[0], evtype = ar[1], proc = ar[2];
|
384
|
+
var on_error = intp.on_error;
|
385
|
+
Event.observe(elem, evtype, function(event){
|
386
|
+
var intp = new Interpreter(on_error);
|
387
|
+
intp.invoke_closure(proc, [event||Window.event]);
|
388
|
+
});
|
389
|
+
return BiwaScheme.undef;
|
390
|
+
})
|
391
|
+
define_libfunc("wait-for", 2, 2, function(ar){
|
392
|
+
var elem = ar[0], evtype = ar[1];
|
393
|
+
elem.biwascheme_wait_for = elem.biwascheme_wait_for || {};
|
394
|
+
|
395
|
+
var prev_handler = elem.biwascheme_wait_for[evtype];
|
396
|
+
if (prev_handler) {
|
397
|
+
// Maybe a wait-for is called more than once,
|
398
|
+
// and previous handler is not consumed.
|
399
|
+
Event.stopObserving(elem, evtype, prev_handler);
|
400
|
+
}
|
401
|
+
|
402
|
+
return new BiwaScheme.Pause(function(pause){
|
403
|
+
var handler = function(event){
|
404
|
+
elem.biwascheme_wait_for[evtype] = undefined;
|
405
|
+
Event.stopObserving(elem, evtype, handler);
|
406
|
+
return pause.resume(BiwaScheme.undef);
|
407
|
+
};
|
408
|
+
|
409
|
+
elem.biwascheme_wait_for[evtype] = handler;
|
410
|
+
Event.observe(elem, evtype, handler);
|
411
|
+
});
|
412
|
+
});
|
413
|
+
|
414
|
+
//
|
415
|
+
// dom
|
416
|
+
//
|
417
|
+
define_libfunc("domelem", 1, null, function(ar){
|
418
|
+
throw new Error("obsolete");
|
419
|
+
});
|
420
|
+
define_libfunc("dom-remove-children!", 1, 1, function(ar){
|
421
|
+
puts("warning: dom-remove-children! is obsolete. use element-empty! instead");
|
422
|
+
$(ar[0]).update("");
|
423
|
+
return BiwaScheme.undef;
|
424
|
+
});
|
425
|
+
define_libfunc("dom-create-element", 1, 1, function(ar){
|
426
|
+
throw new Error("obsolete");
|
427
|
+
});
|
428
|
+
define_libfunc("element-append-child!", 2, 2, function(ar){
|
429
|
+
return $(ar[0]).appendChild(ar[1]);
|
430
|
+
});
|
431
|
+
define_libfunc("dom-remove-child!", 2, 2, function(ar){
|
432
|
+
throw new Error("obsolete");
|
433
|
+
});
|
434
|
+
// define_libfunc("dom-get-attribute", 2, 2, function(ar){
|
435
|
+
// });
|
436
|
+
// define_libfunc("dom-remove-child!", 2, 2, function(ar){
|
437
|
+
// });
|
438
|
+
|
439
|
+
//
|
440
|
+
// interface to javascript
|
441
|
+
//
|
442
|
+
define_libfunc_raw("js-eval", 1, 1, function(ar){
|
443
|
+
return eval(ar[0]);
|
444
|
+
});
|
445
|
+
define_libfunc_raw("js-ref", 2, 2, function(ar){
|
446
|
+
assert_string(ar[1]);
|
447
|
+
return ar[0][ar[1]]; //todo: first-class js function
|
448
|
+
});
|
449
|
+
define_libfunc("js-set!", 3, 3, function(ar){
|
450
|
+
assert_string(ar[1]);
|
451
|
+
ar[0][ar[1]] = ar[2];
|
452
|
+
return BiwaScheme.undef;
|
453
|
+
});
|
454
|
+
|
455
|
+
// (js-call (js-eval "Math.pow") 2 4)
|
456
|
+
define_libfunc_raw("js-call", 1, null, function(ar){
|
457
|
+
var js_func = ar.shift();
|
458
|
+
assert_function(js_func);
|
459
|
+
|
460
|
+
return js_func.apply(js_func, ar);
|
461
|
+
});
|
462
|
+
// (js-invoke (js-new "Date") "getTime")
|
463
|
+
define_libfunc_raw("js-invoke", 2, null, function(ar){
|
464
|
+
var js_obj = ar.shift();
|
465
|
+
var func_name = ar.shift();
|
466
|
+
assert_string(func_name);
|
467
|
+
if(js_obj[func_name])
|
468
|
+
return js_obj[func_name].apply(js_obj, ar);
|
469
|
+
else
|
470
|
+
throw new Error("js-invoke: function "+func_name+" is not defined");
|
471
|
+
});
|
472
|
+
|
473
|
+
// (js-new "Date" 2005 1 1)
|
474
|
+
// (js-new "Draggable elem 'onEnd (lambda (drg) ...))
|
475
|
+
// If symbol is given, following arguments are converted to
|
476
|
+
// an js object. If any of them is a scheme closure,
|
477
|
+
// it is converted to js function which invokes that closure.
|
478
|
+
//
|
479
|
+
define_libfunc("js-new", 1, null, function(ar, intp){
|
480
|
+
// make js object from key-value pair
|
481
|
+
var array_to_obj = function(ary){
|
482
|
+
if((ary.length % 2) != 0)
|
483
|
+
throw new Error("js-new: odd number of key-value pair");
|
484
|
+
|
485
|
+
var obj = {};
|
486
|
+
for(var i=0; i<ary.length; i+=2){
|
487
|
+
var key = ary[i], value = ary[i+1];
|
488
|
+
assert_symbol(key);
|
489
|
+
if(value.closure_p === true)
|
490
|
+
value = BiwaScheme.js_closure(value, intp);
|
491
|
+
|
492
|
+
obj[key.name] = value;
|
493
|
+
}
|
494
|
+
return obj;
|
495
|
+
};
|
496
|
+
|
497
|
+
var ctor = ar.shift();
|
498
|
+
assert_string(ctor);
|
499
|
+
if(ar.length == 0){
|
500
|
+
return eval("new " + ctor + "()");
|
501
|
+
}
|
502
|
+
else{
|
503
|
+
// pack args to js object, if symbol appears
|
504
|
+
var args = [];
|
505
|
+
for(var i=0; i<ar.length; i++){
|
506
|
+
if(ar[i] instanceof Symbol){
|
507
|
+
args.push(array_to_obj(ar.slice(i)));
|
508
|
+
break;
|
509
|
+
}
|
510
|
+
else{
|
511
|
+
args.push(ar[i]);
|
512
|
+
}
|
513
|
+
}
|
514
|
+
// construct js code to create new object
|
515
|
+
var args_str = ar.map(function(value, i){
|
516
|
+
return "args['" + i + "']";
|
517
|
+
}).join(",");
|
518
|
+
return eval("new " + ctor + "(" + args_str + ")");
|
519
|
+
}
|
520
|
+
});
|
521
|
+
|
522
|
+
// (js-obj "foo" 1 "bar" 2)
|
523
|
+
// -> {"foo": 1, "bar": 2}
|
524
|
+
define_libfunc("js-obj", 0, null, function(ar){
|
525
|
+
if(ar.length % 2 != 0){
|
526
|
+
throw new Error("js-obj: number of arguments must be even");
|
527
|
+
}
|
528
|
+
|
529
|
+
var obj = {};
|
530
|
+
for(i=0; i<ar.length/2; i++){
|
531
|
+
assert_string(ar[i*2]);
|
532
|
+
obj[ar[i*2]] = ar[i*2+1];
|
533
|
+
}
|
534
|
+
return obj;
|
535
|
+
});
|
536
|
+
|
537
|
+
// (js-closure (lambda (event) ..))
|
538
|
+
BiwaScheme.js_closure = function(proc, intp){
|
539
|
+
var on_error = intp.on_error;
|
540
|
+
return function(/*args*/){
|
541
|
+
var intp = new Interpreter(on_error);
|
542
|
+
intp.invoke_closure(proc, $A(arguments));
|
543
|
+
};
|
544
|
+
};
|
545
|
+
define_libfunc("js-closure", 1, 1, function(ar, intp){
|
546
|
+
assert_closure(ar[0]);
|
547
|
+
return BiwaScheme.js_closure(ar[0], intp);
|
548
|
+
});
|
549
|
+
|
550
|
+
define_libfunc("js-null?", 1, 1, function(ar){
|
551
|
+
return ar[0] === null;
|
552
|
+
});
|
553
|
+
|
554
|
+
define_libfunc("js-undefined?", 1, 1, function(ar){
|
555
|
+
return ar[0] === undefined;
|
556
|
+
});
|
557
|
+
|
558
|
+
//
|
559
|
+
// communication to server
|
560
|
+
//
|
561
|
+
define_libfunc("http-request", 1, 1, function(ar){
|
562
|
+
var path = ar[0];
|
563
|
+
assert_string(path);
|
564
|
+
|
565
|
+
return new BiwaScheme.Pause(function(pause){
|
566
|
+
new Ajax.Request(path, {
|
567
|
+
method: 'get',
|
568
|
+
onSuccess: function(transport) {
|
569
|
+
pause.resume(transport.responseText)
|
570
|
+
}
|
571
|
+
});
|
572
|
+
});
|
573
|
+
});
|
574
|
+
// (http-post "/foo" '(("x" . 1) ("y" . 2)))
|
575
|
+
define_libfunc("http-post", 2, 2, function(ar){
|
576
|
+
var path = ar[0];
|
577
|
+
assert_string(path);
|
578
|
+
var alist = ar[1];
|
579
|
+
assert_pair(alist);
|
580
|
+
var h = {};
|
581
|
+
|
582
|
+
alist.foreach(function(item){
|
583
|
+
assert_string(item.car);
|
584
|
+
h[item.car] = item.cdr;
|
585
|
+
})
|
586
|
+
|
587
|
+
return new BiwaScheme.Pause(function(pause){
|
588
|
+
new Ajax.Request(path, {
|
589
|
+
method: 'post',
|
590
|
+
postBody: $H(h).toQueryString(),
|
591
|
+
onSuccess: function(transport) {
|
592
|
+
pause.resume(transport.responseText)
|
593
|
+
}
|
594
|
+
});
|
595
|
+
});
|
596
|
+
});
|
597
|
+
|
598
|
+
BiwaScheme.jsonp_receiver = [];
|
599
|
+
define_libfunc("receive-jsonp", 1, 1, function(ar){
|
600
|
+
var url = ar[0];
|
601
|
+
assert_string(url);
|
602
|
+
|
603
|
+
var receives = BiwaScheme.jsonp_receiver;
|
604
|
+
for(var i=0; i<receives.length; i++)
|
605
|
+
if(receives[i] === null) break;
|
606
|
+
var receiver_id = i;
|
607
|
+
url += "?callback=BiwaScheme.jsonp_receiver[" + receiver_id + "]"
|
608
|
+
|
609
|
+
return new BiwaScheme.Pause(function(pause){
|
610
|
+
receives[receiver_id] = function(data){
|
611
|
+
pause.resume(data);
|
612
|
+
receives[receiver_id] = null;
|
613
|
+
}
|
614
|
+
var script = document.createElement('script')
|
615
|
+
script.src = url;
|
616
|
+
document.body.appendChild(script);
|
617
|
+
})
|
618
|
+
});
|
619
|
+
|
620
|
+
//
|
621
|
+
// dialog, debug
|
622
|
+
//
|
623
|
+
define_libfunc("alert", 1, 1, function(ar){
|
624
|
+
alert(ar[0]);
|
625
|
+
return BiwaScheme.undef;
|
626
|
+
});
|
627
|
+
define_libfunc("confirm", 1, 1, function(ar){
|
628
|
+
return confirm(ar[0]);
|
629
|
+
});
|
630
|
+
// define_libfunc("dumpobj", 1, 1, function(ar){
|
631
|
+
// return eval(ar[0]);
|
632
|
+
// });
|
633
|
+
|
634
|
+
//
|
635
|
+
// tuple space
|
636
|
+
//
|
637
|
+
BiwaScheme.TupleSpaceClient = Class.create({
|
638
|
+
initialize: function(server_path){
|
639
|
+
this.server_path = server_path; //must end with '/'
|
640
|
+
},
|
641
|
+
|
642
|
+
nonblocking_request: function(name, data){
|
643
|
+
var path = this.server_path + name + "?"
|
644
|
+
+ encodeURIComponent(to_write(data));
|
645
|
+
return this.connect(path);
|
646
|
+
},
|
647
|
+
blocking_request: function(name, data){
|
648
|
+
this.assert_init();
|
649
|
+
var path = this.server_path + name + "?"
|
650
|
+
+ encodeURIComponent(to_write(data))
|
651
|
+
+ "&cid=" + this.client_id;
|
652
|
+
return new BiwaScheme.Pause(function(pause){
|
653
|
+
this.ajax(path, function(ticket){
|
654
|
+
this.observe(ticket, function(tuple){
|
655
|
+
pause.resume(tuple);
|
656
|
+
});
|
657
|
+
}.bind(this));
|
658
|
+
}.bind(this));
|
659
|
+
},
|
660
|
+
|
661
|
+
write: function(value){
|
662
|
+
return this.nonblocking_request("write", value);
|
663
|
+
},
|
664
|
+
readp: function(query){
|
665
|
+
return this.nonblocking_request("readp", query);
|
666
|
+
},
|
667
|
+
takep: function(query){
|
668
|
+
return this.nonblocking_request("takep", query);
|
669
|
+
},
|
670
|
+
dump: function(){
|
671
|
+
return this.nonblocking_request("dump", "");
|
672
|
+
},
|
673
|
+
|
674
|
+
read: function(query){
|
675
|
+
return this.blocking_request("read", query);
|
676
|
+
},
|
677
|
+
take: function(query){
|
678
|
+
return this.blocking_request("take", query);
|
679
|
+
},
|
680
|
+
|
681
|
+
ajax: function(path, callback){
|
682
|
+
new Ajax.Request(path, {
|
683
|
+
onSuccess: function(transport){
|
684
|
+
callback(transport.responseText);
|
685
|
+
},
|
686
|
+
onFailure: function(){
|
687
|
+
puts("error: failed to access " + path);
|
688
|
+
}
|
689
|
+
});
|
690
|
+
},
|
691
|
+
|
692
|
+
init_connection: function(){
|
693
|
+
if(this.client_id){
|
694
|
+
return this.client_id;
|
695
|
+
}
|
696
|
+
else{
|
697
|
+
return new Pause(function(pause){
|
698
|
+
var path = this.server_path + "init_connection";
|
699
|
+
this.ajax(path, function(str){
|
700
|
+
this.client_id = str;
|
701
|
+
this.start_connection();
|
702
|
+
pause.resume(this.client_id);
|
703
|
+
}.bind(this));
|
704
|
+
}.bind(this));
|
705
|
+
}
|
706
|
+
},
|
707
|
+
assert_init: function(){
|
708
|
+
if(!this.client_id){
|
709
|
+
puts("ts-init not called:"+Object.inspect(this.client_id));
|
710
|
+
throw new Error("ts-init not called");
|
711
|
+
}
|
712
|
+
},
|
713
|
+
|
714
|
+
|
715
|
+
// returns nothing
|
716
|
+
start_connection: function(){
|
717
|
+
var path = this.server_path + "connection?"
|
718
|
+
+ "cid=" + this.client_id;
|
719
|
+
var loop = function(){
|
720
|
+
this.ajax(path, function(str){
|
721
|
+
var result = Interpreter.read(str);
|
722
|
+
var ticket = result.car, tuple = result.cdr;
|
723
|
+
|
724
|
+
this.notify(ticket, tuple);
|
725
|
+
loop();
|
726
|
+
}.bind(this));
|
727
|
+
}.bind(this);
|
728
|
+
loop();
|
729
|
+
},
|
730
|
+
|
731
|
+
waiters: [],
|
732
|
+
too_early_tuples: [],
|
733
|
+
observe: function(ticket, callback){
|
734
|
+
if(this.too_early_tuples[ticket]){
|
735
|
+
//alert("1 too early resolved");
|
736
|
+
callback(this.too_early_tuples[ticket]);
|
737
|
+
this.too_early_tuples[ticket] = undefined;
|
738
|
+
}
|
739
|
+
else if(this.waiters[ticket]){
|
740
|
+
puts("Bug: ticket conflicted");
|
741
|
+
}
|
742
|
+
else{
|
743
|
+
this.waiters[ticket] = callback;
|
744
|
+
}
|
745
|
+
},
|
746
|
+
notify: function(ticket, tuple){
|
747
|
+
var callback = this.waiters[ticket];
|
748
|
+
if(callback){
|
749
|
+
this.waiters[ticket] = undefined; //or use 'delete'?
|
750
|
+
return callback(tuple);
|
751
|
+
}
|
752
|
+
else{
|
753
|
+
this.too_early_tuples[ticket] = tuple;
|
754
|
+
}
|
755
|
+
},
|
756
|
+
|
757
|
+
connect: function(path, on_result){
|
758
|
+
path += "&time=" + (new Date()).getTime();
|
759
|
+
return new BiwaScheme.Pause(function(pause){
|
760
|
+
new Ajax.Request(path, {
|
761
|
+
method: 'get',
|
762
|
+
onSuccess: function(transport){
|
763
|
+
var result = transport.responseText;
|
764
|
+
if(on_result)
|
765
|
+
result = on_result(result);
|
766
|
+
else
|
767
|
+
result = Interpreter.read(result);
|
768
|
+
|
769
|
+
if(result == undefined)
|
770
|
+
pause.resume(false)
|
771
|
+
else
|
772
|
+
pause.resume(result)
|
773
|
+
},
|
774
|
+
onFailure: function(transport){
|
775
|
+
throw new Error("ts_client.connect: failed to access"+path);
|
776
|
+
pause.resume(false)
|
777
|
+
}
|
778
|
+
});
|
779
|
+
});
|
780
|
+
}
|
781
|
+
});
|
782
|
+
BiwaScheme.ts_client = new TupleSpaceClient("/ts/");
|
783
|
+
|
784
|
+
define_libfunc("ts-init", 0, 0, function(ar){
|
785
|
+
return ts_client.init_connection();
|
786
|
+
});
|
787
|
+
define_libfunc("ts-write", 1, 1, function(ar){
|
788
|
+
return ts_client.write(ar[0]);
|
789
|
+
});
|
790
|
+
|
791
|
+
define_libfunc("ts-read", 1, 1, function(ar){
|
792
|
+
var query = ar[0];
|
793
|
+
return ts_client.read(query); //returns a Pause
|
794
|
+
});
|
795
|
+
define_libfunc("ts-readp", 1, 1, function(ar){
|
796
|
+
return ts_client.readp(ar[0]);
|
797
|
+
});
|
798
|
+
define_libfunc("ts-take", 1, 1, function(ar){
|
799
|
+
return ts_client.take(ar[0]);
|
800
|
+
});
|
801
|
+
define_libfunc("ts-takep", 1, 1, function(ar){
|
802
|
+
return ts_client.takep(ar[0]);
|
803
|
+
});
|
804
|
+
define_libfunc("ts-dump", 0, 0, function(ar){
|
805
|
+
return ts_client.dump();
|
806
|
+
});
|
807
|
+
|
808
|
+
}
|
809
|
+
|