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.svg?branch=master )] ( http://travis-ci.org/opal/opal-browser )
5
4
[ ![ Gem Version] ( https://badge.fury.io/rb/opal-browser.svg )] ( http://badge.fury.io/rb/opal-browser )
6
5
[ ![ Code Climate] ( http://img.shields.io/codeclimate/github/opal/opal-browser.svg )] ( https://codeclimate.com/github/opal/opal-browser )
7
6
8
7
9
- This library aims to be a full-blown wrapper for all the browser API including
8
+ This library aims to be a full-blown wrapper for all the browser API as defined by
10
9
HTML5.
11
10
11
+ It provides a very JQuery-like interface to DOM, but itself it doesn't use nor
12
+ require JQuery nor opal-jquery (which is an alternative library for interfacing
13
+ the web browser). The main difference though is that Opal-Browser goes far beyond
14
+ what JQuery does.
15
+
12
16
Usage
13
17
=====
14
18
15
- _ Server side (config.ru, Rakefile, Rails, Sinatra, etc.)_
19
+ _ Gemfile_
20
+
21
+ ``` ruby
22
+ source ' https://rubygems.org/'
23
+
24
+ gem ' paggio' , github: ' hmdne/paggio'
25
+ gem ' opal-browser'
26
+ ```
27
+
28
+ _ Server side (config.ru, Rakefile, Rails, Sinatra, Roda, etc. - not needed for static compilation)_
16
29
17
30
``` ruby
18
31
require ' opal-browser'
@@ -23,18 +36,47 @@ _Browser side_
23
36
24
37
``` ruby
25
38
require ' opal'
26
- require ' browser'
39
+ require ' native'
40
+ require ' promise'
41
+ require ' browser/setup/full'
42
+
27
43
# Your Opal code here
44
+ $document .body << " Hello world!"
28
45
```
29
46
30
- _ Static Compile JS_
47
+ _ Static Compile Opal + Opal-Browser library_
48
+
31
49
``` bash
32
- opal -I ./ opal --gem paggio --compile opal/ browser.rb > browser.js
50
+ bundle exec opal -c -q opal-browser -p native -p promise -p browser/setup/full -e ' # ' -E > opal- browser.js
33
51
```
34
52
53
+ _ Static Compile your application_
54
+
55
+ ``` bash
56
+ bundle exec opal -Oc -s opal -s native -s promise -s browser/setup/full app/application.rb > application.js
57
+ ```
58
+
59
+ _ And load it in HTML!_
60
+
61
+ ``` html
62
+ <!DOCTYPE html>
63
+ <html >
64
+ <head >
65
+ <title >My Application</title >
66
+ </head >
67
+ <body >
68
+ <script src =' opal-browser.js' onload =' Opal.require("native"); Opal.require("promise"); Opal.require("browser/setup/full");' ></script >
69
+ <script src =' application.js' ></script >
70
+ </body >
71
+ </html >
72
+ ```
73
+
74
+ See the examples/integrations/ directory for various ideas on how to quickly start
75
+ development using opal-browser.
76
+
35
77
Features
36
78
========
37
- This is a list of the currently wrapped features and some details on them.
79
+ This is a list of many currently wrapped features and some details on them.
38
80
39
81
DOM
40
82
---
@@ -47,8 +89,8 @@ $document.ready do
47
89
end
48
90
```
49
91
50
- It also supports a markaby inspired builder DSL which generates DOM nodes
51
- directly instead of creating a string.
92
+ It also supports a markaby inspired builder DSL (using Paggio) which generates
93
+ DOM nodes directly instead of creating a string.
52
94
53
95
``` ruby
54
96
$document .ready do
@@ -60,12 +102,37 @@ $document.ready do
60
102
end
61
103
```
62
104
105
+ Events
106
+ ------
107
+
108
+ Add an event to a given element:
109
+
110
+ ``` ruby
111
+ $document .at_css(" button" ).on(:click ) do |e |
112
+ e.prevent # Prevent the default action (eg. form submission)
113
+ alert " Button clicked!"
114
+ end
115
+ ```
116
+
117
+ Or add it to a parent element and use a delegator, so that an event gets fired
118
+ when any button children of ` $document ` is clicked:
119
+
120
+ ``` ruby
121
+ $document .on(:click , " button" ) do |e |
122
+ e.prevent
123
+ # e.on is a button that has been clicked
124
+ e.on.inner_text = " Clicked!"
125
+ end
126
+ ```
127
+
128
+ Run an event once with ` #one ` instead of ` #on ` , or disable an event with ` #off ` .
129
+
63
130
CSSOM
64
131
-----
65
- CSSOM support is still incomplete but the useful parts are implemented, this
66
- includes a DSL for generating a CSS style and the same DSL is also used to
67
- change style declarations (which can either belong to a ` DOM::Element ` or a
68
- ` CSS::Rule::Style ` ).
132
+ CSSOM support (using Paggio) is still incomplete but the useful parts are
133
+ implemented, this includes a DSL for generating a CSS style and the same DSL
134
+ is also used to change style declarations (which can either belong to a
135
+ ` DOM::Element ` or a ` CSS::Rule::Style ` ).
69
136
70
137
``` ruby
71
138
$document .body.style.apply {
@@ -140,9 +207,16 @@ Storage
140
207
The HTML5 Storage API has been wrapped and it exports a single Storage class
141
208
that uses the most appropriate and available API to store data locally.
142
209
210
+ ``` ruby
211
+ require ' browser/storage'
212
+
213
+ $storage = $window .storage
214
+ $storage [:hello ] = " world"
215
+ ```
216
+
143
217
Database SQL
144
218
------------
145
- WebSQL has been fully wrapped.
219
+ WebSQL has been fully wrapped (Chromium-only)
146
220
147
221
``` ruby
148
222
require ' browser/database/sql'
@@ -166,55 +240,33 @@ db.transaction {|t|
166
240
Browser support
167
241
===============
168
242
169
- * Internet Explorer 6+
170
- * Firefox (Current - 1) or Current
171
- * Chrome (Current - 1) or Current
172
- * Safari 5.1+
173
- * Opera 12.1x or (Current - 1) or Current
243
+ * Edge (Current - 3) to Current
244
+ * Firefox (Current - 3) to Current
245
+ * Chrome (Current - 3) to Current
246
+ * Safari (Current - 3) to Current
247
+ * Opera (Current - 3) to Current
174
248
175
249
Any problem above browsers should be considered and reported as a bug.
176
250
177
- (Current - 1) or Current denotes that we support the current stable version of
178
- the browser and the version that preceded it. For example, if the current
179
- version of a browser is 24.x, we support the 24.x and 23.x versions.
180
-
181
- 12.1x or (Current - 1) or Current denotes that we support Opera 12.1x as well
182
- as last 2 versions of Opera. For example, if the current Opera version is 20.x,
183
- we support Opera 12.1x, 19.x and 20.x but not Opera 15.x through 18.x.
184
-
185
- Cross-browser testing sponsored by [ BrowserStack] ( http://browserstack.com ) .
186
-
187
- CSS selectors
188
- -------------
189
- Older browsers do not support CSS selector in queries, this means you'll need
190
- external polyfills for this.
191
-
192
- The suggested polyfill is [ Sizzle] ( http://sizzlejs.com/ ) , require it ** before**
193
- opal-browser.
194
-
195
- JSON parsing
196
- ------------
197
- Older browsers don't support JSON parsing natively, this means you'll need
198
- external polyfills for this.
199
-
200
- The suggested polyfill is [ json2] ( https://github.com/douglascrockford/JSON-js ) ,
201
- require it ** before** opal-browser.
251
+ (Current - 3) to Current denotes that we support the current major stable version
252
+ of the browser and 3 versions preceding it. For example, if the current version
253
+ of a browser is 24.x, we support all versions between 21.x to 24.x.
202
254
203
- XPath support
204
- -------------
205
- Not all browsers support XPath queries, I'm looking at you Internet Explorer,
206
- this means you'll need external polyfills for this .
255
+ We will accept compatibility patches for even earlier browser versions. Opal-Browser
256
+ is written in such a way, that it integrates a robust compatibility check system,
257
+ similar to Modernizr, and the history of this library goes even as far as supporting
258
+ Internet Explorer 6 .
207
259
208
- The suggested polyfill is
209
- [ wgxpath] ( https://code.google.com/p/wicked-good-xpath/ ) , require it ** before**
210
- opal-browser.
260
+ See the [ polyfills documentation] ( docs/polyfills.md ) if you wish to polyfill some
261
+ behaviors not supported by the ancient web browsers (like ` querySelectorAll ` ).
211
262
212
263
License
213
264
=======
214
265
215
266
(The MIT License)
216
267
217
- Copyright (C) 2014 by meh
268
+ Copyright (C) 2013-2018 by meh<br >
269
+ Copyright (C) 2019-2021 hmdne and the Opal-Browser contributors
218
270
219
271
Permission is hereby granted, free of charge, to any person obtaining a copy
220
272
of this software and associated documentation files (the "Software"), to deal
0 commit comments