bowser 0.5.3 → 0.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99863c5a834f54c9060f9f08b39a742ca397a978da8db9c3306ebe6ffc033d09
4
- data.tar.gz: 61043cb4797a1c767ff8bb7863d2d9d2935574785b812858df0df0dea0960533
3
+ metadata.gz: e29282cc18c5cb7189e25666a7145156a07b66721fa379a2d642208c044644d5
4
+ data.tar.gz: 370e47229f7089509074177c00037a2d8a26df1fa23c143f821af1405da379cf
5
5
  SHA512:
6
- metadata.gz: '01207861e030df2d7491dab9a9b9960be85cb9e89ed39cf11105a2723d33e613430f59341312af156d617e73defdfae9637fac900db08bce7167bf17bf43c979'
7
- data.tar.gz: cf388f7b6623b65cff61c06dd10dddcbddc195ec689208489b1a30284076e9f84e9fb8821e9eb76df35217a1c72d6f3210571a8917b984fb152e142be3fbd786
6
+ metadata.gz: 2980467c77a84e280349aa3a6d8c628aa07f66149b9682a0ca7942ea14bce1b93b4c683a2583e9d14dd6d04e7dbb3cbc03b737ad2e635348d039c4aeffa444fc
7
+ data.tar.gz: 4a01ca82ce5d29435d1b4d91acb40d54078db58a20a53a82d31a7330e7ca5acc24f0640ec9020fd932369bffd53bf060d1ad2a4e4ff71a3679ce3297fc9e7474
@@ -1,3 +1,26 @@
1
+ ## Version 0.5.4
2
+
3
+ - Improve ServiceWorker promise support
4
+ - Add support for `Document#head`
5
+ - Add `Iterable` mixin to support JS Iterable interface
6
+ - Allows you to `include Iterable` on any JS iterable to make it `Enumerable`
7
+ - Add initial Canvas support
8
+
9
+ ## Version 0.5.3
10
+
11
+ - Add default `initialize` for `DelegateNative`
12
+ - Return `nil` from `DelegateNative` methods that explicitly return `undefined`
13
+ - Previously, this would raise `NoMethodError`
14
+ - Yield timestamp to `Bowser.window.animation_frame` block
15
+
16
+ ## Version 0.5.2
17
+
18
+ - Allow videos to be full-screened
19
+
20
+ ## Version 0.5.1
21
+
22
+ This appears to have been an accidental release. I actually don't know what happened here.
23
+
1
24
  ## Version 0.5.0
2
25
 
