opal 0.2.2 → 0.3.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.
Files changed (325) hide show
  1. data/.gitignore +5 -10
  2. data/LICENSE +75 -0
  3. data/README.md +55 -3
  4. data/Rakefile +62 -139
  5. data/bin/opal +7 -10
  6. data/gems/core/README.md +5 -0
  7. data/gems/core/Rakefile +7 -0
  8. data/gems/core/core.gemspec +13 -0
  9. data/gems/core/lib/core.rb +33 -0
  10. data/gems/core/lib/core/array.rb +1470 -0
  11. data/gems/core/lib/core/basic_object.rb +15 -0
  12. data/gems/core/lib/core/class.rb +31 -0
  13. data/gems/core/lib/core/dir.rb +26 -0
  14. data/gems/core/lib/core/error.rb +43 -0
  15. data/gems/core/lib/core/false_class.rb +21 -0
  16. data/gems/core/lib/core/file.rb +54 -0
  17. data/gems/core/lib/core/hash.rb +725 -0
  18. data/gems/core/lib/core/kernel.rb +240 -0
  19. data/gems/core/lib/core/module.rb +98 -0
  20. data/gems/core/lib/core/nil_class.rb +41 -0
  21. data/gems/core/lib/core/numeric.rb +370 -0
  22. data/gems/core/lib/core/proc.rb +11 -0
  23. data/gems/core/lib/core/range.rb +17 -0
  24. data/gems/core/lib/core/regexp.rb +18 -0
  25. data/gems/core/lib/core/string.rb +328 -0
  26. data/gems/core/lib/core/symbol.rb +15 -0
  27. data/gems/core/lib/core/top_self.rb +8 -0
  28. data/gems/core/lib/core/true_class.rb +20 -0
  29. data/gems/core/lib/core/vm.rb +16 -0
  30. data/{opals/opal/opal → gems/core}/spec/core/array/append_spec.rb +0 -0
  31. data/{opals/opal/opal → gems/core}/spec/core/array/assoc_spec.rb +0 -0
  32. data/{opals/opal/opal → gems/core}/spec/core/array/at_spec.rb +0 -0
  33. data/{opals/opal/opal → gems/core}/spec/core/array/clear_spec.rb +1 -1
  34. data/{opals/opal/opal → gems/core}/spec/core/array/collect_bang_spec.rb +0 -0
  35. data/{opals/opal/opal → gems/core}/spec/core/array/collect_spec.rb +0 -0
  36. data/gems/core/spec/core/array/compact_spec.rb +41 -0
  37. data/{opals/opal/opal → gems/core}/spec/core/array/concat_spec.rb +0 -0
  38. data/{opals/opal/opal → gems/core}/spec/core/array/constructor_spec.rb +0 -0
  39. data/{opals/opal/opal → gems/core}/spec/core/array/each_spec.rb +0 -0
  40. data/{opals/opal/opal → gems/core}/spec/core/array/element_reference_spec.rb +0 -0
  41. data/{opals/opal/opal → gems/core}/spec/core/array/first_spec.rb +1 -1
  42. data/{opals/opal/opal → gems/core}/spec/core/array/include_spec.rb +0 -0
  43. data/gems/core/spec/core/array/join_spec.rb +6 -0
  44. data/gems/core/spec/core/array/last_spec.rb +51 -0
  45. data/gems/core/spec/core/array/length_spec.rb +6 -0
  46. data/{opals/opal/opal → gems/core}/spec/core/array/map_spec.rb +2 -0
  47. data/gems/core/spec/core/array/reverse_spec.rb +6 -0
  48. data/{opals/opal/opal → gems/core}/spec/core/builtin_constants/builtin_constants_spec.rb +0 -0
  49. data/{opals/opal/opal → gems/core}/spec/core/false/and_spec.rb +0 -0
  50. data/{opals/opal/opal → gems/core}/spec/core/false/inspect_spec.rb +0 -0
  51. data/{opals/opal/opal → gems/core}/spec/core/false/or_spec.rb +0 -0
  52. data/{opals/opal/opal → gems/core}/spec/core/false/to_s_spec.rb +0 -0
  53. data/{opals/opal/opal → gems/core}/spec/core/false/xor_spec.rb +0 -0
  54. data/{opals/opal/opal → gems/core}/spec/core/file/join_spec.rb +1 -1
  55. data/gems/core/spec/core/hash/assoc_spec.rb +32 -0
  56. data/{opals/opal/opal → gems/core}/spec/core/kernel/instance_eval_spec.rb +0 -0
  57. data/{opals/opal/opal → gems/core}/spec/core/kernel/loop_spec.rb +0 -0
  58. data/{opals/opal/opal → gems/core}/spec/core/kernel/raise_spec.rb +0 -0
  59. data/{opals/opal/opal → gems/core}/spec/core/module/attr_accessor_spec.rb +0 -0
  60. data/{opals/opal/opal → gems/core}/spec/core/number/lt_spec.rb +0 -0
  61. data/gems/core/spec/core/string/sub_spec.rb +24 -0
  62. data/{opals/opal/opal → gems/core}/spec/core/true/and_spec.rb +0 -0
  63. data/{opals/opal/opal → gems/core}/spec/core/true/inspect_spec.rb +0 -0
  64. data/{opals/opal/opal → gems/core}/spec/core/true/or_spec.rb +0 -0
  65. data/{opals/opal/opal → gems/core}/spec/core/true/to_s_spec.rb +0 -0
  66. data/{opals/opal/opal → gems/core}/spec/core/true/xor_spec.rb +0 -0
  67. data/{opals/opal/opal → gems/core}/spec/language/and_spec.rb +2 -3
  68. data/{opals/opal/opal → gems/core}/spec/language/array_spec.rb +21 -5
  69. data/gems/core/spec/language/block_spec.rb +38 -0
  70. data/{opals/opal/opal → gems/core}/spec/language/break_spec.rb +0 -0
  71. data/gems/core/spec/language/case_spec.rb +103 -0
  72. data/{opals/opal/opal → gems/core}/spec/language/def_spec.rb +11 -1
  73. data/{opals/opal/opal → gems/core}/spec/language/eigenclass_spec.rb +0 -0
  74. data/gems/core/spec/language/file_spec.rb +13 -0
  75. data/gems/core/spec/language/fixtures/block.rb +21 -0
  76. data/gems/core/spec/language/fixtures/super.rb +293 -0
  77. data/{opals/opal/opal → gems/core}/spec/language/hash_spec.rb +0 -0
  78. data/{opals/opal/opal → gems/core}/spec/language/if_spec.rb +0 -0
  79. data/{opals/opal/opal → gems/core}/spec/language/loop_spec.rb +0 -0
  80. data/gems/core/spec/language/metaclass_spec.rb +21 -0
  81. data/{opals/opal/opal → gems/core}/spec/language/method_spec.rb +60 -0
  82. data/{opals/opal/opal → gems/core}/spec/language/next_spec.rb +0 -0
  83. data/{opals/opal/opal → gems/core}/spec/language/or_spec.rb +0 -0
  84. data/{opals/opal/opal → gems/core}/spec/language/redo_spec.rb +0 -0
  85. data/gems/core/spec/language/regexp_spec.rb +26 -0
  86. data/{opals/opal/opal → gems/core}/spec/language/rescue_spec.rb +0 -0
  87. data/{opals/opal/opal → gems/core}/spec/language/return_spec.rb +0 -0
  88. data/{opals/opal/opal → gems/core}/spec/language/string_spec.rb +0 -0
  89. data/gems/core/spec/language/super_spec.rb +32 -0
  90. data/{opals/opal/opal → gems/core}/spec/language/until_spec.rb +47 -47
  91. data/gems/core/spec/language/variables_spec.rb +155 -0
  92. data/{opals/opal/opal → gems/core}/spec/language/while_spec.rb +47 -47
  93. data/{opals/opal/opal → gems/core}/spec/spec_helper.rb +1 -1
  94. data/gems/core_fs/README.md +19 -0
  95. data/gems/dev/Rakefile +5 -0
  96. data/gems/dev/lib/dev.js +99 -0
  97. data/gems/dev/lib/dev/generator.js +1264 -0
  98. data/gems/dev/lib/dev/parser.js +979 -0
  99. data/gems/dev/lib/dev/ruby_parser.js +1088 -0
  100. data/gems/dev/lib/dev/ruby_parser.y +1267 -0
  101. data/gems/dev/lib/dev/string_scanner.js +38 -0
  102. data/gems/dev/tools/racc2js/README.md +39 -0
  103. data/gems/dev/tools/racc2js/math_parser.js +222 -0
  104. data/gems/dev/tools/racc2js/math_parser.rb +133 -0
  105. data/gems/dev/tools/racc2js/math_parser.y +28 -0
  106. data/gems/dev/tools/racc2js/parser.js +218 -0
  107. data/gems/dev/tools/racc2js/racc2js.rb +153 -0
  108. data/gems/json/README.md +4 -0
  109. data/gems/json/json.gemspec +14 -0
  110. data/gems/json/lib/json.rb +64 -0
  111. data/gems/json/lib/json/ext.rb +51 -0
  112. data/{opals/opal/browser/lib/browser/json_parse.js → gems/json/lib/json/json2.js} +197 -37
  113. data/gems/ospec/README.md +0 -0
  114. data/gems/ospec/lib/ospec.rb +6 -0
  115. data/gems/ospec/lib/ospec/autorun.rb +3 -0
  116. data/gems/ospec/lib/ospec/dsl.rb +15 -0
  117. data/gems/ospec/lib/ospec/example.rb +11 -0
  118. data/gems/ospec/lib/ospec/example/before_and_after_hooks.rb +56 -0
  119. data/gems/ospec/lib/ospec/example/errors.rb +17 -0
  120. data/gems/ospec/lib/ospec/example/example_group.rb +12 -0
  121. data/gems/ospec/lib/ospec/example/example_group_factory.rb +21 -0
  122. data/gems/ospec/lib/ospec/example/example_group_hierarchy.rb +20 -0
  123. data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/example/example_group_methods.rb +26 -68
  124. data/gems/ospec/lib/ospec/example/example_group_proxy.rb +14 -0
  125. data/gems/ospec/lib/ospec/example/example_methods.rb +46 -0
  126. data/gems/ospec/lib/ospec/example/example_proxy.rb +18 -0
  127. data/gems/ospec/lib/ospec/expectations.rb +19 -0
  128. data/gems/ospec/lib/ospec/expectations/errors.rb +8 -0
  129. data/gems/ospec/lib/ospec/expectations/fail_with.rb +8 -0
  130. data/gems/ospec/lib/ospec/expectations/handler.rb +27 -0
  131. data/gems/ospec/lib/ospec/matchers.rb +24 -0
  132. data/{opals/opal/Rakefile → gems/ospec/lib/ospec/matchers/be.rb} +0 -0
  133. data/gems/ospec/lib/ospec/matchers/generated_descriptions.rb +20 -0
  134. data/gems/ospec/lib/ospec/matchers/operator_matcher.rb +52 -0
  135. data/gems/ospec/lib/ospec/runner.rb +40 -0
  136. data/gems/ospec/lib/ospec/runner/example_group_runner.rb +44 -0
  137. data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/formatter/html_formatter.rb +31 -40
  138. data/gems/ospec/lib/ospec/runner/formatter/terminal_formatter.rb +48 -0
  139. data/gems/ospec/lib/ospec/runner/options.rb +36 -0
  140. data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/reporter.rb +23 -55
  141. data/gems/ospec/ospec.gemspec +0 -0
  142. data/gems/rquery/README.md +9 -0
  143. data/gems/rquery/lib/rquery.rb +10 -0
  144. data/gems/rquery/lib/rquery/ajax.rb +4 -0
  145. data/gems/rquery/lib/rquery/css.rb +96 -0
  146. data/gems/rquery/lib/rquery/document.rb +25 -0
  147. data/gems/rquery/lib/rquery/element.rb +292 -0
  148. data/gems/rquery/lib/rquery/event.rb +108 -0
  149. data/gems/rquery/lib/rquery/jquery.js +8177 -0
  150. data/gems/rquery/lib/rquery/request.rb +138 -0
  151. data/gems/rquery/lib/rquery/response.rb +49 -0
  152. data/gems/rquery/rquery.gemspec +16 -0
  153. data/lib/opal.js +1597 -0
  154. data/lib/opal.rb +6 -69
  155. data/lib/opal/builder.rb +115 -0
  156. data/lib/opal/bundle.rb +131 -0
  157. data/lib/opal/command.rb +11 -0
  158. data/lib/opal/context.rb +69 -0
  159. data/lib/opal/context/console.rb +12 -0
  160. data/lib/opal/context/file_system.rb +19 -0
  161. data/lib/opal/context/loader.rb +117 -0
  162. data/lib/opal/gem.rb +153 -0
  163. data/lib/opal/ruby/nodes.rb +1302 -0
  164. data/lib/opal/ruby/parser.rb +780 -0
  165. data/lib/opal/ruby/ruby_parser.rb +5170 -0
  166. data/lib/opal/ruby/ruby_parser.y +1298 -0
  167. data/opal.gemspec +11 -256
  168. metadata +179 -240
  169. data/.gitmodules +0 -6
  170. data/Opalfile +0 -384
  171. data/VERSION +0 -1
  172. data/demos/apps/browser_demo/index.html +0 -11
  173. data/demos/apps/browser_demo/lib/browser_demo.rb +0 -31
  174. data/demos/apps/simple_opal/Opalfile +0 -13
  175. data/demos/apps/simple_opal/index.html +0 -11
  176. data/demos/apps/simple_opal/lib/app_controller.rb +0 -62
  177. data/demos/apps/simple_opal/lib/main_window.rb +0 -146
  178. data/demos/browser/request/index.html +0 -52
  179. data/demos/browser/request/request.rb +0 -48
  180. data/gen/browser/__PROJECT_NAME__/Rakefile +0 -12
  181. data/gen/browser/__PROJECT_NAME__/index.html +0 -11
  182. data/gen/browser/__PROJECT_NAME__/javascripts/opal.debug.js +0 -4687
  183. data/gen/browser/__PROJECT_NAME__/javascripts/opal.min.js +0 -175
  184. data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +0 -1
  185. data/lib/opal/builders/base.rb +0 -50
  186. data/lib/opal/builders/css.rb +0 -46
  187. data/lib/opal/builders/javascript.rb +0 -44
  188. data/lib/opal/builders/opal.rb +0 -79
  189. data/lib/opal/builders/ruby.rb +0 -50
  190. data/lib/opal/builders/ruby/generate.rb +0 -1851
  191. data/lib/opal/builders/ruby/nodes.rb +0 -210
  192. data/lib/opal/builders/ruby/ruby.rb +0 -916
  193. data/lib/opal/builders/ruby/ruby_parser.rb +0 -6008
  194. data/lib/opal/builders/ruby/ruby_parser.rb.y +0 -1451
  195. data/lib/opal/models/build_item.rb +0 -104
  196. data/lib/opal/models/hash_struct.rb +0 -40
  197. data/lib/opal/models/project.rb +0 -252
  198. data/lib/opal/models/struct_accessors.rb +0 -58
  199. data/lib/opal/models/target.rb +0 -176
  200. data/lib/opal/opal/build.rb +0 -169
  201. data/lib/opal/opal/env/console.rb +0 -66
  202. data/lib/opal/opal/env/fs.rb +0 -98
  203. data/lib/opal/opal/env/object.rb +0 -48
  204. data/lib/opal/opal/environment.rb +0 -139
  205. data/lib/opal/opal/gen.rb +0 -62
  206. data/lib/opal/opal/opal.rb +0 -75
  207. data/lib/opal/opal/repl.rb +0 -38
  208. data/lib/opal/opalfile/dsl.rb +0 -62
  209. data/lib/opal/opalfile/opalfile.rb +0 -133
  210. data/lib/opal/opalfile/task.rb +0 -96
  211. data/lib/opal/opalfile/task_manager.rb +0 -63
  212. data/lib/opal/opalfile/task_scope.rb +0 -52
  213. data/lib/opal/rack/app_server.rb +0 -119
  214. data/lib/opal/rake/opal_task.rb +0 -34
  215. data/opals/opal/README.md +0 -37
  216. data/opals/opal/browser/Opalfile +0 -11
  217. data/opals/opal/browser/README.md +0 -146
  218. data/opals/opal/browser/SIZZLE_LICESNSE.txt +0 -148
  219. data/opals/opal/browser/lib/browser.rb +0 -118
  220. data/opals/opal/browser/lib/browser/builder.rb +0 -41
  221. data/opals/opal/browser/lib/browser/canvas_context.rb +0 -115
  222. data/opals/opal/browser/lib/browser/dimensions.rb +0 -50
  223. data/opals/opal/browser/lib/browser/document.rb +0 -146
  224. data/opals/opal/browser/lib/browser/element.rb +0 -487
  225. data/opals/opal/browser/lib/browser/element/attributes.rb +0 -88
  226. data/opals/opal/browser/lib/browser/element/css.rb +0 -290
  227. data/opals/opal/browser/lib/browser/element/form.rb +0 -146
  228. data/opals/opal/browser/lib/browser/event/dom_events.rb +0 -81
  229. data/opals/opal/browser/lib/browser/event/event.rb +0 -177
  230. data/opals/opal/browser/lib/browser/event/trigger_events.rb +0 -53
  231. data/opals/opal/browser/lib/browser/geometry.rb +0 -97
  232. data/opals/opal/browser/lib/browser/json.rb +0 -32
  233. data/opals/opal/browser/lib/browser/request/request.rb +0 -201
  234. data/opals/opal/browser/lib/browser/sizzle.js +0 -1068
  235. data/opals/opal/browser/lib/browser/string.rb +0 -42
  236. data/opals/opal/browser/lib/browser/touch.rb +0 -37
  237. data/opals/opal/browser/lib/browser/vml_context.js +0 -33
  238. data/opals/opal/browser/lib/browser/window.rb +0 -36
  239. data/opals/opal/browser/spec/browser/browser_detection_spec.rb +0 -7
  240. data/opals/opal/browser/spec/document/aref_spec.rb +0 -110
  241. data/opals/opal/browser/spec/document/ready_spec.rb +0 -16
  242. data/opals/opal/browser/spec/element/body_spec.rb +0 -11
  243. data/opals/opal/browser/spec/element/clear_spec.rb +0 -26
  244. data/opals/opal/browser/spec/element/empty_spec.rb +0 -29
  245. data/opals/opal/browser/spec/element/has_class_spec.rb +0 -40
  246. data/opals/opal/browser/spec/element/hidden_spec.rb +0 -23
  247. data/opals/opal/browser/spec/element/hide_spec.rb +0 -31
  248. data/opals/opal/browser/spec/element/remove_spec.rb +0 -25
  249. data/opals/opal/browser/spec/element/show_spec.rb +0 -31
  250. data/opals/opal/browser/spec/element/style_spec.rb +0 -69
  251. data/opals/opal/browser/spec/element/toggle_spec.rb +0 -31
  252. data/opals/opal/browser/spec/element/visible_spec.rb +0 -23
  253. data/opals/opal/browser/spec/spec_helper.rb +0 -1
  254. data/opals/opal/opal/Opalfile +0 -14
  255. data/opals/opal/opal/spec/core/array/compact_spec.rb +0 -15
  256. data/opals/opal/opal/spec/fixtures/super.rb +0 -70
  257. data/opals/opal/opal/spec/language/____temp_remove_this.rb +0 -12
  258. data/opals/opal/opal/spec/language/block_spec.rb +0 -18
  259. data/opals/opal/opal/spec/language/case_spec.rb +0 -103
  260. data/opals/opal/opal/spec/language/metaclass_spec.rb +0 -21
  261. data/opals/opal/opal/spec/language/super_spec.rb +0 -26
  262. data/opals/opal/runtime/Opalfile +0 -78
  263. data/opals/opal/runtime/README.md +0 -12
  264. data/opals/opal/runtime/docs/debugging.md +0 -51
  265. data/opals/opal/runtime/lib/array.rb +0 -1516
  266. data/opals/opal/runtime/lib/basic_object.rb +0 -49
  267. data/opals/opal/runtime/lib/class.rb +0 -54
  268. data/opals/opal/runtime/lib/dir.rb +0 -36
  269. data/opals/opal/runtime/lib/error.rb +0 -49
  270. data/opals/opal/runtime/lib/false_class.rb +0 -52
  271. data/opals/opal/runtime/lib/file.rb +0 -79
  272. data/opals/opal/runtime/lib/hash.rb +0 -791
  273. data/opals/opal/runtime/lib/io.rb +0 -39
  274. data/opals/opal/runtime/lib/kernel.rb +0 -288
  275. data/opals/opal/runtime/lib/match_data.rb +0 -36
  276. data/opals/opal/runtime/lib/module.rb +0 -109
  277. data/opals/opal/runtime/lib/nil_class.rb +0 -69
  278. data/opals/opal/runtime/lib/number.rb +0 -398
  279. data/opals/opal/runtime/lib/proc.rb +0 -77
  280. data/opals/opal/runtime/lib/range.rb +0 -63
  281. data/opals/opal/runtime/lib/regexp.rb +0 -111
  282. data/opals/opal/runtime/lib/ruby.rb +0 -30
  283. data/opals/opal/runtime/lib/string.rb +0 -328
  284. data/opals/opal/runtime/lib/symbol.rb +0 -40
  285. data/opals/opal/runtime/lib/top_self.rb +0 -33
  286. data/opals/opal/runtime/lib/true_class.rb +0 -45
  287. data/opals/opal/runtime/runtime/browser.js +0 -287
  288. data/opals/opal/runtime/runtime/debug.js +0 -180
  289. data/opals/opal/runtime/runtime/opal.js +0 -1008
  290. data/opals/opal/runtime/runtime/post_opal.js +0 -1
  291. data/opals/opal/runtime/runtime/pre_opal.js +0 -2
  292. data/opals/opal/runtime/runtime/server_side.js +0 -50
  293. data/opals/opal/spec/LICENSE.txt +0 -26
  294. data/opals/opal/spec/Opalfile +0 -5
  295. data/opals/opal/spec/bin/spec.rb +0 -43
  296. data/opals/opal/spec/lib/spec.rb +0 -33
  297. data/opals/opal/spec/lib/spec/dsl.rb +0 -41
  298. data/opals/opal/spec/lib/spec/example.rb +0 -35
  299. data/opals/opal/spec/lib/spec/example/before_and_after_hooks.rb +0 -81
  300. data/opals/opal/spec/lib/spec/example/errors.rb +0 -42
  301. data/opals/opal/spec/lib/spec/example/example_group.rb +0 -37
  302. data/opals/opal/spec/lib/spec/example/example_group_factory.rb +0 -43
  303. data/opals/opal/spec/lib/spec/example/example_group_hierarchy.rb +0 -45
  304. data/opals/opal/spec/lib/spec/example/example_group_proxy.rb +0 -41
  305. data/opals/opal/spec/lib/spec/example/example_methods.rb +0 -73
  306. data/opals/opal/spec/lib/spec/example/example_proxy.rb +0 -48
  307. data/opals/opal/spec/lib/spec/expectations.rb +0 -46
  308. data/opals/opal/spec/lib/spec/expectations/errors.rb +0 -35
  309. data/opals/opal/spec/lib/spec/expectations/fail_with.rb +0 -37
  310. data/opals/opal/spec/lib/spec/expectations/handler.rb +0 -48
  311. data/opals/opal/spec/lib/spec/matchers.rb +0 -50
  312. data/opals/opal/spec/lib/spec/matchers/be.rb +0 -26
  313. data/opals/opal/spec/lib/spec/matchers/generated_descriptions.rb +0 -47
  314. data/opals/opal/spec/lib/spec/matchers/operator_matcher.rb +0 -66
  315. data/opals/opal/spec/lib/spec/runner.rb +0 -48
  316. data/opals/opal/spec/lib/spec/runner/example_group_runner.rb +0 -71
  317. data/opals/opal/spec/lib/spec/runner/formatter/terminal_formatter.rb +0 -82
  318. data/opals/opal/spec/lib/spec/runner/options.rb +0 -63
  319. data/opals/opal/spec/resources/index.html +0 -25
  320. data/opals/opal/spec/resources/spec.css +0 -132
  321. data/spec/cherry_kit/iseq_spec.rb +0 -38
  322. data/spec/spec_helper.rb +0 -16
  323. data/spec/vienna_spec.rb +0 -7
  324. data/yard/index.html +0 -43
  325. data/yard/style.css +0 -765
