serviceworker-rails 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1375be90e53a9669b3c5cf8e87c9b60fc7358280
4
- data.tar.gz: 1ca30b3dc68fe59b06d5b16fd3373820d281e861
3
+ metadata.gz: 31552ed751cd1b86fdd2c30a11e4ecb131e4e947
4
+ data.tar.gz: 9afb5f219f579eef75b06f99d69bbacfa67fc8c6
5
5
  SHA512:
6
- metadata.gz: 5122e12977bddf53e9800f8c2995d5b21da94f21ef8569ee1e5a74f447123f26ddce865d7f8855f5b0919feeb6c7658267bdbe6ddf5044e126d4cd5ecd5c91af
7
- data.tar.gz: 2846135d62fb691d98a3979d1d86ad86b57d8a7c2394d2e06495332018ddd158801b7838d219fd49a16852b2b9b8c10d0b47f59c7bbebeeff4d61571c119fbd7
6
+ metadata.gz: 335912fa3a5c4910004163a289e863467cde8eb5a5d96b9bade63287abd4e1c244944741a599c2c7f56c106d442b83eb7b8671916f7bdb61a6120316ea719588
7
+ data.tar.gz: f7ec9e6be9ad4dc3cf67f96dbbf14d1fc2c6345c59ba4eddf1d11575b9ac2cf30dec32a6314cbc565b69997b7526b76b4ef66b3b4bbc6616d2d5879b873c1d54
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - "test/tmp/**/*"
4
+ - "tmp/**/*"
4
5
 
5
6
  Metrics/LineLength:
6
7
  Max: 120
@@ -85,3 +86,6 @@ Style/SpecialGlobalVars:
85
86
 
86
87
  Style/TrivialAccessors:
87
88
  Enabled: false
89
+
90
+ Style/ClassAndModuleChildren:
91
+ Enabled: false
@@ -1,3 +1,19 @@
1
+ ### 0.5.2 - 2017-01-07
2
+
3
+ * enhancements
4
+ * Enable generated serviceworker.js with improved fetch logic
5
+ * bug fixes
6
+ * Omit application.js from generated serviceworker.js to prevent circular
7
+ sprockets requires
8
+
9
+ ### 0.5.1 - 2016-11-17
10
+
11
+ * enhancements
12
+ * Add support for Rails 3
13
+ * bug fixes
14
+ * Fix syntax error in generated serviceworker.js
15
+ * Remove duplicate line in generated manifest.json (@brandonhilkert)
16
+
1
17
  ### 0.5.0 - 2016-11-10
2
18
 
3
19
  * enhancements
data/Gemfile CHANGED
@@ -4,12 +4,10 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
- gem "rubocop", "0.39.0"
8
-
9
7
  unless ENV["TRAVIS"]
8
+ gem "guard", require: false
9
+ gem "guard-minitest", require: false
10
10
  gem "pry"
11
11
  gem "pry-byebug", platforms: [:mri]
12
- gem "guard"
13
- gem "guard-minitest"
14
12
  end
15
13
  end
data/README.md CHANGED
@@ -81,6 +81,8 @@ It will also make the following modifications to existing files:
81
81
  * Injects tags into the `head` of `app/views/layouts/application.html.erb` for
82
82
  linking to the web app manifest
83
83
 
84
+ **NOTE** Given that Service Worker operates in a separate browser thread, outside the context of your web pages, you don't want to include `serviceworker.js` script in your `application.js`. So if you have a line like `require_tree .` in your `application.js` file, you'll either need to move your `serviceworker.js` to another location or replace `require_tree` with something more explicit.
85
+
84
86
  To learn more about each of the changes or to perform the set up yourself, check
85
87
  out the manual setup section below.
86
88
 
