opal 0.0.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/runtime/compar.js ADDED
@@ -0,0 +1,73 @@
1
+ /*
2
+ * compar.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ var rb_mComparable;
29
+
30
+ function rb_cmp_equal(x, y) {
31
+ if (x == y) return true;
32
+ // rescue..
33
+ }
34
+
35
+ function rb_cmp_gt(x, y) {
36
+ var c = rb_funcall(x, "<=>", 1, y);
37
+ if (c > 0) return true;
38
+ return false;
39
+ }
40
+
41
+ function rb_cmp_ge(x, y) {
42
+ var c = rb_funcall(x, "<=>", 1, y);
43
+ if (c >= 0) return true;
44
+ return false;
45
+ }
46
+
47
+ function rb_cmp_lt(x, y) {
48
+ var c = rb_funcall(x, "<=>", 1, y);
49
+ if (c < 0) return true;
50
+ return false;
51
+ }
52
+
53
+ function rb_cmp_le(x, y) {
54
+ var c = rb_funcall(x, "<=>", 1, y);
55
+ if (c <= 0) return true;
56
+ return false;
57
+ }
58
+
59
+ function rb_cmp_between(obj, min, max) {
60
+ if (RTEST(rb_cmp_lt(obj, min))) return false;
61
+ if (RTEST(rb_cmp_gt(obj, max))) return false;
62
+ return true;
63
+ }
64
+
65
+ function Init_Comparable() {
66
+ rb_mComparable = rb_define_module("Comparable");
67
+ rb_define_method(rb_mComparable, "==", rb_cmp_equal, 1);
68
+ rb_define_method(rb_mComparable, ">", rb_cmp_gt, 1);
69
+ rb_define_method(rb_mComparable, ">=", rb_cmp_ge, 1);
70
+ rb_define_method(rb_mComparable, "<", rb_cmp_lt, 1);
71
+ rb_define_method(rb_mComparable, "<=", rb_cmp_le, 1);
72
+ rb_define_method(rb_mComparable, "between?", rb_cmp_between, 2);
73
+ }
data/runtime/dir.js ADDED
@@ -0,0 +1,115 @@
1
+ /*
2
+ * dir.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ var rb_cDir;
29
+
30
+ // glob
31
+ // /^\/app\/.*\/charles\/[^\/]*\.rb$/
32
+ // \/app\/.*\/[^\/]*\.rb
33
+ function rb_dir_s_glob(argc, argv, dir) {
34
+ if (argc > 1) throw "unsupported Dir.glob.. FIXME"
35
+
36
+ var result = [], eof = false;
37
+
38
+ var scanner = new vn_ruby_string_scanner(argv[0]);
39
+ while (!eof) {
40
+ // ** does not HAVE to include a dir, so capture **/ to match .* which will
41
+ // match a dir, or no dir.. allows both to work together.
42
+ if (scanner.scan(/^\*\*\//)) {
43
+ result.push('.*');
44
+ }
45
+ else if (scanner.scan(/^\*\*/)) {
46
+ result.push('.*');
47
+ }
48
+ else if (scanner.scan(/^\//)) {
49
+ result.push('\\/');
50
+ }
51
+ else if (scanner.scan(/^\*/)) {
52
+ result.push('[^\\/]*');
53
+ }
54
+ else if (scanner.scan(/^[a-zA-Z_]+/)) {
55
+ result.push(scanner.matched);
56
+ }
57
+ else if (scanner.scan(/^\./)) {
58
+ result.push('\\.');
59
+ }
60
+ else {
61
+ eof = true;
62
+ }
63
+ // if (result.length > 108)
64
+ // throw result.join("") + scanner.peek(10);
65
+ }
66
+
67
+ var reg = new RegExp('^' + result.join("") + '$');
68
+ var matching = [];
69
+ for (prop in vn_fs_path_hash) {
70
+ if (reg.exec(prop)) {
71
+ matching.push(prop);
72
+ }
73
+ }
74
+ return matching;
75
+ }
76
+
77
+ function Init_Dir() {
78
+
79
+ rb_cDir = rb_define_class("Dir", rb_cObject);
80
+ // rb_include_module(rb_cDir, rb_mEnumerable);
81
+
82
+ // rb_define_alloc_func(rb_cDir, rb_dir_s_alloc);
83
+ // rb_define_singleton_method(rb_cDir, "open", rb_dir_s_open, -1);
84
+ // rb_define_singleton_method(rb_cDir, "foreach", rb_dir_foreach, -1);
85
+ // rb_define_singleton_method(rb_cDir, "entries", rb_dir_entries, -1);
86
+ //
87
+ // rb_define_method(rb_cDir,"initialize", rb_dir_initialize, -1);
88
+ // rb_define_method(rb_cDir,"path", rb_dir_path, 0);
89
+ // rb_define_method(rb_cDir,"inspect", rb_dir_inspect, 0);
90
+ // rb_define_method(rb_cDir,"read", rb_dir_read, 0);
91
+ // rb_define_method(rb_cDir,"each", rb_dir_each, 0);
92
+ // rb_define_method(rb_cDir,"rewind", rb_dir_rewind, 0);
93
+ // rb_define_method(rb_cDir,"tell", rb_dir_tell, 0);
94
+ // rb_define_method(rb_cDir,"seek", rb_dir_seek, 1);
95
+ // rb_define_method(rb_cDir,"pos", rb_dir_tell, 0);
96
+ // rb_define_method(rb_cDir,"pos=", rb_dir_set_pos, 1);
97
+ // rb_define_method(rb_cDir,"close", rb_dir_close, 0);
98
+ //
99
+ // rb_define_singleton_method(rb_cDir,"chdir", rb_dir_s_chdir, -1);
100
+ // rb_define_singleton_method(rb_cDir,"getwd", rb_dir_s_getwd, 0);
101
+ // rb_define_singleton_method(rb_cDir,"pwd", rb_dir_s_getwd, 0);
102
+ // rb_define_singleton_method(rb_cDir,"chroot", rb_dir_s_chroot, 1);
103
+ // rb_define_singleton_method(rb_cDir,"mkdir", rb_dir_s_mkdir, -1);
104
+ // rb_define_singleton_method(rb_cDir,"rmdir", rb_dir_s_rmdir, 1);
105
+ // rb_define_singleton_method(rb_cDir,"delete", rb_dir_s_rmdir, 1);
106
+ // rb_define_singleton_method(rb_cDir,"unlink", rb_dir_s_rmdir, 1);
107
+ //
108
+ rb_define_singleton_method(rb_cDir,"glob", rb_dir_s_glob, -1);
109
+ // rb_define_singleton_method(rb_cDir,"[]", rb_dir_s_aref, -1);
110
+ // rb_define_singleton_method(rb_cDir,"exist?", rb_file_directory_p, 1);
111
+ // rb_define_singleton_method(rb_cDir,"exists?", rb_file_directory_p, 1);
112
+ //
113
+ // rb_define_singleton_method(rb_cFile,"fnmatch", rb_file_s_fnmatch, -1);
114
+ // rb_define_singleton_method(rb_cFile,"fnmatch?", rb_file_s_fnmatch, -1);
115
+ }
data/runtime/enum.js ADDED
@@ -0,0 +1,74 @@
1
+ /*
2
+ * enum.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+
29
+ var rb_mEnumerable;
30
+
31
+ function Init_Enumerable() {
32
+ rb_mEnumerable = rb_define_module("Enumerable");
33
+
34
+ // rb_define_method(rb_mEnumerable, "to_a", rb_enum_to_a, -1);
35
+ // rb_define_method(rb_mEnumerable, "entries", rb_enum_to_a, -1);
36
+
37
+ // rb_define_method(rb_mEnumerable, "sort", rb_enum_sort, 0);
38
+ // rb_define_method(rb_mEnumerable, "sort_by", rb_enum_sort_by, 0);
39
+ // rb_define_method(rb_mEnumerable, "grep", rb_enum_grep, 1);
40
+ // rb_define_method(rb_mEnumerable, "count", rb_enum_count, -1);
41
+ // rb_define_method(rb_mEnumerable, "find", rb_enum_find, -1);
42
+ // rb_define_method(rb_mEnumerable, "detect", rb_enum_find, -1);
43
+ // rb_define_method(rb_mEnumerable, "find_index", rb_enum_find_index, -1);
44
+ // rb_define_method(rb_mEnumerable, "find_all", rb_enum_find_all, 0);
45
+ // rb_define_method(rb_mEnumerable, "select", rb_enum_find_all, 0);
46
+ // rb_define_method(rb_mEnumerable, "reject", rb_enum_reject, 0);
47
+ // rb_define_method(rb_mEnumerable, "collect", rb_enum_collect, 0);
48
+ // rb_define_method(rb_mEnumerable, "map", rb_enum_collect, 0);
49
+ // rb_define_method(rb_mEnumerable, "inject", rb_enum_inject, -1);
50
+ // rb_define_method(rb_mEnumerable, "reduce", rb_enum_inject, -1);
51
+ // rb_define_method(rb_mEnumerable, "partition", rb_enum_partition, 0);
52
+ // rb_define_method(rb_mEnumerable, "group_by", rb_enum_group_by, 0);
53
+ // rb_define_method(rb_mEnumerable, "first", rb_enum_first, -1);
54
+ // rb_define_method(rb_mEnumerable, "all?", rb_enum_all, 0);
55
+ // rb_define_method(rb_mEnumerable, "any?", rb_enum_any, 0);
56
+ // rb_define_method(rb_mEnumerable, "one?", rb_enum_one, 0);
57
+ // rb_define_method(rb_mEnumerable, "none?", rb_enum_none, 0);
58
+ // rb_define_method(rb_mEnumerable, "min", rb_enum_min, 0);
59
+ // rb_define_method(rb_mEnumerable, "max", rb_enum_max, 0);
60
+ // rb_define_method(rb_mEnumerable, "minmax", rb_enum_minmax, 0);
61
+ // rb_define_method(rb_mEnumerable, "min_by", rb_enum_min_by, 0);
62
+ // rb_define_method(rb_mEnumerable, "max_by", rb_enum_max_by, 0);
63
+ // rb_define_method(rb_mEnumerable, "minmax_by", rb_enum_minmax_by, 0);
64
+ // rb_define_method(rb_mEnumerable, "member?", rb_enum_member, 1);
65
+ // rb_define_method(rb_mEnumerable, "include?", rb_enum_member, 1);
66
+ // rb_define_method(rb_mEnumerable, "each_with_index", rb_enum_each_with_index, -1);
67
+ // rb_define_method(rb_mEnumerable, "reverse_each", rb_enum_reverse_each, -1);
68
+ // rb_define_method(rb_mEnumerable, "zip", rb_enum_zip, -1);
69
+ // rb_define_method(rb_mEnumerable, "take", rb_enum_take, 1);
70
+ // rb_define_method(rb_mEnumerable, "take_while", rb_enum_take_while, 0);
71
+ // rb_define_method(rb_mEnumerable, "drop", rb_enum_drop, 1);
72
+ // rb_define_method(rb_mEnumerable, "drop_while", rb_enum_drop_while, 0);
73
+ // rb_define_method(rb_mEnumerable, "cycle", rb_enum_cycle, -1);
74
+ }
data/runtime/file.js ADDED
@@ -0,0 +1,165 @@
1
+ /*
2
+ * file.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ /**
29
+ @class File
30
+ @super Object
31
+
32
+ File.
33
+ */
34
+ var rb_cFile;
35
+
36
+ /**
37
+ Base object to store file/dir directory structure
38
+
39
+ Vienna FileSystem Root ("/")
40
+
41
+ Every entry has:
42
+ . as a self referring link to current dir
43
+ .. as a link to the parent dir
44
+ $ holds the current dirname (not whole path, just node name)
45
+
46
+ every other entry is then a file (child) belonging to the directory.
47
+ Objects as childs represent directories, where as a string refers to a
48
+ file, where the string content is the file content.
49
+
50
+ Directory names do not include a path seperator, and cannot be 0 length.
51
+ 0 length is reserved for root directory.
52
+ */
53
+ var vn_fs_root = {};
54
+ // roots' parent directory points to itself, only exception to rule.
55
+ vn_fs_root[".."] = vn_fs_root["."] = vn_fs_root;
56
+ vn_fs_root['$'] = "";
57
+
58
+ /**
59
+ Object/hash, from full file/dir names to either the file contents, for files,
60
+ or the directory structure, for directories. Makes accessing explicit file
61
+ paths easier, instead of splitting the path and manually going through the
62
+ tree, e.g:
63
+
64
+ ...
65
+ /vendor/vienna/lib/models => [Object object]
66
+ /vendor/vienna/lib/views/button.rb => "class Button < Control ... end"
67
+ ...
68
+ */
69
+ var vn_fs_path_hash = {
70
+ "/": vn_fs_root
71
+ };
72
+
73
+ /**
74
+ define a new file by filename (f), and filecontent (c)
75
+ */
76
+ function vn_fs_define_file(f, content) {
77
+ vn_fs_path_hash[f] = content;
78
+ var p = f.split("/");
79
+ var i, c = vn_fs_root, b;
80
+ // for each path segment, except first (which will be empty) and
81
+ // last, which will be a file, so treat differently
82
+ for (i = 1; i < p.length - 1; i++) {
83
+ b = p[i];
84
+ if (c[b] === undefined) {
85
+ c[b] = { };
86
+ c[b]['.'] = c[b];
87
+ c[b]['..'] = c;
88
+ c[b]['$'] = b;
89
+ }
90
+ c = c[b];
91
+ }
92
+ c[p[p.length - 1]] = content;
93
+ }
94
+
95
+
96
+ function rb_file_s_dirname(cls, dirname) {
97
+ return dirname.substr(0, dirname.lastIndexOf('/'));
98
+ // return "/dirname";
99
+ }
100
+
101
+ function rb_file_s_join(cls, args) {
102
+ return args.join("/");
103
+ }
104
+
105
+ function rb_file_s_expand_path(argc, args, obj) {
106
+ var res_stack = [], cur;
107
+ args = args[0].split("/")
108
+ for (var i = 0; i < args.length; i++) {
109
+ cur = args[i];
110
+ if (cur == '..') {
111
+ res_stack.pop();
112
+ }
113
+ else if (cur == '.' || cur == '') {
114
+ // do nothing
115
+ }
116
+ else {
117
+ res_stack.push(cur);
118
+ }
119
+ }
120
+ return "/" + res_stack.join("/");
121
+ }
122
+
123
+ function Init_File() {
124
+ rb_cFile = rb_define_class("File", rb_cObject);
125
+
126
+ // It seems silly to have all of these, but maybe we should have them to keep
127
+ // code comaptible? Just return current time..?
128
+ // rb_define_singleton_method(rb_cFile, "stat", rb_file_s_stat, 1);
129
+ // rb_define_singleton_method(rb_cFile, "lstat", rb_file_s_lstat, 1);
130
+ // rb_define_singleton_method(rb_cFile, "ftype", rb_file_s_ftype, 1);
131
+ //
132
+ // rb_define_singleton_method(rb_cFile, "atime", rb_file_s_atime, 1);
133
+ // rb_define_singleton_method(rb_cFile, "mtime", rb_file_s_mtime, 1);
134
+ // rb_define_singleton_method(rb_cFile, "ctime", rb_file_s_ctime, 1);
135
+ //
136
+ // rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1);
137
+ // rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1);
138
+ // rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1);
139
+ // rb_define_singleton_method(rb_cFile, "lchmod", rb_file_s_lchmod, -1);
140
+ // rb_define_singleton_method(rb_cFile, "lchown", rb_file_s_lchown, -1);
141
+ //
142
+ // rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2);
143
+ // rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2);
144
+ // rb_define_singleton_method(rb_cFile, "readlink", rb_file_s_readlink, 1);
145
+ //
146
+ // rb_define_singleton_method(rb_cFile, "unlink", rb_file_s_unlink, -2);
147
+ // rb_define_singleton_method(rb_cFile, "delete", rb_file_s_unlink, -2);
148
+ // rb_define_singleton_method(rb_cFile, "rename", rb_file_s_rename, 2);
149
+ // rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
150
+ // rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
151
+ rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
152
+ // rb_define_singleton_method(rb_cFile, "absolute_path", rb_file_s_absolute_path, -1);
153
+ // rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
154
+ rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1);
155
+ // rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
156
+ // rb_define_singleton_method(rb_cFile, "path", rb_file_s_path, 1);
157
+ //
158
+ // rb_define_const(rb_cFile, "Separator", "/");
159
+ // rb_define_const(rb_cFile, "SEPARATOR", "/");
160
+ // rb_define_const(rb_cFile, "PATH_SEPARATOR", "/");
161
+ //
162
+ // rb_define_singleton_method(rb_cFile, "split", rb_file_s_split, 1);
163
+ rb_define_singleton_method(rb_cFile, "join", rb_file_s_join, -1);
164
+ }
165
+
data/runtime/gem.js ADDED
@@ -0,0 +1,241 @@
1
+ /*
2
+ * gem.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+
29
+ /**
30
+ Gem support: only for gems/bundles in the vngem format. Also provides some gem
31
+ methods and classes that are useful. The majority is not implemented however
32
+ for usage patterns/reasons.
33
+
34
+ name - gem name, e.g. 'vienna'
35
+ path - bundles will be '/vendor' or similar, app will be '/' or ''
36
+ content - string content of the vngem file. This will possibly be removed once
37
+ the content has been parsed and the necessary files have been created.
38
+ loaded - has this gem/bundle been required()? The content is not parsed or
39
+ processed until it is required... which usually happens straight away.
40
+ This property is useful to avoid loading a bundle twice.
41
+ */
42
+ function vn_gem() {
43
+ this.name = "";
44
+ this.path = "";
45
+ this.content = "";
46
+ this.loaded = false;
47
+ }
48
+
49
+ // all gems/apps/bundles, name => gem object
50
+ var vn_gem_all = { };
51
+
52
+ /**
53
+ preload the gem at the given path so it will be ready. callbacks used for
54
+ chaining gem loading
55
+ */
56
+ function vn_gem_preload(path, name) {
57
+ // preload.
58
+ }
59
+
60
+ /**
61
+ boot a gem with the given name, path and content (i.e. process it)
62
+ */
63
+ function vn_gem_boot(name, path, content) {
64
+ var g = new vn_gem();
65
+ g.name = name;
66
+ g.path = path;
67
+ g.content = content;
68
+ vn_gem_all[name] = g;
69
+ vm_gem_load(g);
70
+ return g;
71
+ }
72
+
73
+ /**
74
+ Do actual gem processing
75
+ */
76
+ function vm_gem_load(gem) {
77
+ if (gem.loaded) throw "Cannot load gem twice... something silly happened"
78
+
79
+ var at = 0;
80
+ var ch = '';
81
+ var text = gem.content;
82
+
83
+ // parse a file
84
+ function parse_file() {
85
+ var f = get_next(marker_count());
86
+ var c = get_next(marker_count());
87
+ vn_fs_define_file(f, c);
88
+ }
89
+
90
+ // parse gem definiton
91
+ function parse_gem_def() {
92
+ var g = get_next(marker_count());
93
+ var p = get_next(marker_count());
94
+ console.log('found ' + g + ' at ' + p);
95
+ }
96
+
97
+ // parse_locales
98
+ // parse a list of locales that this application has defined
99
+ function parse_locales() {
100
+
101
+ }
102
+
103
+ // parse a css file..
104
+ // for IE we might need to use:
105
+ // var content = get_next(marker_count());
106
+ // var style = document.createElement("style");
107
+ // style.setAttribute("type", "text/css");
108
+ // if (style.styleSheet) {
109
+ // // this for internet explorer..
110
+ // style.styleSheet.cssText = content;
111
+ // }
112
+ // else {
113
+ // style.appendChild(document.createTextNode(content));
114
+ // }
115
+ function parse_css() {
116
+ var content = get_next(marker_count());
117
+ var style = document.createElement('style');
118
+ style.setAttribute("type", "text/css");
119
+ if (style.styleSheet) {
120
+ // ie.
121
+ style.styleSheet.cssText = content;
122
+ }
123
+ else {
124
+ // w3c
125
+ style.appendChild(document.createTextNode(content));
126
+ }
127
+
128
+ document.getElementsByTagName('head')[0].appendChild(style);
129
+ }
130
+
131
+ // get gem format
132
+ var gem_format = (function() {
133
+ var marker = text.indexOf('$', at);
134
+ var format = text.substr(at, marker - at);
135
+ at = marker + 1;
136
+ return format;
137
+ })();
138
+
139
+ // get gem version
140
+ var gem_version = (function() {
141
+ var marker = text.indexOf('$', at);
142
+ var version = text.substr(at, marker - at);
143
+ at = marker + 1;
144
+ return version;
145
+ })();
146
+
147
+ var next = function(c) {
148
+ if (c && c !== ch) {
149
+ console.log('bundle parse error: Expected ' + c + ', but instead got ' + ch);
150
+ }
151
+ ch = text.charAt(at);
152
+ at += 1;
153
+ return ch;
154
+ };
155
+
156
+ var get_next = function(i) {
157
+ var result = text.substr(at, i);
158
+ at += i;
159
+ return result;
160
+ };
161
+
162
+ var marker_count = function() {
163
+ var len = '';
164
+ next();
165
+ while (ch >= '0' && ch <= '9') {
166
+ len += ch;
167
+ next(); // this will also pass us through the $ at the end of length
168
+ }
169
+ return parseInt(len);
170
+ };
171
+
172
+ while (next()) {
173
+ switch (ch) {
174
+ case 'f':
175
+ parse_file();
176
+ break;
177
+ case 'g':
178
+ parse_gem_def();
179
+ break;
180
+ case 'l':
181
+ parse_locales();
182
+ break;
183
+ case 's':
184
+ parse_string_table();
185
+ break;
186
+ case 'p':
187
+ parse_platform_list();
188
+ break;
189
+ case 'c':
190
+ parse_css();
191
+ break;
192
+ default:
193
+ throw "unknown bundle part " + ch
194
+ }
195
+ }
196
+
197
+ // make sure we dont do this again
198
+ gem.loaded = true;
199
+ return gem;
200
+ }
201
+
202
+
203
+ /**
204
+ New javascript based "gem" loading
205
+ */
206
+
207
+ /**
208
+ Declare this file contains the gem named 'name' which is located at the path
209
+ 'path'
210
+ */
211
+ function opal_gem(name, path) {
212
+
213
+ };
214
+
215
+ /**
216
+ A source file - ruby, yaml etc. NOT Javascript. JS files are handled
217
+ seperately so they are eval()'d instantly.
218
+ */
219
+ function opal_file(path, content) {
220
+ vn_fs_define_file(path, content);
221
+ };
222
+
223
+ /**
224
+ Code - i.e. javascript. Eval these instantly. We retain the path so if an
225
+ error occurs, then we can point back to the source file it originates from.
226
+ */
227
+ function opal_code(path, code) {
228
+ if (window.execScript) {
229
+ window.execScript(code);
230
+ } else {
231
+ with (window) { eval(code); }
232
+ }
233
+ };
234
+
235
+ /**
236
+ CSS styles - shouldnt be a lot of these, but, if they exist, pop into head of
237
+ document.
238
+ */
239
+ function opal_style(content) {
240
+
241
+ };