opal-browser 0.2.0.beta1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +95 -0
  3. data/.gitignore +3 -0
  4. data/CHANGELOG.md +8 -0
  5. data/Gemfile +17 -3
  6. data/LICENSE +2 -1
  7. data/README.md +183 -52
  8. data/Rakefile +29 -1
  9. data/config.ru +20 -3
  10. data/docs/polyfills.md +24 -0
  11. data/examples/2048/Gemfile +6 -0
  12. data/examples/2048/README.md +13 -0
  13. data/examples/2048/app/application.rb +169 -0
  14. data/examples/2048/config.ru +9 -0
  15. data/examples/canvas/Gemfile +6 -0
  16. data/examples/canvas/README.md +9 -0
  17. data/examples/canvas/app/application.rb +55 -0
  18. data/examples/canvas/config.ru +9 -0
  19. data/examples/component/Gemfile +6 -0
  20. data/examples/component/README.md +10 -0
  21. data/examples/component/app/application.rb +66 -0
  22. data/examples/component/config.ru +9 -0
  23. data/examples/integrations/README.md +24 -0
  24. data/examples/integrations/dynamic-rack-opal-sprockets-server/Gemfile +6 -0
  25. data/examples/integrations/dynamic-rack-opal-sprockets-server/README.md +16 -0
  26. data/examples/integrations/dynamic-rack-opal-sprockets-server/app/application.rb +6 -0
  27. data/examples/integrations/dynamic-rack-opal-sprockets-server/config.ru +9 -0
  28. data/examples/integrations/dynamic-roda-roda-sprockets/.gitignore +1 -0
  29. data/examples/integrations/dynamic-roda-roda-sprockets/Gemfile +7 -0
  30. data/examples/integrations/dynamic-roda-roda-sprockets/README.md +22 -0
  31. data/examples/integrations/dynamic-roda-roda-sprockets/Rakefile +4 -0
  32. data/examples/integrations/dynamic-roda-roda-sprockets/app/application.rb +6 -0
  33. data/examples/integrations/dynamic-roda-roda-sprockets/app.rb +32 -0
  34. data/examples/integrations/dynamic-roda-roda-sprockets/config.ru +3 -0
  35. data/examples/integrations/dynamic-roda-tilt/.gitignore +1 -0
  36. data/examples/integrations/dynamic-roda-tilt/Gemfile +8 -0
  37. data/examples/integrations/dynamic-roda-tilt/README.md +17 -0
  38. data/examples/integrations/dynamic-roda-tilt/Rakefile +6 -0
  39. data/examples/integrations/dynamic-roda-tilt/app/application.rb +6 -0
  40. data/examples/integrations/dynamic-roda-tilt/app.rb +50 -0
  41. data/examples/integrations/dynamic-roda-tilt/config.ru +3 -0
  42. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/Gemfile +7 -0
  43. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/README.md +16 -0
  44. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/app/application.rb +6 -0
  45. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/config.ru +29 -0
  46. data/examples/integrations/static-bash/.gitignore +2 -0
  47. data/examples/integrations/static-bash/Gemfile +3 -0
  48. data/examples/integrations/static-bash/README.md +8 -0
  49. data/examples/integrations/static-bash/app/application.rb +6 -0
  50. data/examples/integrations/static-bash/build.sh +4 -0
  51. data/examples/integrations/static-bash/index.html +10 -0
  52. data/examples/integrations/static-bash-opal-parser/.gitignore +3 -0
  53. data/examples/integrations/static-bash-opal-parser/Gemfile +3 -0
  54. data/examples/integrations/static-bash-opal-parser/README.md +10 -0
  55. data/examples/integrations/static-bash-opal-parser/build.sh +4 -0
  56. data/examples/integrations/static-bash-opal-parser/index.html +19 -0
  57. data/examples/integrations/static-rake/.gitignore +1 -0
  58. data/examples/integrations/static-rake/Gemfile +4 -0
  59. data/examples/integrations/static-rake/README.md +7 -0
  60. data/examples/integrations/static-rake/Rakefile +10 -0
  61. data/examples/integrations/static-rake/app/application.rb +6 -0
  62. data/examples/integrations/static-rake/index.html +9 -0
  63. data/examples/integrations/static-rake-guard/.gitignore +1 -0
  64. data/examples/integrations/static-rake-guard/Gemfile +6 -0
  65. data/examples/integrations/static-rake-guard/Guardfile +3 -0
  66. data/examples/integrations/static-rake-guard/README.md +10 -0
  67. data/examples/integrations/static-rake-guard/Rakefile +10 -0
  68. data/examples/integrations/static-rake-guard/app/application.rb +6 -0
  69. data/examples/integrations/static-rake-guard/index.html +9 -0
  70. data/examples/svg/.gitignore +1 -0
  71. data/examples/svg/Gemfile +4 -0
  72. data/examples/svg/README.md +7 -0
  73. data/examples/svg/Rakefile +10 -0
  74. data/examples/svg/app/application.rb +11 -0
  75. data/examples/svg/index.html +17 -0
  76. data/examples/svg/index.svg +6 -0
  77. data/index.html.erb +8 -6
  78. data/lib/opal-browser.rb +1 -0
  79. data/opal/browser/animation_frame.rb +26 -1
  80. data/opal/browser/audio/node.rb +121 -0
  81. data/opal/browser/audio/param_schedule.rb +43 -0
  82. data/opal/browser/audio.rb +66 -0
  83. data/opal/browser/blob.rb +94 -0
  84. data/opal/browser/canvas/data.rb +1 -11
  85. data/opal/browser/canvas/gradient.rb +1 -11
  86. data/opal/browser/canvas/style.rb +3 -11
  87. data/opal/browser/canvas/text.rb +1 -11
  88. data/opal/browser/canvas.rb +17 -13
  89. data/opal/browser/console.rb +3 -1
  90. data/opal/browser/cookies.rb +78 -42
  91. data/opal/browser/crypto.rb +79 -0
  92. data/opal/browser/css/declaration.rb +1 -1
  93. data/opal/browser/css/rule.rb +1 -1
  94. data/opal/browser/css/style_sheet.rb +2 -2
  95. data/opal/browser/css.rb +23 -7
  96. data/opal/browser/database/sql.rb +193 -0
  97. data/opal/browser/delay.rb +41 -7
  98. data/opal/browser/dom/attribute.rb +13 -12
  99. data/opal/browser/dom/builder.rb +31 -17
  100. data/opal/browser/dom/document.rb +174 -42
  101. data/opal/browser/dom/document_fragment.rb +18 -0
  102. data/opal/browser/dom/document_or_shadow_root.rb +19 -0
  103. data/opal/browser/dom/element/attributes.rb +111 -0
  104. data/opal/browser/dom/element/button.rb +31 -0
  105. data/opal/browser/dom/element/custom.rb +177 -0
  106. data/opal/browser/dom/element/data.rb +82 -0
  107. data/opal/browser/dom/element/editable.rb +47 -0
  108. data/opal/browser/dom/element/form.rb +38 -0
  109. data/opal/browser/dom/element/iframe.rb +37 -0
  110. data/opal/browser/dom/element/image.rb +2 -0
  111. data/opal/browser/dom/element/input.rb +48 -1
  112. data/opal/browser/dom/element/media.rb +17 -0
  113. data/opal/browser/dom/element/offset.rb +5 -0
  114. data/opal/browser/dom/element/position.rb +11 -2
  115. data/opal/browser/dom/element/scroll.rb +123 -24
  116. data/opal/browser/dom/element/select.rb +42 -0
  117. data/opal/browser/dom/element/size.rb +17 -0
  118. data/opal/browser/dom/element/template.rb +11 -0
  119. data/opal/browser/dom/element/textarea.rb +26 -0
  120. data/opal/browser/dom/element.rb +468 -238
  121. data/opal/browser/dom/mutation_observer.rb +4 -4
  122. data/opal/browser/dom/node.rb +142 -60
  123. data/opal/browser/dom/node_set.rb +73 -44
  124. data/opal/browser/dom/shadow_root.rb +12 -0
  125. data/opal/browser/dom/text.rb +2 -2
  126. data/opal/browser/dom.rb +40 -16
  127. data/opal/browser/effects.rb +180 -3
  128. data/opal/browser/event/all.rb +26 -0
  129. data/opal/browser/{dom/event → event}/animation.rb +4 -2
  130. data/opal/browser/{dom/event → event}/audio_processing.rb +4 -2
  131. data/opal/browser/{dom/event → event}/base.rb +98 -9
  132. data/opal/browser/{dom/event → event}/before_unload.rb +4 -2
  133. data/opal/browser/{dom/event → event}/clipboard.rb +11 -2
  134. data/opal/browser/{dom/event → event}/close.rb +4 -2
  135. data/opal/browser/{dom/event → event}/composition.rb +4 -2
  136. data/opal/browser/{dom/event → event}/custom.rb +3 -3
  137. data/opal/browser/event/data_transfer.rb +95 -0
  138. data/opal/browser/{dom/event → event}/device_light.rb +4 -2
  139. data/opal/browser/{dom/event → event}/device_motion.rb +4 -2
  140. data/opal/browser/{dom/event → event}/device_orientation.rb +4 -2
  141. data/opal/browser/{dom/event → event}/device_proximity.rb +4 -2
  142. data/opal/browser/{dom/event → event}/drag.rb +11 -7
  143. data/opal/browser/{dom/event → event}/focus.rb +4 -2
  144. data/opal/browser/{dom/event → event}/gamepad.rb +5 -3
  145. data/opal/browser/{dom/event → event}/hash_change.rb +4 -2
  146. data/opal/browser/{dom/event → event}/keyboard.rb +16 -3
  147. data/opal/browser/{dom/event → event}/message.rb +4 -2
  148. data/opal/browser/{dom/event → event}/mouse.rb +12 -8
  149. data/opal/browser/{dom/event → event}/page_transition.rb +4 -2
  150. data/opal/browser/{dom/event → event}/pop_state.rb +4 -2
  151. data/opal/browser/{dom/event → event}/progress.rb +4 -2
  152. data/opal/browser/{dom/event → event}/sensor.rb +4 -2
  153. data/opal/browser/{dom/event → event}/storage.rb +4 -2
  154. data/opal/browser/{dom/event → event}/touch.rb +4 -2
  155. data/opal/browser/{dom/event → event}/ui.rb +2 -2
  156. data/opal/browser/{dom/event → event}/wheel.rb +4 -2
  157. data/opal/browser/event.rb +163 -0
  158. data/opal/browser/event_source.rb +2 -2
  159. data/opal/browser/form_data.rb +225 -0
  160. data/opal/browser/history.rb +4 -8
  161. data/opal/browser/http/binary.rb +1 -0
  162. data/opal/browser/http/headers.rb +16 -2
  163. data/opal/browser/http/request.rb +46 -48
  164. data/opal/browser/http/response.rb +5 -1
  165. data/opal/browser/http.rb +25 -2
  166. data/opal/browser/immediate.rb +9 -5
  167. data/opal/browser/interval.rb +34 -11
  168. data/opal/browser/location.rb +7 -1
  169. data/opal/browser/navigator.rb +127 -7
  170. data/opal/browser/polyfill/visual_viewport.rb +216 -0
  171. data/opal/browser/screen.rb +3 -3
  172. data/opal/browser/setup/base.rb +6 -0
  173. data/opal/browser/setup/full.rb +13 -0
  174. data/opal/browser/setup/large.rb +17 -0
  175. data/opal/browser/setup/mini.rb +8 -0
  176. data/opal/browser/setup/traditional.rb +10 -0
  177. data/opal/browser/socket.rb +8 -4
  178. data/opal/browser/storage.rb +53 -35
  179. data/opal/browser/support.rb +72 -5
  180. data/opal/browser/utils.rb +94 -14
  181. data/opal/browser/version.rb +1 -1
  182. data/opal/browser/visual_viewport.rb +39 -0
  183. data/opal/browser/window/size.rb +31 -3
  184. data/opal/browser/window/view.rb +15 -0
  185. data/opal/browser/window.rb +46 -25
  186. data/opal/browser.rb +1 -10
  187. data/opal/opal-browser.rb +1 -0
  188. data/opal-browser.gemspec +3 -3
  189. data/spec/database/sql_spec.rb +139 -0
  190. data/spec/delay_spec.rb +41 -0
  191. data/spec/dom/attribute_spec.rb +49 -0
  192. data/spec/dom/builder_spec.rb +25 -8
  193. data/spec/dom/document_spec.rb +22 -0
  194. data/spec/dom/element/attributes_spec.rb +52 -0
  195. data/spec/dom/element/custom_spec.rb +106 -0
  196. data/spec/dom/element/subclass_spec.rb +144 -0
  197. data/spec/dom/element_spec.rb +181 -4
  198. data/spec/dom/mutation_observer_spec.rb +12 -8
  199. data/spec/dom/node_set_spec.rb +44 -0
  200. data/spec/dom/node_spec.rb +48 -0
  201. data/spec/dom_spec.rb +8 -0
  202. data/spec/event_source_spec.rb +15 -12
  203. data/spec/{dom/event_spec.rb → event_spec.rb} +44 -15
  204. data/spec/history_spec.rb +23 -19
  205. data/spec/http_spec.rb +19 -31
  206. data/spec/immediate_spec.rb +5 -4
  207. data/spec/interval_spec.rb +59 -0
  208. data/spec/native_cached_wrapper_spec.rb +46 -0
  209. data/spec/runner.rb +62 -69
  210. data/spec/socket_spec.rb +16 -12
  211. data/spec/spec_helper.rb +2 -5
  212. data/spec/spec_helper_promise.rb.erb +25 -0
  213. data/spec/storage_spec.rb +1 -1
  214. metadata +172 -50
  215. data/.travis.yml +0 -60
  216. data/opal/browser/dom/event.rb +0 -253
  217. data/opal/browser/http/parameters.rb +0 -8
  218. data/opal/browser/window/scroll.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7b0aa6c5110fd5e167607dbdea62c227163d95be