3
26
  - IndexedDB support (#22)
@@ -1,3 +1,3 @@
1
1
  module Bowser
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -11,6 +11,11 @@ module Bowser
11
11
 
12
12
  module_function
13
13
 
14
+ # @return [Bowser::Element] the head element of the current document
15
+ def head
16
+ @head ||= Element.new(`#@native.head`)
17
+ end
18
+
14
19
  # @return [Bowser::Element] the body element of the current document
15
20
  def body
16
21
  @body ||= Element.new(`#@native.body`)
@@ -1,6 +1,7 @@
1
1
  require 'bowser/event_target'
2
2
  require 'bowser/file_list'
3
3
  require 'bowser/delegate_native'
4
+ require 'bowser/iterable'
4
5
 
5
6
  module Bowser
6
7
  # Wrap a native DOM element
@@ -138,18 +139,35 @@ module Bowser
138
139
  FileList.new(`#@native.files`)
139
140
  end
140
141
 
142
+ # Determine whether this is the same element
143
+ #
144
+ # @return [boolean] true if the element is the same, false otherwise
141
145
  def ==(other)
142
146
  `#@native === #{other.to_n}`
143
147
  end
144
148
 
149
+ # Set the specified attribute to the specified value
145
150
  def []= attribute, value
146
151
  `#@native.setAttribute(#{attribute}, #{value})`
147
152
  end
148
153
 
154
+ # Return the specified attribute
155
+ #
156
+ # @return [String] the value for the specified attribute
149
157
  def [] attribute
150
158
  `#@native.getAttribute(#{attribute})`
151
159
  end
152
160
 
161
+ def query_selector selector
162
+ result = super
163
+
164
+ Element.new(result) if result
165
+ end
166
+
167
+ def query_selector_all selector
168
+ Iterable.new(super).map { |element| Element.new(element) }
169
+ end
170
+
153
171
  # The native representation of this element.
154
172
  #
155
173
  # @return [JS] the native element wrapped by this object.
@@ -0,0 +1,19 @@
1
+ require 'bowser/element'
2
+
3
+ module Bowser
4
+ class Element
5
+ element :canvas do
6
+ def context(type='2d')
7
+ Context.new(`#@native.getContext(#{type})`)
8
+ end
9
+
10
+ class Context
11
+ include DelegateNative
12
+
13
+ def initialize native
14
+ @native = native
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module Bowser
2
+ class Iterable
3
+ include Enumerable
4
+
5
+ def initialize js_iterable
6
+ @js_iterable = js_iterable
7
+ end
8
+
9
+ def each
10
+ `#@js_iterable.length`.times do |i|
11
+ yield `#@js_iterable[i]`
12
+ end
13
+ end
14
+ end
15
+ end
@@ -23,7 +23,7 @@ module Bowser
23
23
  Promise.from_native(`
24
24
  #@native.open(name)
25
25
  .then(#{proc { |native| Cache.new(native) }})
26
- .catch(#{proc { |native| `console.error(native)` }})
26
+ .catch(#{proc { |native| `console.error(native)`; raise native }})
27
27
  `)
28
28
  end
29
29
 
@@ -36,6 +36,16 @@ module Bowser
36
36
  Promise.from_native(`#@native.addAll(#{requests.map(&:to_n)})`)
37
37
  end
38
38
 
39
+ def match request, **options
40
+ Promise
41
+ .from_native(`#@native.match(#{request.to_n}, #{options.to_n})`)
42
+ .then do |response|
43
+ if response
44
+ Response.from_native response
45
+ end
46
+ end
47
+ end
48
+
39
49
  def put request, response
40
50
  Promise.from_native(`#@native.put(#{request.to_n}, #{response.to_n})`)
41
51
  end
@@ -1,8 +1,9 @@
1
1
  require 'opal'
2
2
  require 'native'
3
+ require 'bowser/service_worker/cache_storage'
3
4
  require 'bowser/service_worker/extendable_event'
4
5
  require 'bowser/service_worker/fetch_event'
5
- require 'bowser/service_worker/cache_storage'
6
+ require 'bowser/service_worker/push_event'
6
7
  require 'bowser/service_worker/request'
7
8
  require 'bowser/service_worker/response'
8
9
  require 'bowser/service_worker/promise'
@@ -1,3 +1,5 @@
1
+ require 'bowser/service_worker/promise'
2
+
1
3
  module Bowser
2
4
  module ServiceWorker
3
5
  class ExtendableEvent
@@ -6,9 +8,7 @@ module Bowser
6
8
  end
7
9
 
8
10
  def wait_until promise
9
- `#@native.waitUntil(#{promise.to_n})`
10
-
11
- promise
11
+ Promise.from_native `#@native.waitUntil(#{promise.to_n})`
12
12
  end
13
13
 
14
14
  def to_n
@@ -21,7 +21,7 @@ module Bowser
21
21
  end
22
22
 
23
23
  def respond_with promise
24
- `#@native.respondWith(#{promise.then(&:to_n).to_n})`
24
+ `#@native.respondWith(#{promise.then { |value| value.to_n }.to_n})`
25
25
  end
26
26
  end
27
27
  end
@@ -37,12 +37,13 @@ module Bowser
37
37
  Promise.from_native `#@native.then(block)`
38
38
  end
39
39
 
40
- def fail &block
40
+ def catch &block
41
41
  Promise.from_native `#@native.catch(block)`
42
42
  end
43
+ alias fail catch
43
44
 
44
45
  def always &block
45
- Promise.from_native `#@native.then(block).fail(block)`
46
+ Promise.from_native `#@native.then(block, block)`
46
47
  end
47
48
 
48
49
  def resolve value
@@ -72,11 +73,11 @@ module Bowser
72
73
  end
73
74
 
74
75
  def resolved?
75
- !value.nil?
76
+ defined? @value
76
77
  end
77
78
 
78
79
  def rejected?
79
- !failure.nil?
80
+ defined? @failure
80
81
  end
81
82
 
82
83
  def to_n
@@ -87,13 +88,13 @@ module Bowser
87
88
  Opal.defn(self, 'then', function(callback) {
88
89
  var self = this;
89
90
 
90
- #{self.then(&`callback`)};
91
+ return #{self.then(&`callback`)};
91
92
  });
92
93
 
93
94
  Opal.defn(self, 'catch', function(callback) {
94
95
  var self = this;
95
96
 
96
- #{self.fail(&`callback`)};
97
+ return #{self.catch(&`callback`)};
97
98
  });
98
99
  }
99
100
  end
@@ -0,0 +1,26 @@
1
+ require 'bowser/service_worker/extendable_event'
2
+ require 'native' # for Hash.new(js_obj)
3
+
4
+ module Bowser
5
+ module ServiceWorker
6
+ class PushEvent < ExtendableEvent
7
+ def data
8
+ PushMessageData.new(`#@native.data`)
9
+ end
10
+
11
+ class PushMessageData
12
+ def initialize data
13
+ @data = data
14
+ end
15
+
16
+ def json
17
+ Hash.new(`#@data.json()`)
18
+ end
19
+
20
+ def text
21
+ `#@data.text()`
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -17,6 +17,10 @@ module Bowser
17
17
  @text ||= `#@native.text()`
18
18
  end
19
19
 
20
+ def ok?
21
+ `!!#@native.ok`
22
+ end
23
+
20
24
  def to_n
21
25
  @native
22
26
  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.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Gaskins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-24 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -97,6 +97,7 @@ files:
97
97
  - opal/bowser/delegate_native.rb
98
98
  - opal/bowser/document.rb
99
99
  - opal/bowser/element.rb
100
+ - opal/bowser/element/canvas.rb
100
101
  - opal/bowser/element/media.rb
101
102
  - opal/bowser/event.rb
102
103
  - opal/bowser/event_target.rb
@@ -107,6 +108,7 @@ files:
107
108
  - opal/bowser/http/request.rb
108
109
  - opal/bowser/http/response.rb
109
110
  - opal/bowser/indexed_db.rb
111
+ - opal/bowser/iterable.rb
110
112
  - opal/bowser/service_worker.rb
111
113
  - opal/bowser/service_worker/cache_storage.rb
112
114
  - opal/bowser/service_worker/clients.rb
@@ -114,6 +116,7 @@ files:
114
116
  - opal/bowser/service_worker/extendable_event.rb
115
117
  - opal/bowser/service_worker/fetch_event.rb
116
118
  - opal/bowser/service_worker/promise.rb
119
+ - opal/bowser/service_worker/push_event.rb
117
120
  - opal/bowser/service_worker/request.rb
118
121
  - opal/bowser/service_worker/response.rb
119
122
  - opal/bowser/websocket.rb