@@ -0,0 +1,4 @@
1
+ class Ajax
2
+ nil
3
+ end
4
+
@@ -0,0 +1,96 @@
1
+ class Element
2
+
3
+ # Adds the given class or classes to each element in the receiver. Multiple
4
+ # classes may be added by seperating them with a space. These classes do not
5
+ # replace any previously set classes, but are instead added.
6
+ #
7
+ # @param [String] name the class(es) name(s)
8
+ # @return [Element] returns the receiver
9
+ def add_class(name)
10
+ `return self.addClass(name);`
11
+ end
12
+
13
+ # Removes the given class or classes to each element in the receiver. Multiple
14
+ # classes may be removed at once by passing in a space seperated string of
15
+ # classnames. To remove all classes, dont pass in a parameter, which will
16
+ # remove all set classes.
17
+ #
18
+ # @param [String] name the classes to remove
19
+ # @return [Element] returns the receiver
20
+ def remove_class(name = nil)
21
+ if name
22
+ `self.removeClass(name)`
23
+ else
24
+ `self.removeClass()`
25
+ end
26
+ end
27
+
28
+ # Returns `true` if any of the matched elements contain the given `name` in
29
+ # their classes, `false` otherwise.
30
+ #
31
+ # @param [String] name class name to check for
32
+ # @return [true, false]
33
+ def has_class?(name)
34
+ `return self.hasClass(name) ? Qtrue : Qfalse;`
35
+ end
36
+
37
+ def style(key = nil, value = nil)
38
+ if key.nil?
39
+ # raise "need to return a StyleHash"
40
+ @style_hash ||= StyleHash.new self
41
+ elsif value.nil?
42
+ raise "need to use getter for key"
43
+ else
44
+ raise "need to use setter"
45
+ end
46
+ end
47
+
48
+ alias_method :css, :style
49
+
50
+ # Basically used to catch method_missing calls when we try to set style
51
+ # properties, or try to retrieve them. All calls onto style will be
52
+ # either trying to set or set a property, so we just do the right thing.
53
+ class StyleHash < BasicObject
54
+ def initialize(element)
55
+ `return self.$element = element;`
56
+ end
57
+
58
+ # Method missing will be called for getting and setting properties. If we
59
+ # are setting a property, then our css_property will have a '=' at the end
60
+ # of it, and its value will be css_value. If we are just getting a value,
61
+ # then css_property will not have an '=', and css_value will remain nil.
62
+ #
63
+ # {#[]} and {#[]=} can handle aref and aset independantly also, so they
64
+ # will not be forwarded here.
65
+ def method_missing(css_property, css_value = nil)
66
+ `var name = #{css_property.to_s};
67
+ console.log("===== " + name);
68
+ if (css_value == nil) {
69
+ console.log("getting property!");
70
+ return self.$element.css(css_property);
71
+ } else {
72
+ console.log("need to remove = from css_property name");
73
+ console.log("setting property!");
74
+ return self.$element.css(css_property, css_value);
75
+ }`
76
+ end
77
+
78
+ # We will be accessing to_s and inspect a lot during development, so lets
79
+ # just define them here. They do not conflict with any css property, so
80
+ # no issues will be presented.
81
+ def to_s
82
+ "#<StyleHash element: " + `self.$element`.inspect + ">"
83
+ end
84
+
85
+ def inspect
86
+ to_s
87
+ end
88
+
89
+ # Again, during development we may want to put stuff to console, so we just
90
+ # use Object's puts implementation
91
+ def puts(str)
92
+ Object.puts str
93
+ end
94
+ end
95
+ end
96
+
@@ -0,0 +1,25 @@
1
+ module Document
2
+ # Accepts a block that will be called once the document is ready. This uses
3
+ # the underlying $(function() { ... }) mechanism. Note, multiple blocks may
4
+ # be passed to this function and they will be called in order.
5
+ #
6
+ # @example
7
+ #
8
+ # Document.ready? do
9
+ # puts "document is now ready"
10
+ # end
11
+ #
12
+ # @return [Document] returns self
13
+ def self.ready?
14
+ `$(function() { #{yield}; })` if block_given?
15
+ self
16
+ end
17
+
18
+ # Returns an {Element} representing the <head> element of the page.
19
+ #
20
+ # @return {Element} head element
21
+ def self.head
22
+ `return $(document.getElementsByTagName('head')[0]);`
23
+ end
24
+ end
25
+
@@ -0,0 +1,292 @@
1
+ # jQuery objects themselves are bridged to the ruby Element class. This allows
2
+ # direct access to jquery through ruby, and makes the creation and accessing of
3
+ # jquery objects really fast and efficient (there is minimal overhead introduced
4
+ # by wrapping them).
5
+ #
6
+ # This is accomplished basically by adding the requied opal properties onto jquery
7
+ # as if they were just plugins; $m, $klass and $flags. These are the same names as
8
+ # added to the core prototypes as to avoid name confliction as much as possible.
9
+ OpalVM.bridged_class `$.fn`, 'Element'
10
+
11
+ # Element is used two-fold. It is the equivalent of the jQuery object in js,
12
+ # and is used to create new element literals. Therefore, an Element instance
13
+ # can actually represent 1, many, or even 0 actual elements. Element for this
14
+ # reason is actually more like an array of elements, where its instance
15
+ # methods are applied to 0 or more actual elements. Accessing elements
16
+ # individually through {#first} etc, still returns an Element instance with
17
+ # a singular element literal.
18
+ class Element
19
+ # Top level selector. This is the equivalent of passing a selector string
20
+ # to the jQuery object. This searches essentially in the context of the
21
+ # document, and returns an Element instance with all matched elements.
22
+ #
23
+ # @example
24
+ #
25
+ # Element.find 'div > p'
26
+ # # => #<Element 0x91232>
27
+ #
28
+ # @param [String] selector
29
+ # @return [Element]
30
+ def self.find(selector)
31
+ from_native `$(selector)`
32
+ end
33
+
34
+ # alias_method :[], :find
35
+
36
+ # Initialze is used when simply creating a new Element, the equivalent of
37
+ # document.createElement('tagName'). It is then wrapped by jquery and
38
+ # becomes the sole element belonging to this instance.
39
+ #
40
+ # Creating a new Element instance should only be used when actually creating
41
+ # a new DOM element. For referencing already existing elements, instead use
42
+ # one of the selector methods, {Element#find} etc.
43
+ #
44
+ # NOTE: initialize is not used due to limitations on creating/adding to jquery
45
+ # objects, so we need to override .new instead.
46
+ #
47
+ # @return [Element]
48
+ def self.new(type = 'div')
49
+ `return $(document.createElement(type));`
50
+ end
51
+
52
+ # PRIVATE!!!!!
53
+ #
54
+ # Should really be a js method? Basically this takes a jquery object, which
55
+ # is NOT a ruby object, and returns a new Element instance with the given
56
+ # jquery object as its content. The passed jq variable should be a jquery
57
+ # object.
58
+ def self.from_native(elem)
59
+ `return $(elem);`
60
+ end
61
+
62
+ # Returns a string representation of the collection of elements. If the
63
+ # receiver contains a single element, then it will display the tag name,
64
+ # id and class of the receiver. If more than one element is present, then
65
+ # the inspection string will just contain the number of contained elements.
66
+ #
67
+ # @return [String]
68
+ def to_s
69
+ if length == 1
70
+ str = "#<Element #{tag}"
71
+ str += ", id=#{id.inspect}" if id
72
+ str + ">"
73
+ else
74
+ "#<Element length: #{length}>"
75
+ end
76
+ end
77
+
78
+ # Returns the tag name of the receiver. All tag names are in lowercase and
79
+ # will overcome any cross browser differences. If there are no elements in
80
+ # the receiver then the tag name will be an empty string. If there are more
81
+ # than one elements, the tag name will be that of the first element in the
82
+ # collection.
83
+ #
84
+ # @return [String]
85
+ def tag
86
+ `return self[0] ? self[0].tagName.toLowerCase() : '';`
87
+ end
88
+
89
+ # Returns the number of elements in the receiver.
90
+ #
91
+ # @return [Numeric]
92
+ def length
93
+ `return self.length;`
94
+ end
95
+
96
+ alias_method :size, :length
97
+
98
+ # Indexed reference - Returns the matched element at the given index, or
99
+ # returns a slice of elements beginning at the given index for the given
100
+ # count of elements. Negative indecies count backwards from the end of the
101
+ # set of matched elements, so that -1 would be the last matched element.
102
+ # This will return nil if the given index is not in range.
103
+ #
104
+ # TODO: count functionality not yet implemented - only simple index
105
+ # referencing.
106
+ #
107
+ # @param [Numeric] index index to start at
108
+ # @param [Numeric] count last index
109
+ # @return [Element, nil]
110
+ def [](index, count = nil)
111
+ `var size = self.length;
112
+
113
+ if (index < 0) index += size;
114
+
115
+ if (index >= size || index < 0) return nil;
116
+
117
+ return $(self[index]);`
118
+ end
119
+
120
+ # Returns the original selector passed to find the elements. If no selector
121
+ # was given, for example when creating a new object literal, or by passing
122
+ # in a current element, then the selector will just be an empty string.
123
+ #
124
+ # @return [String]
125
+ def selector
126
+ `return self.selector;`
127
+ end
128
+
129
+ # Yields the block for each matched element in the receiver. The block is
130
+ # passed the element as the first param, and the index as the second.
131
+ #
132
+ # @example
133
+ #
134
+ # Element.find('div').each do |elem, idx|
135
+ # puts "at idx #{idx} we found: #{elem}."
136
+ # end
137
+ #
138
+ # @return [Element] returns the receiver
139
+ def each
140
+ `var length = self.length;
141
+
142
+ for (var i = 0; i < length; i++) {
143
+ try {
144
+ #{yield `$(self[i])`, `i`};
145
+ } catch (e) {
146
+ throw e;
147
+ }
148
+ }
149
+
150
+ return self;`
151
+ end
152
+
153
+ # Get or set the value of an attribute for the first element in this set of
154
+ # matched elements. This will only happen for the first matched element, so
155
+ # to apply this to all matches, use {#each} or loop over each item with
156
+ # another construct.
157
+ #
158
+ #
159
+ def attr(name, value = nil)
160
+ if value.nil?
161
+ `self.attr(#{name.to_s}) || ''`
162
+ else
163
+ `self.attr(#{name.to_s}, value)`
164
+ end
165
+ end
166
+
167
+ # Returns the id attr of the first matched element. If the set of elements
168
+ # is empty, then nil is just returned. An optional value may be passed
169
+ # which will be set as the id of the first element. This is the same as
170
+ # setting the id with {#id=} but this allows for chained calls, and it also
171
+ # returns the receiver (to allow for chained calls).
172
+ #
173
+ # @example Retrieving the id
174
+ #
175
+ # Element['div'].id
176
+ # # => 'some_id'
177
+ #
178
+ # @example Setting the id
179
+ #
180
+ # Element['div'].id('new_id')
181
+ # # => #<Element 0x827>
182
+ #
183
+ # @param [String] value optional id to set
184
+ # @return [Element, String]
185
+ def id(value = nil)
186
+ if value
187
+ `return self.attr('id', value);`
188
+ self
189
+ else
190
+ `return self.attr('id');`
191
+ end
192
+ end
193
+
194
+ # Sets the id of the first matched element in the receiver.
195
+ #
196
+ # @example
197
+ #
198
+ # Element['div].id = "some_new_id"
199
+ #
200
+ # @param [String] value the id to set
201
+ # @return [String] returns the set value
202
+ def id=(value)
203
+ `self.attr('id', value)`
204
+ value
205
+ end
206
+
207
+ # Returns the html content of the first matched element in the receiver.
208
+ # If the optional `content` is given, then this will set the html content
209
+ # in the same manner than {#html=} does, except that this method will
210
+ # return the receiver so that it can be used for chaining calls.
211
+ #
212
+ def html(content = nil)
213
+ if content
214
+ `self.html(content)`
215
+ else
216
+ `self.html()`
217
+ end
218
+ end
219
+
220
+ def html=(content)
221
+ `return self.html(content);`
222
+ end
223
+
224
+ # Return the first matched element in the receiver.
225
+ #
226
+ # @return [Element]
227
+ def first
228
+ `return self.first();`
229
+ end
230
+
231
+ # Remove all the child nodes from each of the matched elements in the
232
+ # receiver. This method will remove all text contents of the receiver
233
+ # as well, as they are also text nodes belonging to the receiver. By
234
+ # using jQuery underpinnings, all event listeners of all children are
235
+ # also removed first to avoid memory leaks.
236
+ #
237
+ # @return [Element] returns the receiver
238
+ def clear
239
+ `return self.empty();`
240
+ end
241
+
242
+ alias_method :empty, :clear
243
+
244
+ # Removes the set of matched elements from the DOM. This method works
245
+ # similarly to {#clear}, but the matched element is also removed, as well
246
+ # as its children. Also, like {#clear}, all event handlers are removed
247
+ # first. An optional selector may be passed which removes those children
248
+ # of the matched elements that match the given selector.
249
+ #
250
+ # @return [Element] returns the receiver
251
+ def remove
252
+ `return self.remove();`
253
+ end
254
+
255
+ # Inserts the given content to the end of each element in the set
256
+ # represented by the receiver.
257
+ #
258
+ # @param [String, Element] content content to insert
259
+ # @return [Element] returns the receiver
260
+ def append(content)
261
+ `return self.append(content);`
262
+ end
263
+
264
+ # Inserts the given `content` before each member in the receiver. The
265
+ # content may be a string, or an element.
266
+ #
267
+ # @param [String, Element] content the content to insert
268
+ # @return [Element] returns the receiver
269
+ def before(content)
270
+ `return self.before(content);`
271
+ end
272
+
273
+ # Inserts the `content` before each member in the receiver. Content
274
+ # may be a string or an Element instance.
275
+ #
276
+ # @param [String, Element] content content to insert
277
+ # @return [Element] returns the receiver
278
+ def after(content)
279
+ `return self.after(content);`
280
+ end
281
+
282
+ # @group Events
283
+ def mouse_down
284
+ `return self.mousedown(function(event) {
285
+ #{yield `event`};
286
+ });`
287
+ end
288
+
289
+ # @endgroup
290
+
291
+ end
292
+
@@ -0,0 +1,108 @@
1
+ OpalVM.bridged_class `$.Event.prototype`, 'Event'
2
+
3
+ class Event
4
+
5
+ # Returns the actual element that initiated the event.
6
+ #
7
+ # @return [Element]
8
+ def target
9
+ `return $(self.target);`
10
+ end
11
+ # Returns the current target for the event.
12
+ #
13
+ def current
14
+ `return $(self.currentTarget);`
15
+ end
16
+
17
+ # The type of event that occured.
18
+ #
19
+ # FIXME: for now, these are the raw javascript/jquery names for the events
20
+ # and are not snake_cased. This needs to be fixed.
21
+ def type
22
+ `return self.type;`
23
+ end
24
+
25
+ # If {#prevent_default} has been called on the event, returns `true`,
26
+ # otherwise returns `false`.
27
+ #
28
+ # @example
29
+ #
30
+ # Element['div'].mouse_down do |event|
31
+ # event.default_prevented? # => false
32
+ # event.prevent_default
33
+ # event.default_prevented? # => true
34
+ # end
35
+ #
36
+ # @return [true, false]
37
+ def default_prevented?
38
+ `return self.isDefaultPrevented() ? Qtrue : Qfalse;`
39
+ end
40
+
41
+ # Use this method to stop the default action of the event. For example, this
42
+ # can be used to stop browsers following a href links on a page.
43
+ #
44
+ # @return [Event] returns the receiver
45
+ def prevent_default
46
+ `self.preventDefault()`
47
+ self
48
+ end
49
+
50
+ # Returns `true` if the alt key was pressed during the event, `false`
51
+ # otherwise.
52
+ #
53
+ # @return [true, false]
54
+ def alt?
55
+ `return self.altKey ? Qtrue : Qfalse;`
56
+ end
57
+
58
+ # Returns `true` if the ctrl key was pressed during the event, `false`
59
+ # otherwise.
60
+ #
61
+ # @return [true, false]
62
+ def ctrl?
63
+ `return self.ctrlKey ? Qtrue : Qfalse;`
64
+ end
65
+
66
+ # Returns `true` if the shift key was pressed during the event, `false`
67
+ # otherwise.
68
+ #
69
+ # @return [true, false]
70
+ def shift?
71
+ `return self.shiftKey ? Qtrue : Qfalse;`
72
+ end
73
+
74
+ # Returns `true` if the meta key was pressed during the event, `false`
75
+ # otherwise.
76
+ #
77
+ # @return [true, false]
78
+ def meta?
79
+ `return self.metaKey ? Qtrue : Qfalse;`
80
+ end
81
+
82
+ # Stops the event from propagating up the DOM tree so that parent elements
83
+ # will not receive the event.
84
+ #
85
+ # @return [Event] returns the receiver.
86
+ def stop_propagation
87
+ `self.stopPropagation()`
88
+ self
89
+ end
90
+
91
+ # Returns `true` if {#stop_propagation} was called on the receiver, `false`
92
+ # otherwise.
93
+ #
94
+ # @example
95
+ #
96
+ # Element['div'].mouse_down do |evt|
97
+ # evt.propagation_stopped? # => false
98
+ # evt.stop_propagation
99
+ # evt.propagation_stopped? # => true
100
+ # end
101
+ #
102
+ # @return [true, false]
103
+ def propagation_stopped?
104
+ `return self.isPropagationStopped() ? Qtrue : Qfalse;`
105
+ end
106
+ end
107
+
108
+