4
- data.tar.gz: 666fc17d0cb5be69e9acf8a2f2d526e4995b7496
2
+ SHA256:
3
+ metadata.gz: 16a070e0b1c644fc54d33c3266f0c470a920cac127bc4b37ede951f55f76517f
4
+ data.tar.gz: 7895a72bebd9b3528fcd1b714a603355f83b9fb3c34ea610f3bc4157a5eb8b93
5
5
  SHA512:
6
- metadata.gz: bdb5103e7c85d23815225544ee28a504a024cc61beb58c5ca77e1af6c0b33853c6bc0b5cc530975039f28151572b423725e6abc7bf5aa22bd4fe82ec4ef68ed8
7
- data.tar.gz: 4c08aa42993c6e63623dae9d5b9b09ed722801bf771c1527c56bb0791807958ffbb2d5c80904ae457c0686cf15ea597176de7269f9862a0d014f7171d7597f35
6
+ metadata.gz: 3e08c691cfc2f4c633c3467a7ed8059690ded3bbcf3759e2c5b5333f220f67752caf4d13316dd956e87304f192732ca027434810b1c6a0f77cc7e039fa5fa871
7
+ data.tar.gz: d724afddb0f157fe632275195ca01bc776129442cce3876fb0d6aea2d30202e81d0240c4666b5fe76837f5671398efa63f648f61e518fc7b7a7017fccb1817e7
@@ -0,0 +1,95 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ - "*-stable"
8
+ - "*/ci-check"
9
+ pull_request: {}
10
+
11
+ jobs:
12
+ rake:
13
+ name: ${{ matrix.combo.name }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ combo:
18
+ - name: Chromium/Linux/Opal-master
19
+ browser: chrome
20
+ os: ubuntu-latest
21
+ opal: master
22
+ - name: Chromium/Linux/Opal-1.3/PromiseV2
23
+ browser: chrome
24
+ os: ubuntu-latest
25
+ opal: 1.3
26
+ promise: v2
27
+ - name: Chromium/Linux/Opal-1.3
28
+ browser: chrome
29
+ os: ubuntu-latest
30
+ opal: 1.3
31
+ - name: Chromium/Linux/Opal-1.2
32
+ browser: chrome
33
+ os: ubuntu-latest
34
+ opal: 1.2
35
+ - name: Chromium/Linux/Opal-1.0
36
+ browser: chrome
37
+ os: ubuntu-latest
38
+ opal: '1.0'
39
+ - name: Chromium/Linux/Ruby-2.7
40
+ browser: chrome
41
+ os: ubuntu-latest
42
+ ruby: 2.7
43
+ - name: Chromium/Linux/Ruby-2.6
44
+ browser: chrome
45
+ os: ubuntu-latest
46
+ ruby: 2.6
47
+ - name: Firefox/Linux
48
+ browser: gecko
49
+ os: ubuntu-latest
50
+ - name: Chromium/Windows
51
+ browser: chrome
52
+ os: windows-latest
53
+ - name: Firefox/Windows
54
+ browser: gecko
55
+ os: windows-latest
56
+ - name: Edge/Windows
57
+ browser: edge
58
+ os: windows-latest
59
+ - name: Chromium/macOS
60
+ browser: chrome
61
+ os: macos-latest
62
+ - name: Firefox/macOS
63
+ browser: gecko
64
+ os: macos-latest
65
+ - name: Safari/macOS
66
+ browser: safari
67
+ os: macos-latest
68
+
69
+ runs-on: ${{ matrix.combo.os }}
70
+
71
+ steps:
72
+ - uses: actions/checkout@v2
73
+ - name: set environment variables
74
+ run: |
75
+ echo "OPAL_VERSION=${{ matrix.combo.opal || '1.3' }}" >> $GITHUB_ENV
76
+ echo "OPAL_BROWSER_PROMISE=${{ matrix.combo.promise || 'v1' }}" >> $GITHUB_ENV
77
+ - uses: ruby/setup-ruby@v1
78
+ with:
79
+ ruby-version: ${{ matrix.combo.ruby || '3.0' }}
80
+ - run: bundle lock
81
+ - uses: actions/cache@v2
82
+ with:
83
+ path: ./vendor/bundle
84
+ key: ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.2.0.beta1' }}-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
85
+ restore-keys: |
86
+ ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.2.0.beta1' }}-${{ github.ref }}
87
+ ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.2.0.beta1' }}-master
88
+ ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.2.0.beta1' }}-
89
+ ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-
90
+ - name: bundle install
91
+ run: |
92
+ bundle config path $PWD/vendor/bundle
93
+ bundle install --jobs 4 --retry 3
94
+ bundle clean
95
+ - run: bundle exec rake selenium_${{ matrix.combo.browser }}
data/.gitignore CHANGED
@@ -3,3 +3,6 @@ vendor
3
3
  .bundle
4
4
  copycat
5
5
  doc
6
+ .yardoc
7
+ screenshot.png
8
+ /pkg
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.3.2
2
+ * Cookie: refactor the module
3
+ * Note in documentation it's available as `$document.cookies` and it's the preferred way to access it
4
+ * Always encode a cookie with JSON, unless a new parameter `raw:` is provided
5
+
6
+ ## 0.3.1
7
+ * Element#inner_dom: Reduce flickering - first build tree, then insert it
8
+ * NodeSet#to_a to be aliased to #to_ary
data/Gemfile CHANGED
@@ -2,15 +2,29 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  # specs
5
+ gem 'rake'
5
6
  gem 'rack'
6
7
  gem 'sinatra'
7
8
  gem 'sinatra-websocket'
8
- gem 'opal-rspec', '0.3.0.beta3'
9
+ gem 'opal-rspec'
10
+ gem 'opal-sprockets'
11
+ # Force build of eventmachine... I wish we could find a way to not use
12
+ # this unmaintained library anymore.
13
+ gem 'eventmachine', github: 'eventmachine/eventmachine'
14
+ gem 'thin', github: 'macournoyer/thin' unless RUBY_PLATFORM =~ /mingw/
9
15
 
10
16
  # runner
11
17
  gem 'selenium-webdriver', require: false
12
18
  gem 'rest-client', require: false
19
+ gem 'webdrivers', require: false
20
+ gem 'rexml', require: false
13
21
 
14
22
  # browser
15
- gem 'opal', github: 'opal/opal'
16
- gem 'paggio', github: 'meh/paggio'
23
+ case ENV['OPAL_VERSION']
24
+ when nil
25
+ when /\./
26
+ gem 'opal', "~> #{ENV['OPAL_VERSION']}.0a"
27
+ else
28
+ gem 'opal', github: 'opal/opal', ref: ENV['OPAL_VERSION']
29
+ end
30
+
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (C) 2014 by meh
1
+ Copyright (C) 2013-2018 by meh
2
+ Copyright (C) 2019-2021 hmdne and the Opal-Browser contributors
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,16 +1,84 @@
1
- Browser support for Opal
2
- ========================
1
+ Opal-Browser - Client side web development in pure Ruby, using Opal
2
+ ===================================================================
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/opal/opal-browser.png?branch=master)](http://travis-ci.org/opal/opal-browser)
5
- [![Gem Version](https://badge.fury.io/rb/opal-browser.png)](http://badge.fury.io/rb/opal-browser)
6
- [![Code Climate](https://codeclimate.com/github/opal/opal-browser.png)](https://codeclimate.com/github/opal/opal-browser)
4
+ [![Gem Version](https://badge.fury.io/rb/opal-browser.svg)](http://badge.fury.io/rb/opal-browser)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability-percentage/opal/opal-browser.svg)](https://codeclimate.com/github/opal/opal-browser)
6
+ [![Build Status](https://github.com/opal/opal-browser/workflows/build/badge.svg)](https://github.com/opal/opal-browser/actions?query=workflow%3Abuild)
7
+ [![Join Chat](https://img.shields.io/badge/slack-join%20chat-46BC99?logo=slack&style=flat)](https://slack.opalrb.com/)
8
+ [![Stack Overflow](https://img.shields.io/badge/stackoverflow-%23opalrb-orange.svg?style=flat)](https://stackoverflow.com/questions/ask?tags=opalrb,opal-browser)
9
+ [![Documentation](https://img.shields.io/badge/docs-updated-blue.svg)](https://rubydoc.info/gems/opal-browser)
7
10
 
8
- This library aims to be a full-blown wrapper for all the browser API including
11
+ This library aims to be a full-blown wrapper for all the browser API as defined by
9
12
  HTML5.
10
13
 
14
+ It provides a very JQuery-like interface to DOM, but itself it doesn't use nor
15
+ require JQuery nor opal-jquery (which is an alternative library for interfacing
16
+ the web browser). The main difference though is that Opal-Browser goes far beyond
17
+ what JQuery does.
18
+
19
+ Usage
20
+ =====
21
+
22
+ _Gemfile_
23
+
24
+ ```ruby
25
+ source 'https://rubygems.org/'
26
+
27
+ gem 'opal-browser'
28
+ ```
29
+
30
+ _Server side (config.ru, Rakefile, Rails, Sinatra, Roda, etc. - not needed for static compilation)_
31
+
32
+ ```ruby
33
+ require 'opal-browser'
34
+ # Your server code here
35
+ ```
36
+
37
+ _Browser side_
38
+
39
+ ```ruby
40
+ require 'opal'
41
+ require 'native'
42
+ require 'promise'
43
+ require 'browser/setup/full'
44
+
45
+ # Your Opal code here
46
+ $document.body << "Hello world!"
47
+ ```
48
+
49
+ _Static Compile Opal + Opal-Browser library_
50
+
51
+ ```bash
52
+ bundle exec opal -c -q opal-browser -p native -p promise -p browser/setup/full -e '#' -E > opal-browser.js
53
+ ```
54
+
55
+ _Static Compile your application_
56
+
57
+ ```bash
58
+ bundle exec opal -Oc -s opal -s native -s promise -s browser/setup/full app/application.rb > application.js
59
+ ```
60
+
61
+ _And load it in HTML!_
62
+
63
+ ```html
64
+ <!DOCTYPE html>
65
+ <html>
66
+ <head>
67
+ <title>My Application</title>
68
+ </head>
69
+ <body>
70
+ <script src='opal-browser.js' onload='Opal.require("native"); Opal.require("promise"); Opal.require("browser/setup/full");'></script>
71
+ <script src='application.js'></script>
72
+ </body>
73
+ </html>
74
+ ```
75
+
76
+ See the `examples/integrations/` directory for various ideas on how to quickly start
77
+ development using opal-browser.
78
+
11
79
  Features
12
80
  ========
13
- This is a list of the currently wrapped features and some details on them.
81
+ This is a list of many currently wrapped features and some details on them.
14
82
 
15
83
  DOM
16
84
  ---
@@ -18,16 +86,16 @@ DOM support is complete as far as I know, it has a very Nokogiri feel to it
18
86
  with obvious differences where relevant (for instance, event handling).
19
87
 
20
88
  ```ruby
21
- $document.on 'dom:load' do
89
+ $document.ready do
22
90
  alert "yo dawg, I'm all loaded up in here"
23
91
  end
24
92
  ```
25
93
 
26
- It also supports a markaby inspired builder DSL which generates DOM nodes
27
- directly instead of creating a string.
94
+ It also supports a markaby inspired builder DSL (using Paggio) which generates
95
+ DOM nodes directly instead of creating a string.
28
96
 
29
97
  ```ruby
30
- $document.on 'dom:load' do
98
+ $document.ready do
31
99
  DOM {
32
100
  div.info {
33
101
  span.red "I'm all cooked up."
@@ -36,12 +104,38 @@ $document.on 'dom:load' do
36
104
  end
37
105
  ```
38
106
 
107
+ Events
108
+ ------
109
+
110
+ Add an event to a given element:
111
+
112
+ ```ruby
113
+ $document.at_css("button").on(:click) do |e|
114
+ e.prevent # Prevent the default action (eg. form submission)
115
+ # You can also use `e.stop` to stop propagating the event to other handlers.
116
+ alert "Button clicked!"
117
+ end
118
+ ```
119
+
120
+ Or add it to a parent element and use a delegator, so that an event gets fired
121
+ when any button children of `$document` is clicked:
122
+
123
+ ```ruby
124
+ $document.on(:click, "button") do |e|
125
+ e.prevent
126
+ # e.on is a button that has been clicked
127
+ e.on.inner_text = "Clicked!"
128
+ end
129
+ ```
130
+
131
+ Run an event once with `#one` instead of `#on`, or disable an event with `#off`.
132
+
39
133
  CSSOM
40
134
  -----
41
- CSSOM support is still incomplete but the useful parts are implemented, this
42
- includes a DSL for generating a CSS style and the same DSL is also used to
43
- change style declarations (which can either belong to a `DOM::Element` or a
44
- `CSS::Rule::Style`).
135
+ CSSOM support (using Paggio) is still incomplete but the useful parts are
136
+ implemented, this includes a DSL for generating a CSS style and the same DSL
137
+ is also used to change style declarations (which can either belong to a
138
+ `DOM::Element` or a `CSS::Rule::Style`).
45
139
 
46
140
  ```ruby
47
141
  $document.body.style.apply {
@@ -59,6 +153,8 @@ supports binary results as typed-arrays.
59
153
  It easily allows for synchronous and asynchronous requests.
60
154
 
61
155
  ```ruby
156
+ require 'browser/http'
157
+
62
158
  Browser::HTTP.get "/something.json" do
63
159
  on :success do |res|
64
160
  alert res.json.inspect
@@ -72,6 +168,8 @@ Websockets have been fully wrapped and they are easily configurable with
72
168
  blocks.
73
169
 
74
170
  ```ruby
171
+ require 'browser/socket'
172
+
75
173
  Browser::Socket.new 'ws://echo.websocket.org' do
76
174
  on :open do
77
175
  every 1 do
@@ -89,67 +187,100 @@ EventSource
89
187
  -----------
90
188
  Event sources have been implemented and are easily configurable with blocks.
91
189
 
190
+ ```ruby
191
+ require 'browser/event_source'
192
+
193
+ Browser::EventSource.new '/events' do |es|
194
+ es.on :message do |e|
195
+ alert e.data
196
+ end
197
+
198
+ es.on :custom do |e|
199
+ alert "custom #{e.data}"
200
+ end
201
+ end
202
+ ```
203
+
92
204
  History
93
205
  -------
94
206
  The HTML5 History API has been fully wrapped.
95
207
 
208
+ ```ruby
209
+ current = $window.history.current
210
+ $window.history.replace("?get=params")
211
+ $window.history.push("?get=params")
212
+ $window.history.back
213
+
214
+ $window.on :popstate do |e|
215
+ p "User clicked a back button! He is now on #{$window.history.current}"
216
+ end
217
+ ```
218
+
96
219
  Storage
97
220
  -------
98
221
  The HTML5 Storage API has been wrapped and it exports a single Storage class
99
222
  that uses the most appropriate and available API to store data locally.
100
223
 
101
- Browser support
102
- ===============
103
-
104
- * Internet Explorer 6+
105
- * Firefox (Current - 1) or Current
106
- * Chrome (Current - 1) or Current
107
- * Safari 5.1+
108
- * Opera 12.1x or (Current - 1) or Current
109
-
110
- Any problem above browsers should be considered and reported as a bug.
224
+ ```ruby
225
+ require 'browser/storage'
111
226
 
112
- (Current - 1) or Current denotes that we support the current stable version of
113
- the browser and the version that preceded it. For example, if the current
114
- version of a browser is 24.x, we support the 24.x and 23.x versions.
227
+ $storage = $window.storage
228
+ $storage[:hello] = "world"
229
+ ```
115
230
 
116
- 12.1x or (Current - 1) or Current denotes that we support Opera 12.1x as well
117
- as last 2 versions of Opera. For example, if the current Opera version is 20.x,
118
- we support Opera 12.1x, 19.x and 20.x but not Opera 15.x through 18.x.
231
+ Database SQL
232
+ ------------
233
+ WebSQL has been fully wrapped (Chromium-only)
119
234
 
120
- Cross-browser testing sponsored by [BrowserStack](http://browserstack.com).
235
+ ```ruby
236
+ require 'browser/database/sql'
237
+
238
+ db = Browser::Database::SQL.new 'test'
239
+ db.transaction {|t|
240
+ t.query('CREATE TABLE test(ID INTEGER PRIMARY KEY ASC, text TEXT)').then {
241
+ t.query('INSERT INTO test (id, text) VALUES(?, ?)', 1, 'huehue')
242
+ }.then {
243
+ t.query('INSERT INTO test (id, text) VALUES(?, ?)', 2, 'jajaja')
244
+ }.then {
245
+ t.query('SELECT * FROM test')
246
+ }.then {|r|
247
+ r.each {|row|
248
+ alert row.inspect
249
+ }
250
+ }
251
+ }
252
+ ```
121
253
 
122
- CSS selectors
123
- -------------
124
- Older browsers do not support CSS selector in queries, this means you'll need
125
- external polyfills for this.
254
+ Browser support
255
+ ===============
126
256
 
127
- The suggested polyfill is [Sizzle](http://sizzlejs.com/), require it **before**
128
- opal-browser.
257
+ * Edge (Current - 3) to Current
258
+ * Firefox (Current - 3) to Current
259
+ * Chrome (Current - 3) to Current
260
+ * Safari (Current - 3) to Current
261
+ * Opera (Current - 3) to Current
129
262
 
130
- JSON parsing
131
- ------------
132
- Older browsers don't support JSON parsing natively, this means you'll need
133
- external polyfills for this.
263
+ Any problem above browsers should be considered and reported as a bug.
134
264
 
135
- The suggested polyfill is [json2](https://github.com/douglascrockford/JSON-js),
136
- require it **before** opal-browser.
265
+ (Current - 3) to Current denotes that we support the current major stable version
266
+ of the browser and 3 versions preceding it. For example, if the current version
267
+ of a browser is 24.x, we support all versions between 21.x to 24.x.
137
268
 
138
- XPath support
139
- -------------
140
- Not all browsers support XPath queries, I'm looking at you Internet Explorer,
141
- this means you'll need external polyfills for this.
269
+ We will accept compatibility patches for even earlier browser versions. Opal-Browser
270
+ is written in such a way, that it integrates a robust compatibility check system,
271
+ similar to Modernizr, and the history of this library goes even as far as supporting
272
+ Internet Explorer 6.
142
273
 
143
- The suggested polyfill is
144
- [wgxpath](https://code.google.com/p/wicked-good-xpath/), require it **before**
145
- opal-browser.
274
+ See the [polyfills documentation](docs/polyfills.md) if you wish to polyfill some
275
+ behaviors not supported by the ancient web browsers (like `querySelectorAll`).
146
276
 
147
277
  License
148
278
  =======
149
279
 
150
280
  (The MIT License)
151
281
 
152
- Copyright (C) 2014 by meh
282
+ Copyright (C) 2013-2018 by meh<br>
283
+ Copyright (C) 2019-2021 hmdne and the Opal-Browser contributors
153
284
 
154
285
  Permission is hereby granted, free of charge, to any person obtaining a copy
155
286
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,5 +1,33 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'webdrivers'
6
+ load 'webdrivers/Rakefile'
3
7
 
4
8
  require 'opal/rspec/rake_task'
5
- Opal::RSpec::RakeTask.new(:default)
9
+ Opal::RSpec::RakeTask.new(:broken_rspec) do |_, task|
10
+ task.default_path = 'spec'
11
+ task.pattern = 'spec/**/*_spec.{rb,opal}'
12
+ end
13
+
14
+ task(:nil) {}
15
+
16
+ %w[chrome edge gecko safari].each do |i|
17
+ dependency = nil
18
+ if %w[chrome edge gecko].include? i
19
+ dependency = "webdrivers:#{i}driver:update"
20
+ end
21
+ desc "Run Selenium tests with #{i}"
22
+ task :"selenium_#{i}" => dependency do
23
+ server = Process.spawn("bundle", "exec", "rackup")
24
+ at_exit { Process.kill(9, server) rescue nil }
25
+ sleep 2
26
+ ENV['BROWSER'] = i
27
+ load 'spec/runner.rb'
28
+ ensure
29
+ Process.kill(9, server) rescue nil
30
+ end
31
+ end
32
+
33
+ task :default => :selenium_chrome
data/config.ru CHANGED
@@ -2,11 +2,17 @@ require 'bundler'
2
2
  Bundler.require
3
3
 
4
4
  apps = []
5
- apps << Opal::Server.new { |s|
6
- s.append_path 'spec'
5
+
6
+ sprockets_env = Opal::RSpec::SprocketsEnvironment.new(spec_pattern = 'spec/**/*_spec.{rb,opal}',
7
+ spec_exclude_pattern = nil,
8
+ spec_files = nil,
9
+ default_path = 'spec')
10
+
11
+ apps << Opal::Sprockets::Server.new(sprockets: sprockets_env) { |s|
7
12
  s.main = 'opal/rspec/sprockets_runner'
13
+ s.append_path 'spec'
8
14
  s.index_path = 'index.html.erb'
9
- s.debug = false
15
+ s.debug = true
10
16
  }
11
17
 
12
18
  apps << Class.new(Sinatra::Base) {
@@ -34,6 +40,17 @@ apps << Class.new(Sinatra::Base) {
34
40
  "lol"
35
41
  end
36
42
 
43
+ post '/http-file' do
44
+ if params['lol'] == 'wut' &&
45
+ params['file'][:filename] == 'yay.txt' &&
46
+ params['file'][:tempfile].read == 'content'
47
+
48
+ "ok"
49
+ else
50
+ "fail"
51
+ end
52
+ end
53
+
37
54
  get '/events' do
38
55
  headers 'Content-Type' => 'text/event-stream'
39
56
 
data/docs/polyfills.md ADDED
@@ -0,0 +1,24 @@
1
+ CSS selectors
2
+ -------------
3
+ Older browsers do not support CSS selector in queries, this means you'll need
4
+ external polyfills for this.
5
+
6
+ The suggested polyfill is [Sizzle](http://sizzlejs.com/), require it **before**
7
+ opal-browser.
8
+
9
+ JSON parsing
10
+ ------------
11
+ Older browsers don't support JSON parsing natively, this means you'll need
12
+ external polyfills for this.
13
+
14
+ The suggested polyfill is [json2](https://github.com/douglascrockford/JSON-js),
15
+ require it **before** opal-browser.
16
+
17
+ XPath support
18
+ -------------
19
+ Not all browsers support XPath queries, I'm looking at you Internet Explorer,
20
+ this means you'll need external polyfills for this.
21
+
22
+ The suggested polyfill is
23
+ [wgxpath](https://code.google.com/p/wicked-good-xpath/), require it **before**
24
+ opal-browser.
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "opal-sprockets"
4
+ gem "puma"
5
+ gem "rack"
6
+ gem "opal-browser", path: "../.."
@@ -0,0 +1,13 @@
1
+ 2048 clone with Opal-Browser
2
+ ============================
3
+
4
+ A 167 line implementation of 2048, but in Ruby inside a browser!
5
+
6
+ To install, run:
7
+
8
+ $ bundle install
9
+
10
+ Start server
11
+ ------------
12
+
13
+ $ bundle exec rackup