opal 0.3.2 → 0.3.6

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.
Files changed (203) hide show
  1. data/README.md +85 -127
  2. data/bin/opal +3 -3
  3. data/lib/core.rb +114 -0
  4. data/{gems/core/lib → lib}/core/array.rb +68 -187
  5. data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
  6. data/lib/core/class.rb +38 -0
  7. data/{gems/core/lib → lib}/core/dir.rb +1 -1
  8. data/lib/core/enumerable.rb +33 -0
  9. data/{gems/core/lib → lib}/core/error.rb +1 -4
  10. data/{gems/core/lib → lib}/core/false_class.rb +0 -0
  11. data/{gems/core/lib → lib}/core/file.rb +11 -3
  12. data/{gems/core/lib → lib}/core/hash.rb +12 -0
  13. data/{gems/core/lib → lib}/core/kernel.rb +114 -86
  14. data/lib/core/match_data.rb +33 -0
  15. data/lib/core/module.rb +97 -0
  16. data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
  17. data/{gems/core/lib → lib}/core/numeric.rb +5 -0
  18. data/{gems/core/lib → lib}/core/object.rb +0 -0
  19. data/{gems/core/lib → lib}/core/proc.rb +13 -3
  20. data/{gems/core/lib → lib}/core/range.rb +10 -0
  21. data/{gems/core/lib → lib}/core/regexp.rb +33 -1
  22. data/{gems/core/lib → lib}/core/string.rb +25 -10
  23. data/{gems/core/lib → lib}/core/symbol.rb +3 -3
  24. data/{gems/core/lib → lib}/core/top_self.rb +0 -0
  25. data/{gems/core/lib → lib}/core/true_class.rb +0 -0
  26. data/lib/dev.rb +169 -0
  27. data/{gems/ospec/lib → lib}/ospec.rb +1 -0
  28. data/lib/ospec/autorun.rb +8 -0
  29. data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
  30. data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
  31. data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
  32. data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
  33. data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
  34. data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
  35. data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
  36. data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
  37. data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
  38. data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
  39. data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
  40. data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
  41. data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
  42. data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
  43. data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
  44. data/lib/ospec/helpers/scratch.rb +18 -0
  45. data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
  46. data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
  47. data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
  48. data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
  49. data/lib/ospec/matchers/raise_error.rb +38 -0
  50. data/lib/ospec/runner.rb +90 -0
  51. data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
  52. data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
  53. data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
  54. data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
  55. data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
  56. data/lib/racc/parser.rb +165 -0
  57. data/lib/strscan.rb +52 -0
  58. data/{lib → opal_lib}/opal.rb +2 -0
  59. data/opal_lib/opal/build_methods.rb +51 -0
  60. data/opal_lib/opal/builder.rb +164 -0
  61. data/opal_lib/opal/bundle.rb +70 -0
  62. data/opal_lib/opal/command.rb +68 -0
  63. data/{lib → opal_lib}/opal/context.rb +21 -9
  64. data/{lib → opal_lib}/opal/context/console.rb +0 -2
  65. data/opal_lib/opal/context/file_system.rb +34 -0
  66. data/{lib → opal_lib}/opal/context/loader.rb +26 -8
  67. data/opal_lib/opal/gem.rb +84 -0
  68. data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
  69. data/opal_lib/opal/rake/spec_task.rb +32 -0
  70. data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
  71. data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
  72. data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
  73. data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
  74. data/opal_lib/opal/version.rb +4 -0
  75. data/runtime/class.js +359 -0
  76. data/runtime/debug.js +84 -0
  77. data/runtime/fs.js +199 -0
  78. data/runtime/init.js +558 -0
  79. data/runtime/loader.js +351 -0
  80. data/runtime/module.js +109 -0
  81. data/runtime/post.js +10 -0
  82. data/runtime/pre.js +7 -0
  83. data/runtime/runtime.js +351 -0
  84. metadata +88 -175
  85. data/.gitignore +0 -7
  86. data/Changelog +0 -31
  87. data/LICENSE +0 -75
  88. data/Rakefile +0 -86
  89. data/gems/core/README.md +0 -14
  90. data/gems/core/Rakefile +0 -8
  91. data/gems/core/core.gemspec +0 -13
  92. data/gems/core/lib/core.rb +0 -34
  93. data/gems/core/lib/core/class.rb +0 -31
  94. data/gems/core/lib/core/module.rb +0 -100
  95. data/gems/core/lib/core/vm.rb +0 -16
  96. data/gems/core/spec/core/array/append_spec.rb +0 -30
  97. data/gems/core/spec/core/array/assoc_spec.rb +0 -29
  98. data/gems/core/spec/core/array/at_spec.rb +0 -37
  99. data/gems/core/spec/core/array/clear_spec.rb +0 -22
  100. data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
  101. data/gems/core/spec/core/array/collect_spec.rb +0 -27
  102. data/gems/core/spec/core/array/compact_spec.rb +0 -41
  103. data/gems/core/spec/core/array/concat_spec.rb +0 -15
  104. data/gems/core/spec/core/array/constructor_spec.rb +0 -14
  105. data/gems/core/spec/core/array/each_spec.rb +0 -9
  106. data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
  107. data/gems/core/spec/core/array/first_spec.rb +0 -35
  108. data/gems/core/spec/core/array/include_spec.rb +0 -9
  109. data/gems/core/spec/core/array/join_spec.rb +0 -6
  110. data/gems/core/spec/core/array/last_spec.rb +0 -51
  111. data/gems/core/spec/core/array/length_spec.rb +0 -6
  112. data/gems/core/spec/core/array/map_spec.rb +0 -33
  113. data/gems/core/spec/core/array/reverse_spec.rb +0 -6
  114. data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
  115. data/gems/core/spec/core/false/and_spec.rb +0 -10
  116. data/gems/core/spec/core/false/inspect_spec.rb +0 -6
  117. data/gems/core/spec/core/false/or_spec.rb +0 -10
  118. data/gems/core/spec/core/false/to_s_spec.rb +0 -6
  119. data/gems/core/spec/core/false/xor_spec.rb +0 -10
  120. data/gems/core/spec/core/file/join_spec.rb +0 -19
  121. data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
  122. data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
  123. data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
  124. data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
  125. data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
  126. data/gems/core/spec/core/number/lt_spec.rb +0 -12
  127. data/gems/core/spec/core/string/sub_spec.rb +0 -24
  128. data/gems/core/spec/core/true/and_spec.rb +0 -10
  129. data/gems/core/spec/core/true/inspect_spec.rb +0 -6
  130. data/gems/core/spec/core/true/or_spec.rb +0 -10
  131. data/gems/core/spec/core/true/to_s_spec.rb +0 -6
  132. data/gems/core/spec/core/true/xor_spec.rb +0 -10
  133. data/gems/core/spec/language/and_spec.rb +0 -61
  134. data/gems/core/spec/language/array_spec.rb +0 -68
  135. data/gems/core/spec/language/block_spec.rb +0 -38
  136. data/gems/core/spec/language/break_spec.rb +0 -36
  137. data/gems/core/spec/language/case_spec.rb +0 -103
  138. data/gems/core/spec/language/def_spec.rb +0 -21
  139. data/gems/core/spec/language/eigenclass_spec.rb +0 -60
  140. data/gems/core/spec/language/file_spec.rb +0 -13
  141. data/gems/core/spec/language/fixtures/block.rb +0 -21
  142. data/gems/core/spec/language/fixtures/super.rb +0 -293
  143. data/gems/core/spec/language/hash_spec.rb +0 -29
  144. data/gems/core/spec/language/if_spec.rb +0 -54
  145. data/gems/core/spec/language/loop_spec.rb +0 -11
  146. data/gems/core/spec/language/metaclass_spec.rb +0 -21
  147. data/gems/core/spec/language/method_spec.rb +0 -124
  148. data/gems/core/spec/language/next_spec.rb +0 -25
  149. data/gems/core/spec/language/or_spec.rb +0 -34
  150. data/gems/core/spec/language/redo_spec.rb +0 -24
  151. data/gems/core/spec/language/regexp_spec.rb +0 -26
  152. data/gems/core/spec/language/rescue_spec.rb +0 -20
  153. data/gems/core/spec/language/return_spec.rb +0 -47
  154. data/gems/core/spec/language/string_spec.rb +0 -25
  155. data/gems/core/spec/language/super_spec.rb +0 -32
  156. data/gems/core/spec/language/until_spec.rb +0 -157
  157. data/gems/core/spec/language/variables_spec.rb +0 -155
  158. data/gems/core/spec/language/while_spec.rb +0 -163
  159. data/gems/core/spec/spec_helper.rb +0 -5
  160. data/gems/core_fs/README.md +0 -19
  161. data/gems/dev/Rakefile +0 -5
  162. data/gems/dev/lib/dev.js +0 -99
  163. data/gems/dev/lib/dev/generator.js +0 -1264
  164. data/gems/dev/lib/dev/parser.js +0 -979
  165. data/gems/dev/lib/dev/ruby_parser.js +0 -1088
  166. data/gems/dev/lib/dev/ruby_parser.y +0 -1267
  167. data/gems/dev/lib/dev/string_scanner.js +0 -38
  168. data/gems/dev/tools/racc2js/README.md +0 -39
  169. data/gems/dev/tools/racc2js/math_parser.js +0 -222
  170. data/gems/dev/tools/racc2js/math_parser.rb +0 -133
  171. data/gems/dev/tools/racc2js/math_parser.y +0 -28
  172. data/gems/dev/tools/racc2js/parser.js +0 -218
  173. data/gems/dev/tools/racc2js/racc2js.rb +0 -153
  174. data/gems/json/README.md +0 -4
  175. data/gems/json/json.gemspec +0 -14
  176. data/gems/json/lib/json.rb +0 -64
  177. data/gems/json/lib/json/ext.rb +0 -51
  178. data/gems/json/lib/json/json2.js +0 -481
  179. data/gems/ospec/README.md +0 -0
  180. data/gems/ospec/lib/ospec/autorun.rb +0 -3
  181. data/gems/ospec/lib/ospec/runner.rb +0 -40
  182. data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
  183. data/gems/ospec/ospec.gemspec +0 -0
  184. data/gems/rquery/README.md +0 -9
  185. data/gems/rquery/lib/rquery.rb +0 -10
  186. data/gems/rquery/lib/rquery/ajax.rb +0 -4
  187. data/gems/rquery/lib/rquery/css.rb +0 -96
  188. data/gems/rquery/lib/rquery/document.rb +0 -25
  189. data/gems/rquery/lib/rquery/element.rb +0 -292
  190. data/gems/rquery/lib/rquery/event.rb +0 -108
  191. data/gems/rquery/lib/rquery/jquery.js +0 -8177
  192. data/gems/rquery/lib/rquery/request.rb +0 -138
  193. data/gems/rquery/lib/rquery/response.rb +0 -49
  194. data/gems/rquery/rquery.gemspec +0 -16
  195. data/lib/opal.js +0 -1597
  196. data/lib/opal/builder.rb +0 -117
  197. data/lib/opal/bundle.rb +0 -131
  198. data/lib/opal/command.rb +0 -11
  199. data/lib/opal/context/file_system.rb +0 -19
  200. data/lib/opal/gem.rb +0 -153
  201. data/lib/opal/ruby/ruby_parser.rb +0 -5170
  202. data/lib/opal/ruby/ruby_parser.y +0 -1298
  203. data/opal.gemspec +0 -15