@@ -157,7 +159,7 @@ if (navigator.serviceWorker) {
157
159
 
158
160
  You may also want to create a `manifest.json` file to make your web app installable.
159
161
 
160
- ```
162
+ ```javascript
161
163
  // app/assets/javascripts/manifest.json
162
164
  {
163
165
  "name": "My Progressive Rails App",
@@ -224,7 +226,7 @@ function onFetch(event) {
224
226
  if (request.method !== 'GET') { return; }
225
227
 
226
228
  event.respondWith(
227
- fetch(request). // first, the network
229
+ fetch(request) // first, the network
228
230
  .catch(function fallback() {
229
231
  caches.match(request).then(function(response) { // then, the cache
230
232
  response || caches.match("/offline.html"); // then, /offline cache
@@ -287,7 +289,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
287
289
 
288
290
  ## Contributing
289
291
 
290
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/serviceworker-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
292
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rossta/serviceworker-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
291
293
 
292
294
  ## License
293
295
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
data/bin/guard CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
@@ -1,53 +1,64 @@
1
- // function onInstall(event) {
2
- // console.log('[Serviceworker]', "Installing!", event);
3
- // event.waitUntil(
4
- // caches.open('cached-assets-v1').then(function prefill(cache) {
5
- // return cache.addAll([
6
- // '<%%= asset_path "application.js" %>',
7
- // '<%%= asset_path "application.css" %>',
8
- // '/offline.html'
9
- // ]);
10
- // })
11
- // );
12
- // }
13
- //
14
- // function onActivate(event) {
15
- // console.log('[Serviceworker]', "Activating!", event);
16
- // event.waitUntil(
17
- // caches.keys().then(function(cacheNames) {
18
- // return Promise.all(
19
- // cacheNames.filter(function(cacheName) {
20
- // // Return true if you want to remove this cache,
21
- // // but remember that caches are shared across
22
- // // the whole origin
23
- // return key.indexOf('v1') !== 0;
24
- // }).map(function(cacheName) {
25
- // return caches.delete(cacheName);
26
- // })
27
- // );
28
- // })
29
- // );
30
- // }
31
- //
32
- // function onFetch(event) {
33
- // // Fetch from network, fallback to cached content, then offline.html for same-origin GET requests
34
- // var request = event.request;
35
- //
36
- // if (!request.url.match(/^https?:\/\/example.com/) ) { return; }
37
- // if (request.method !== 'GET') { return; }
38
- //
39
- // event.respondWith(
40
- // fetch(request). // first, the network
41
- // .catch(function fallback() {
42
- // caches.match(request).then(function(response) { // then, the cache
43
- // response || caches.match("/offline.html"); // then, /offline cache
44
- // })
45
- // })
46
- // );
47
- //
48
- // // See https://jakearchibald.com/2014/offline-cookbook/#on-network-response for more examples
49
- // }
50
- //
51
- // self.addEventListener('install', onInstall);
52
- // self.addEventListener('activate', onActivate);
53
- // self.addEventListener('fetch', onFetch);
1
+ var CACHE_VERSION = 'v1'
2
+ var CACHE_NAME = 'sw-cache-' + CACHE_VERSION;
3
+
4
+ function onInstall(event) {
5
+ console.log('[Serviceworker]', "Installing!", event);
6
+ event.waitUntil(
7
+ caches.open(CACHE_NAME).then(function prefill(cache) {
8
+ return cache.addAll([
9
+
10
+ // make sure serviceworker.js is not required by application.js
11
+ // if you want to reference application.js from here
12
+ '<%%#= asset_path "application.js" %>',
13
+
14
+ '<%%= asset_path "application.css" %>',
15
+
16
+ '/offline.html',
17
+
18
+ ]);
19
+ })
20
+ );
21
+ }
22
+
23
+ function onActivate(event) {
24
+ console.log('[Serviceworker]', "Activating!", event);
25
+ event.waitUntil(
26
+ caches.keys().then(function(cacheNames) {
27
+ return Promise.all(
28
+ cacheNames.filter(function(cacheName) {
29
+ // Return true if you want to remove this cache,
30
+ // but remember that caches are shared across
31
+ // the whole origin
32
+ return key.indexOf(CACHE_VERSION) !== 0;
33
+ }).map(function(cacheName) {
34
+ return caches.delete(cacheName);
35
+ })
36
+ );
37
+ })
38
+ );
39
+ }
40
+
41
+ // Borrowed from https://github.com/TalAter/UpUp
42
+ function onFetch(event) {
43
+ event.respondWith(
44
+ // try to return untouched request from network first
45
+ fetch(event.request).catch(function() {
46
+ // if it fails, try to return request from the cache
47
+ return caches.match(event.request).then(function(response) {
48
+ if (response) {
49
+ return response;
50
+ }
51
+ // if not found in cache, return default offline content for navigate requests
52
+ if (event.request.mode === 'navigate' ||
53
+ (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
54
+ console.log('[Serviceworker]', "Fetching offline content", event);
55
+ return caches.match('/offline.html');
56
+ }
57
+ })
58
+ })
59
+ );
60
+ }
61
+
62
+ self.addEventListener('install', onInstall);
63
+ self.addEventListener('activate', onActivate);
64
+ self.addEventListener('fetch', onFetch);
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module ServiceWorker
3
3
  module Rails
4
- VERSION = "0.5.1".freeze
4
+ VERSION = "0.5.2".freeze
5
5
  end
6
6
  end
@@ -75,6 +75,7 @@ module ServiceWorker
75
75
  end
76
76
 
77
77
  def compiled_source(pattern)
78
+ @wildcard_name = nil
78
79
  pattern_match = pattern.match(WILDCARD_PATTERN)
79
80
  if pattern_match
80
81
  @wildcard_name = if pattern_match[1].to_s.strip.empty?
@@ -23,9 +23,10 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "sprockets-rails"
25
25
  spec.add_development_dependency "bundler", "~> 1.11"
26
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rake", "~> 11.0"
27
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
28
  spec.add_development_dependency "rack-test"
29
+ spec.add_development_dependency "rubocop", "0.46.0"
29
30
  spec.add_development_dependency "rails"
30
31
  spec.add_development_dependency "appraisal", "~> 2.1.0"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serviceworker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Kaffenberger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2017-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '11.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '11.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.46.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.46.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rails
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
215
  version: '0'
202
216
  requirements: []
203
217
  rubyforge_project:
204
- rubygems_version: 2.5.2
218
+ rubygems_version: 2.5.1
205
219
  signing_key:
206
220
  specification_version: 4
207
221
  summary: ServiceWorker for Rails 3+