bowser 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGELOG.md +48 -0
- data/lib/bowser/version.rb +1 -1
- data/opal/bowser/element.rb +80 -16
- data/opal/bowser/event.rb +4 -0
- data/opal/bowser/http.rb +8 -8
- data/opal/bowser/http/request.rb +1 -1
- data/opal/bowser/window.rb +12 -0
- metadata +4 -4
- data/opal/bowser/http/event.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e07cbed8dbba587239bd6773b8b773d91195bda
|
4
|
+
data.tar.gz: a2cb7057cc1c44b61fe984a0a62f894be35e4cd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbfbe22f47b55da1d77c8c29613c950143c8604c7eca48c264536f221a3c577109c3a7b17b7e58453d6d27985f606d52065d41604f526cd0c339969def96ac22
|
7
|
+
data.tar.gz: 5b5d6a3ef2917d336c47febfea38b0b1c1e14a25a24457d6ef304c42193cb59f032a9273733bfcf13e8069bf313094a21e069673fdbbc379f1fabb3da0d5dfa8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
## Version 0.2.0
|
2
|
+
|
3
|
+
- Allow specifying methods for HTTP requests, including file uploads
|
4
|
+
- Add `Element#to_n` and `Event#to_n` to unwrap the native objects
|
5
|
+
- Make HTTP events just use `Bowser::Event` instead of their own type
|
6
|
+
- Proxy all native element/event properties
|
7
|
+
- This provides the following types of translations from Ruby method names to JS property names:
|
8
|
+
- `element.text_content` in Ruby becomes `element.textContent` in JS
|
9
|
+
- Predicates like `element.content_editable?` checks for `contentEditable` and `isContentEditable` properties, preferring the version without `is` if both exist.
|
10
|
+
- If the property is a function, it gets called.
|
11
|
+
- No wrapping of results is done for proxied properties. You get the raw JS value back.
|
12
|
+
- Add `Element#children` to wrap child nodes in `Bowser::Element` objects
|
13
|
+
- Add `Bowser.window.location.hash`
|
14
|
+
- Add `Bowser.window.has_push_state?`
|
15
|
+
- Use `load` event for `Bowser::HTTP::Request` instead of `success`. It was causing problems and `load` is the canonical event to use.
|
16
|
+
|
17
|
+
## Version 0.1.5
|
18
|
+
|
19
|
+
- Fix `animation_frame` polyfill delay
|
20
|
+
- Add the abillity to upload files directly from file input elements
|
21
|
+
- Allowing this instead of reading the files in first is a HUGE memory savings for large files. It uses the browser's internal streaming capabilities so we don't need to load the full file into memory.
|
22
|
+
- Memoize file read data
|
23
|
+
|
24
|
+
## Version 0.1.4
|
25
|
+
|
26
|
+
- Relax Opal version restriction to 0.8-0.11
|
27
|
+
- Add `Bowser::HTTP::Response#text` to get the raw response body instead of assuming JSON
|
28
|
+
- Fix JSON dependency loading instead of assuming it's there
|
29
|
+
|
30
|
+
## Version 0.1.3
|
31
|
+
|
32
|
+
- Add `Event#stop_propagation`
|
33
|
+
- Add first-class support for `file` input fields
|
34
|
+
|
35
|
+
## Version 0.1.2
|
36
|
+
|
37
|
+
- Add `Bowser::Window::Location#href`
|
38
|
+
- Fix missing element check for `Document#[]`
|
39
|
+
|
40
|
+
## Version 0.1.1
|
41
|
+
|
42
|
+
- Add `Window#scroll`
|
43
|
+
- Add `Window::History#push`
|
44
|
+
- Add WebSocket support
|
45
|
+
|
46
|
+
## Version 0.1.0
|
47
|
+
|
48
|
+
- Initial release
|
data/lib/bowser/version.rb
CHANGED
data/opal/bowser/element.rb
CHANGED
@@ -18,24 +18,49 @@ module Bowser
|
|
18
18
|
`#@native.innerHTML`
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def inner_html= html
|
22
|
+
`#@native.innerHTML = html`
|
23
|
+
end
|
24
|
+
|
25
|
+
def children
|
26
|
+
elements = []
|
27
|
+
|
22
28
|
%x{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
} else {
|
28
|
-
var children = native.children;
|
29
|
-
for(var i = 0; i < children.length; i++) {
|
30
|
-
children[i].remove();
|
31
|
-
}
|
32
|
-
}
|
29
|
+
var children = #@native.children;
|
30
|
+
for(var i = 0; i < children.length; i++) {
|
31
|
+
elements[i] = #{Element.new(`children[i]`)};
|
32
|
+
}
|
33
33
|
}
|
34
|
+
|
35
|
+
elements
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty?
|
39
|
+
`#@native.children.length === 0`
|
40
|
+
end
|
41
|
+
|
42
|
+
def clear
|
43
|
+
if %w(input textarea).include? type
|
44
|
+
`#@native.value = null`
|
45
|
+
else
|
46
|
+
children.each do |child|
|
47
|
+
remove_child child
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
34
51
|
self
|
35
52
|
end
|
36
53
|
|
54
|
+
def remove_child child
|
55
|
+
`#@native.removeChild(child.native ? child.native : child)`
|
56
|
+
end
|
57
|
+
|
58
|
+
def type
|
59
|
+
`#@native.nodeName`.downcase
|
60
|
+
end
|
61
|
+
|
37
62
|
def append node
|
38
|
-
`#@native.appendChild(node)`
|
63
|
+
`#@native.appendChild(node.native ? node.native : node)`
|
39
64
|
self
|
40
65
|
end
|
41
66
|
|
@@ -44,10 +69,6 @@ module Bowser
|
|
44
69
|
`!!#@native.checked`
|
45
70
|
end
|
46
71
|
|
47
|
-
def value
|
48
|
-
`#@native.value`
|
49
|
-
end
|
50
|
-
|
51
72
|
# Convenience for when you only need a single file
|
52
73
|
def file
|
53
74
|
files.first
|
@@ -56,5 +77,48 @@ module Bowser
|
|
56
77
|
def files
|
57
78
|
FileList.new(`#@native.files`)
|
58
79
|
end
|
80
|
+
|
81
|
+
# Fall back to native properties.
|
82
|
+
def method_missing message, *args, &block
|
83
|
+
camel_cased_message = message
|
84
|
+
.gsub(/_\w/) { |match| match[1].upcase }
|
85
|
+
.sub(/=$/, '')
|
86
|
+
|
87
|
+
# translate setting a property
|
88
|
+
if message.end_with? '='
|
89
|
+
return `#@native[camel_cased_message] = args[0]`
|
90
|
+
end
|
91
|
+
|
92
|
+
# translate `supported?` to `supported` or `isSupported`
|
93
|
+
if message.end_with? '?'
|
94
|
+
camel_cased_message = camel_cased_message.chop
|
95
|
+
property_type = `typeof(#@native[camel_cased_message])`
|
96
|
+
if property_type == 'undefined'
|
97
|
+
camel_cased_message = "is#{camel_cased_message[0].upcase}#{camel_cased_message[1..-1]}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# If the native element doesn't have this property, bubble it up
|
102
|
+
super if `typeof(#@native[camel_cased_message]) === 'undefined'`
|
103
|
+
|
104
|
+
property = `#@native[camel_cased_message]`
|
105
|
+
|
106
|
+
if `property === false`
|
107
|
+
return false
|
108
|
+
else
|
109
|
+
property = `property || nil`
|
110
|
+
end
|
111
|
+
|
112
|
+
# If it's a method, call it. Otherwise, return it.
|
113
|
+
if `typeof(property) === 'function'`
|
114
|
+
`property.apply(#@native, args)`
|
115
|
+
else
|
116
|
+
property
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_n
|
121
|
+
@native
|
122
|
+
end
|
59
123
|
end
|
60
124
|
end
|
data/opal/bowser/event.rb
CHANGED
data/opal/bowser/http.rb
CHANGED
@@ -8,9 +8,9 @@ module Bowser
|
|
8
8
|
module HTTP
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def fetch(url)
|
11
|
+
def fetch(url, method: :get)
|
12
12
|
promise = Promise.new
|
13
|
-
request = Request.new(
|
13
|
+
request = Request.new(method, url)
|
14
14
|
|
15
15
|
connect_events_to_promise request, promise
|
16
16
|
|
@@ -19,9 +19,9 @@ module Bowser
|
|
19
19
|
promise
|
20
20
|
end
|
21
21
|
|
22
|
-
def upload(url, data, content_type: 'application/json')
|
22
|
+
def upload(url, data, content_type: 'application/json', method: :post)
|
23
23
|
promise = Promise.new
|
24
|
-
request = Request.new(
|
24
|
+
request = Request.new(method, url)
|
25
25
|
|
26
26
|
connect_events_to_promise request, promise
|
27
27
|
|
@@ -30,9 +30,9 @@ module Bowser
|
|
30
30
|
promise
|
31
31
|
end
|
32
32
|
|
33
|
-
def upload_files(url, files, key: 'files', key_suffix: '[]')
|
33
|
+
def upload_files(url, files, key: 'files', key_suffix: '[]', method: :post)
|
34
34
|
promise = Promise.new
|
35
|
-
request = Request.new(
|
35
|
+
request = Request.new(method, url)
|
36
36
|
|
37
37
|
connect_events_to_promise request, promise
|
38
38
|
|
@@ -46,8 +46,8 @@ module Bowser
|
|
46
46
|
promise
|
47
47
|
end
|
48
48
|
|
49
|
-
def upload_file(url, file, key: 'file')
|
50
|
-
upload_files(url, [file], key: key, key_suffix: nil)
|
49
|
+
def upload_file(url, file, key: 'file', method: :post)
|
50
|
+
upload_files(url, [file], key: key, key_suffix: nil, method: method)
|
51
51
|
end
|
52
52
|
|
53
53
|
def connect_events_to_promise(request, promise)
|
data/opal/bowser/http/request.rb
CHANGED
data/opal/bowser/window.rb
CHANGED
@@ -41,6 +41,14 @@ module Bowser
|
|
41
41
|
module Location
|
42
42
|
module_function
|
43
43
|
|
44
|
+
def hash
|
45
|
+
`window.location.hash`
|
46
|
+
end
|
47
|
+
|
48
|
+
def hash= hash
|
49
|
+
`window.location.hash = hash`
|
50
|
+
end
|
51
|
+
|
44
52
|
def path
|
45
53
|
`window.location.pathname`
|
46
54
|
end
|
@@ -57,6 +65,10 @@ module Bowser
|
|
57
65
|
module History
|
58
66
|
module_function
|
59
67
|
|
68
|
+
def has_push_state?
|
69
|
+
`!!window.history.pushState`
|
70
|
+
end
|
71
|
+
|
60
72
|
def push path
|
61
73
|
`window.history.pushState({}, '', path)`
|
62
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bowser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- ".gitignore"
|
83
83
|
- ".rspec"
|
84
84
|
- ".travis.yml"
|
85
|
+
- CHANGELOG.md
|
85
86
|
- CODE_OF_CONDUCT.md
|
86
87
|
- Gemfile
|
87
88
|
- LICENSE.md
|
@@ -99,7 +100,6 @@ files:
|
|
99
100
|
- opal/bowser/event_target.rb
|
100
101
|
- opal/bowser/file_list.rb
|
101
102
|
- opal/bowser/http.rb
|
102
|
-
- opal/bowser/http/event.rb
|
103
103
|
- opal/bowser/http/form_data.rb
|
104
104
|
- opal/bowser/http/request.rb
|
105
105
|
- opal/bowser/http/response.rb
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.6
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Minimalist browser support for Opal apps
|