@@ -1,155 +0,0 @@
1
-
2
- describe "Operator assignment 'var op= expr'" do
3
- it "is equivalent to 'var = var op expr'" do
4
- x = 13
5
- (x += 5).should == 18
6
- x.should == 18
7
-
8
- x = 17
9
- (x -= 11).should == 6
10
- x.should == 6
11
-
12
- x = 2
13
- (x *= 5).should == 10
14
- x.should == 10
15
-
16
- # x = 36
17
- # (x /= 9).should == 4
18
- # x.should == 4
19
-
20
- # x = 23
21
- # (x %= 5).should == 3
22
- # x.should == 3
23
- # (x %= 3).should == 0
24
- # x.should == 0
25
-
26
- # x = 2
27
- # (x **= 3).should == 8
28
- # x.should == 8
29
-
30
- # x = 4
31
- # (x |= 3).should == 7
32
- # x.should == 7
33
- # (x |= 4).should == 7
34
- # x.should == 7
35
-
36
- # x = 6
37
- # (x &= 3).should == 2
38
- # x.should == 2
39
- # (x &= 4).should == 0
40
- # x.should == 0
41
-
42
- # x = 2
43
- # (x ^= 3).should == 1
44
- # x.should == 1
45
- # (x ^= 4).should == 5
46
- # x.should == 5
47
-
48
- # x = 17
49
- # (x <<= 3).should == 136
50
- # x.should == 136
51
-
52
- # x = 5
53
- # (x >>= 1).should == 2
54
- # x.should == 2
55
-
56
- x = nil
57
- (x ||= 17).should == 17
58
- x.should == 17
59
- (x ||= 2).should == 17
60
- x.should == 17
61
-
62
- # x = false
63
- # (x &&= true).should == false
64
- # x.should == false
65
- # (x &&= false).should == false
66
- # x.should == false
67
- # x = true
68
- # (x &&= true).should == true
69
- # x.should == true
70
- # (x &&= false).should == false
71
- # x.should == false
72
- end
73
- end
74
-
75
- describe "Operator assignment 'obj[idx] op= expr'" do
76
- it "is equivalent to 'obj[idx] = obj[idx] op expr'" do
77
- x = [2, 13, 7]
78
- (x[1] += 5).should == 18
79
- x.should == [2, 18, 7]
80
-
81
- x = [17, 6]
82
- (x[0] -= 11).should == 6
83
- x.should == [6, 6]
84
- end
85
- end
86
-
87
- describe "Single assignment" do
88
- it "Assignment does not modify the lhs, it reassigns its reference" do
89
- a = 'Foobar'
90
- b = a
91
- b = 'Bazquux'
92
- a.should == 'Foobar'
93
- b.should == 'Bazquux'
94
- end
95
-
96
- it "Assignment does not copy the object being assigned, just creates a new reference to it" do
97
- a = []
98
- b = a
99
- b << 1
100
- a.should == [1]
101
- end
102
-
103
- it "If rhs has multiple arguments, lhs becomes an Array of them" do
104
- a = 1, 2, 3
105
- a.should == [1, 2, 3]
106
-
107
- a = 1, (), 3
108
- a.should == [1, nil, 3]
109
- end
110
- end
111
-
112
- describe "Multiple assignment without grouping or splatting" do
113
- it "an equal number of arguments on lhs and rhs assigns positionally" do
114
- a, b, c, d = 1, 2, 3, 4
115
- a.should == 1
116
- b.should == 2
117
- c.should == 3
118
- d.should == 4
119
- end
120
-
121
- it "If rhs has too few arguments, the missing ones on lhs are assigned nil" do
122
- a, b, c = 1, 2
123
- a.should == 1
124
- b.should == 2
125
- c.should == nil
126
- end
127
-
128
- it "If rhs has too many arguments, the extra ones are silently not assigned anywhere" do
129
- a, b = 1, 2, 3
130
- a.should == 1
131
- b.should == 2
132
- end
133
- end
134
-
135
- describe "Multiple assignments with splats" do
136
- it "* on the lhs collects all parameters from its position onwards as an Array or an empty array" do
137
- a, *b = 1, 2
138
- c, *d = 1
139
- e, *f = 1, 2, 3
140
- g, *h = 1, [2, 3]
141
- # i
142
- # j
143
- # k
144
-
145
- a.should == 1
146
- b.should == [2]
147
- c.should == 1
148
- d.should == []
149
- e.should == 1
150
- f.should == [2, 3]
151
- g.should == 1
152
- h.should == [[2, 3]]
153
- end
154
- end
155
-
@@ -1,163 +0,0 @@
1
-
2
- describe "The while expression" do
3
- it "runs while the expression is true" do
4
- i = 0
5
- while i < 3
6
- i = i + 1
7
- end
8
-
9
- i.should == 3
10
- end
11
-
12
- it "optionally takes a 'do' after the expression" do
13
- i = 0
14
- while i < 3 do
15
- i = i + 1
16
- end
17
-
18
- i.should == 3
19
- end
20
-
21
- it "allows body begin on the same line if do is used" do
22
- i = 0
23
- while i < 3 do i = i + 1
24
- end
25
-
26
- i.should == 3
27
- end
28
-
29
- it "executes code in containing variable scope" do
30
- i = 0
31
- while i != 1
32
- a = 123
33
- i = 1
34
- end
35
-
36
- a.should == 123
37
- end
38
-
39
- it "executes code in containing variable scope with 'do'" do
40
- i = 0
41
- while i != 1 do
42
- a = 123
43
- i = 1
44
- end
45
-
46
- a.should == 123
47
- end
48
-
49
- it "returns nil if ended when condition became false" do
50
- i = 0
51
- while i < 3
52
- i = i + 1
53
- end.should == nil
54
- end
55
-
56
- it "does not evaluate the body if expression is empty" do
57
- a = []
58
- while ()
59
- a << :body_evaluated
60
- end
61
- a.should == []
62
- end
63
-
64
- it "stops running body if interrupted by break" do
65
- i = 0
66
- while i < 10
67
- i = i + 1
68
- break if i > 5
69
- end
70
-
71
- i.should == 6
72
- end
73
-
74
- it "returns value passed to break if interrupted by break" do
75
- while true
76
- break 123
77
- end.should == 123
78
- end
79
-
80
- it "returns nil if interrupted by break with no arguments" do
81
- while true
82
- break
83
- end.should == nil
84
- end
85
-
86
- it "skips to end of body with next" do
87
- a = []
88
- i = 0
89
- while (i = i + 1) < 5
90
- next if i == 3
91
- a << i
92
- end
93
-
94
- a.should == [1, 2, 4]
95
- end
96
-
97
- it "restarts the current iteration without reevaluating condition with redo" do
98
- a = []
99
- i = 0
100
- j = 0
101
- while (i = i + 1) < 3
102
- a << i
103
- j = j + 1
104
- # redo if j < 3
105
- end
106
-
107
- a.should == [1, 1, 1, 2]
108
- end
109
- end
110
-
111
- describe "The while modifier" do
112
- it "runs preceding statement while the condition is true" do
113
- i = 0
114
- i = i + 1 while i < 3
115
- i.should == 3
116
- end
117
-
118
- it "evaluates condition before statement execution" do
119
- a = []
120
- i = 0
121
- a << i while (i = i + 1) < 3
122
- a.should == [1, 2]
123
- end
124
-
125
- it "does not run preceding statement if the condition is false" do
126
- i = 0
127
- i = i + 1 while false
128
- i.should == 0
129
- end
130
-
131
- it "does not run preceding statement if the condition is empty" do
132
- i = 0
133
- i = i + 1 while ()
134
- i.should == 0
135
- end
136
-
137
- it "returns nil if ended when condition became false" do
138
- i = 0
139
- (i = i + 1 while i < 10).should == nil
140
- end
141
-
142
- it "returns value passed to break if interrupetd by break" do
143
- (break 123 while true).should == 123
144
- end
145
-
146
- it "returns nil if interrupted by break with no arguments" do
147
- (break while true).should == nil
148
- end
149
-
150
- it "skips to end of body with next" do
151
- i = 0
152
- j = 0
153
- (( i = i + 1) == 3 ? next : j = j + i) while i <= 10
154
- j.should == 63
155
- end
156
-
157
- it "restarts the current iteration without reevaluating condition with redo" do
158
- i = 0
159
- j = 0
160
- # (i = i + 1) == 4 ? redo : j = j + i while (i = i + 1) <= 10
161
- j.should == 34
162
- end
163
- end
@@ -1,5 +0,0 @@
1
- # Usually do this to require our libs, but as we are in opal, these are already
2
- # included.
3
- # require File.join(File.dirname(__FILE__), '..', 'lib', 'opal.rb')
4
-
5
- puts "in spec helper"
@@ -1,19 +0,0 @@
1
- Opals' Ruby Filesystem
2
- ======================
3
-
4
- This gem provides the additional methods for File and Dir to support
5
- full reading and writing. Core only contains the most basic methods
6
- from File and Dir because Opal in the browser has no means of actually
7
- reading or writing to disk. This gem is only meant to be used by the
8
- gem context, which runs ontop of therubyracer. This gem will
9
- automatically be loaded by the Context class, so it will be immediately
10
- available for use.
11
-
12
- Implementation
13
- --------------
14
-
15
- The Context class in the Opal build tools exposes/fixes the `.fs` property
16
- on the `opal` object in the javascript context to expose a lot of the
17
- native functionality directly. This is backed by the `FileSystem` class
18
- in the Opal build tools.
19
-
data/gems/dev/Rakefile DELETED
@@ -1,5 +0,0 @@
1
- desc "Rebuild parser for dev"
2
- task :parser do
3
- system "./tools/racc2js/racc2js.rb ./packages/opal_dev/lib/opal_dev/ruby_parser.y"
4
- end
5
-
data/gems/dev/lib/dev.js DELETED
@@ -1,99 +0,0 @@
1
- console.log("in opal dev, boom!");
2
-
3
- /*
4
- * Browser dev wraps all the dev tools, for compiling etc, but adds some functionality
5
- * in-browser. It will automatically pick out text/ruby script tags and execute their
6
- * content. opal.js does not do this as the compiler is required. opal_dev.js should
7
- * only be used in development mode, so overhead in checking/compiling ruby code
8
- * in the browser will not affect production level environments.
9
- */
10
-
11
- var dev_tools = require('opal_dev/parser');
12
-
13
- for (var prop in dev_tools) {
14
- exports[prop] = dev_tools[prop];
15
- };
16
-
17
- /**
18
- Exposes an on screen repl session.
19
- */
20
- exports.browser_repl = function() {
21
- browser_register_ready_listener(function() {
22
- // wrapping div
23
- var repl_element = document.createElement('div');
24
-
25
- // text input
26
- var input = document.createElement('input');
27
- input.type = 'text';
28
- repl_element.appendChild(input);
29
-
30
- document.body.appendChild(repl_element);
31
-
32
- input.onkeydown = function() {
33
- console.log("key down..");
34
- };
35
- });
36
- };
37
-
38
- /*
39
- * Document ready listener can take callbacks that are fired when the document
40
- * and/or window are ready to run. If already loaded then the callback is just
41
- * called immediately.
42
- */
43
- var browser_register_ready_listener = function(callback) {
44
- if (browser_is_ready) return callback();
45
-
46
- (function() {
47
- // w3c - chrome, safari, ff
48
- if (document.addEventListener) {
49
- document.addEventListener('DOMContentLoaded', callback, false);
50
- }
51
- // IE
52
- else {
53
- (function() {
54
- try {
55
- document.documentElement.doScroll('left');
56
- } catch (e) {
57
- setTimeout(arguments.callee, 0);
58
- return;
59
- }
60
- callback();
61
- })();
62
- }
63
- })();
64
- };
65
-
66
- /*
67
- * Document is not ready yet...
68
- */
69
- var browser_is_ready = false;
70
-
71
- /*
72
- * Find all script tags and run them.
73
- */
74
- browser_register_ready_listener(function() {
75
- browser_is_ready = true;
76
-
77
- var tags = document.getElementsByTagName('script'), tag;
78
-
79
- for (var i = 0; i < tags.length; i++) {
80
- tag = tags[i];
81
-
82
- if (tag.type == 'text/ruby') {
83
- // src property - load by ajax, then run
84
- if (tag.src) {
85
-
86
- }
87
- // no src, so just run inner contents
88
- else {
89
- console.log('need to run content:');
90
- console.log(tag.innerHTML);
91
- var result = Opal.compile(tag.innerHTML);
92
- console.log(result);
93
- eval(result);
94
- }
95
- }
96
- }
97
- });
98
-
99
-