serviceworker-rails 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +6 -2
  4. data/Appraisals +12 -0
  5. data/CHANGELOG.md +13 -0
  6. data/README.md +79 -17
  7. data/Rakefile +2 -0
  8. data/bin/appraisal +17 -0
  9. data/gemfiles/rails_3.gemfile +16 -0
  10. data/gemfiles/rails_4.gemfile +15 -0
  11. data/gemfiles/rails_5.gemfile +15 -0
  12. data/lib/assets/images/convert.rb +3 -0
  13. data/lib/assets/images/serviceworker-rails/heart-1200x1200.png +0 -0
  14. data/lib/assets/images/serviceworker-rails/heart-120x120.png +0 -0
  15. data/lib/assets/images/serviceworker-rails/heart-152x152.png +0 -0
  16. data/lib/assets/images/serviceworker-rails/heart-180x180.png +0 -0
  17. data/lib/assets/images/serviceworker-rails/heart-192x192.png +0 -0
  18. data/lib/assets/images/serviceworker-rails/heart-36x36.png +0 -0
  19. data/lib/assets/images/serviceworker-rails/heart-48x48.png +0 -0
  20. data/lib/assets/images/serviceworker-rails/heart-512x512.png +0 -0
  21. data/lib/assets/images/serviceworker-rails/heart-60x60.png +0 -0
  22. data/lib/assets/images/serviceworker-rails/heart-72x72.png +0 -0
  23. data/lib/assets/images/serviceworker-rails/heart-76x76.png +0 -0
  24. data/lib/assets/images/serviceworker-rails/heart-96x96.png +0 -0
  25. data/lib/generators/serviceworker/install_generator.rb +36 -24
  26. data/lib/generators/serviceworker/templates/manifest.json +6 -53
  27. data/lib/generators/serviceworker/templates/offline.html +66 -0
  28. data/lib/generators/serviceworker/templates/serviceworker.js +53 -14
  29. data/lib/serviceworker/{railtie.rb → engine.rb} +9 -1
  30. data/lib/serviceworker/handler.rb +1 -0
  31. data/lib/serviceworker/rails.rb +1 -1
  32. data/lib/serviceworker/rails/handler.rb +1 -0
  33. data/lib/serviceworker/rails/version.rb +2 -1
  34. data/lib/serviceworker/route.rb +1 -0
  35. data/serviceworker-rails.gemspec +1 -0
  36. metadata +37 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3752a3b8e5aab69a95949bf282791c5871a1297d
4
- data.tar.gz: 22de311f4ed1728871bb3032673f03e3bac57e4e
3
+ metadata.gz: 1375be90e53a9669b3c5cf8e87c9b60fc7358280
4
+ data.tar.gz: 1ca30b3dc68fe59b06d5b16fd3373820d281e861
5
5
  SHA512:
6
- metadata.gz: e14a4a092b558e85a68d3dbef7f61d2fdf185d3510d9def1480a45d8abd7a96202f00da5ce2debe3a05fe2bd408d7a8ec26a801f19427fb6a8bd25aaae4c6c70
7
- data.tar.gz: b439353ce2aa25da2df120f902b59ed431b873cf077cb48e3d3a612c71f6ae474f12cf57b5e4900ad70f66d220c82297b4e71dac0885178eda6aeb7bbbc920a8
6
+ metadata.gz: 5122e12977bddf53e9800f8c2995d5b21da94f21ef8569ee1e5a74f447123f26ddce865d7f8855f5b0919feeb6c7658267bdbe6ddf5044e126d4cd5ecd5c91af
7
+ data.tar.gz: 2846135d62fb691d98a3979d1d86ad86b57d8a7c2394d2e06495332018ddd158801b7838d219fd49a16852b2b9b8c10d0b47f59c7bbebeeff4d61571c119fbd7
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /gemfiles/*.lock
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.5
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.11.2
4
+ - 2.3.2
5
+ before_install: gem install bundler -v 1.13.6
6
+ gemfile:
7
+ - gemfiles/rails_3.gemfile
8
+ - gemfiles/rails_4.gemfile
9
+ - gemfiles/rails_5.gemfile
@@ -0,0 +1,12 @@
1
+ appraise "rails-3" do
2
+ gem "rails", "~> 3.2"
3
+ gem "test-unit", "~> 3.0"
4
+ end
5
+
6
+ appraise "rails-4" do
7
+ gem "rails", "~> 4.2"
8
+ end
9
+
10
+ appraise "rails-5" do
11
+ gem "rails", "~> 5.0"
12
+ end
@@ -1,3 +1,16 @@
1
+ ### 0.5.0 - 2016-11-10
2
+
3
+ * enhancements
4
+ * Convert railtie to Rails engine
5
+ * Extend install generator to add offline page and starter icons for generated web app manifest
6
+ * Install serviceworker and manifest as .erb files
7
+
8
+ ### 0.4.0 - 2016-11-09
9
+
10
+ * enhancements
11
+ * Add install generator to insert code snippets and add default serviceworker
12
+ and companion scripts, web app manifest, and Rails initializer
13
+
1
14
  ### 0.3.1 - 2016-05-03
2
15
 
3
16
  * enhancements
data/README.md CHANGED
@@ -61,6 +61,29 @@ your Rails project.
61
61
  $ rails g serviceworker:install
62
62
  ```
63
63
 
64
+ The generator will create the following files:
65
+
66
+ * `config/initializers/serviceworker.rb` - for configuring your Rails app
67
+ * `app/assets/javascripts/serviceworker.js.erb` - a blank Service Worker
68
+ script with some example strategies
69
+ * `app/assets/javascripts/serviceworker-companion.js` - a snippet of JavaScript
70
+ necessary to register your Service Worker in the browser
71
+ * `app/assets/javascripts/manifest.json.erb` - a starter web app manifest
72
+ pointing to some default app icons provided by the gem
73
+ * `public/offline.html` - a starter offline page
74
+
75
+ It will also make the following modifications to existing files:
76
+
77
+ * Adds a sprockets directive to `application.js` to require
78
+ `serviceworker-companion.js`
79
+ * Adds `serviceworker.js` and `manifest.json` to the list of compiled assets in
80
+ `config/initializers/assets.rb`
81
+ * Injects tags into the `head` of `app/views/layouts/application.html.erb` for
82
+ linking to the web app manifest
83
+
84
+ To learn more about each of the changes or to perform the set up yourself, check
85
+ out the manual setup section below.
86
+
64
87
  ### Manual setup
65
88
 
66
89
  Let's add a `ServiceWorker` to cache some of your JavaScript and CSS assets. We'll assume you already have a Rails application using the asset pipeline built on Sprockets.
@@ -75,34 +98,41 @@ console.log('[Service Worker] Hello world!');
75
98
 
76
99
  function onInstall(event) {
77
100
  event.waitUntil(
78
- caches.open('cached-assets').then(function prefill(cache) {
101
+ caches.open('cached-assets-v1').then(function prefill(cache) {
79
102
  return cache.addAll([
80
103
  '<%= asset_path "application.js" %>',
81
104
  '<%= asset_path "application.css" %>',
82
- '<%= asset_path "admin.css" %>',
105
+ '/offline.html',
83
106
  // you get the idea ...
84
107
  ]);
85
108
  })
86
109
  );
87
110
  }
88
111
 
112
+ function onActivate(event) {
113
+ console.log('[Serviceworker]', "Activating!", event);
114
+ event.waitUntil(
115
+ caches.keys().then(function(cacheNames) {
116
+ return Promise.all(
117
+ cacheNames.filter(function(cacheName) {
118
+ // Return true if you want to remove this cache,
119
+ // but remember that caches are shared across
120
+ // the whole origin
121
+ return key.indexOf('v1') !== 0;
122
+ }).map(function(cacheName) {
123
+ return caches.delete(cacheName);
124
+ })
125
+ );
126
+ })
127
+ );
128
+ }
129
+
89
130
  self.addEventListener('install', onInstall)
131
+ self.addEventListener('activate', onActivate)
90
132
  ```
91
133
 
92
134
  For use in production, instruct Sprockets to precompile service worker scripts separately from `application.js`, as in the following example:
93
135
 
94
- #### Precompile the asset
95
-
96
- ```ruby
97
- # config/initializers/assets.rb
98
-
99
- Rails.application.configure do
100
- config.assets.precompile += %w[
101
- serviceworker.js
102
- ]
103
- end
104
- ```
105
-
106
136
  #### Register the service worker
107
137
 
108
138
  You'll need to register the service worker with a companion script in your main page JavaScript, like `application.js`. You can use the following:
@@ -128,9 +158,8 @@ if (navigator.serviceWorker) {
128
158
  You may also want to create a `manifest.json` file to make your web app installable.
129
159
 
130
160
  ```
131
- // manifest.json
161
+ // app/assets/javascripts/manifest.json
132
162
  {
133
- "name": "My Rails App"
134
163
  "name": "My Progressive Rails App",
135
164
  "short_name": "Progressive",
136
165
  "start_url": "/"
@@ -159,6 +188,16 @@ Rails.application.configure do
159
188
  end
160
189
  ```
161
190
 
191
+ #### Precompile the assets
192
+
193
+ ```ruby
194
+ # config/initializers/assets.rb
195
+
196
+ Rails.application.configure do
197
+ config.assets.precompile += %w[serviceworker.js manifest.json]
198
+ end
199
+ ```
200
+
162
201
  #### Test the setup
163
202
 
164
203
  At this point, restart your Rails app and reload a page in your app in Chrome or Firefox. Using dev tools, you should be able to determine.
@@ -174,7 +213,30 @@ So far so good? At this point, all we've done is pre-fetched assets and added th
174
213
 
175
214
  Now, we can use the service worker to intercept requests and either serve them from the cache if they exist there or fallback to the network response otherwise. In most cases, we can expect responses coming from the local cache to be much faster than those coming from the network.
176
215
 
177
- (...more coming soon, WIP)
216
+ ```javascript
217
+ // app/assets/javascripts/serviceworker.js.erb
218
+
219
+ function onFetch(event) {
220
+ // Fetch from network, fallback to cached content, then offline.html for same-origin GET requests
221
+ var request = event.request;
222
+
223
+ if (!request.url.match(/^https?:\/\/example.com/) ) { return; }
224
+ if (request.method !== 'GET') { return; }
225
+
226
+ event.respondWith(
227
+ fetch(request). // first, the network
228
+ .catch(function fallback() {
229
+ caches.match(request).then(function(response) { // then, the cache
230
+ response || caches.match("/offline.html"); // then, /offline cache
231
+ })
232
+ })
233
+ );
234
+
235
+ // See https://jakearchibald.com/2014/offline-cookbook/#on-network-response for more examples
236
+ }
237
+
238
+ self.addEventListener('install', onInstall);
239
+ ```
178
240
 
179
241
  ## Configuration
180
242
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
  require "rubocop/rake_task"
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'appraisal' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("appraisal", "appraisal")
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2"
6
+ gem "test-unit", "~> 3.0"
7
+
8
+ group :development, :test do
9
+ gem "rubocop", "0.39.0"
10
+ gem "pry"
11
+ gem "pry-byebug", :platforms => [:mri]
12
+ gem "guard"
13
+ gem "guard-minitest"
14
+ end
15
+
16
+ gemspec :path => "../"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2"
6
+
7
+ group :development, :test do
8
+ gem "rubocop", "0.39.0"
9
+ gem "pry"
10
+ gem "pry-byebug", :platforms => [:mri]
11
+ gem "guard"
12
+ gem "guard-minitest"
13
+ end
14
+
15
+ gemspec :path => "../"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0"
6
+
7
+ group :development, :test do
8
+ gem "rubocop", "0.39.0"
9
+ gem "pry"
10
+ gem "pry-byebug", :platforms => [:mri]
11
+ gem "guard"
12
+ gem "guard-minitest"
13
+ end
14
+
15
+ gemspec :path => "../"
@@ -0,0 +1,3 @@
1
+ %w[48 60 72 76 96 120 152 180 192 512].each do |dim|
2
+ %(convert heart-1200x1200.png -resize #{dim}x heart-#{dim}x#{dim}.png)
3
+ end
@@ -1,4 +1,5 @@
1
1
  require "rails/generators"
2
+ require "fileutils"
2
3
 
3
4
  module Serviceworker
4
5
  module Generators
@@ -7,44 +8,47 @@ module Serviceworker
7
8
  source_root File.join(File.dirname(__FILE__), "templates")
8
9
 
9
10
  def create_assets
10
- template "serviceworker.js",
11
- File.join(javascripts_base_dir, "serviceworker.js")
12
- template "serviceworker-companion.js",
13
- File.join(javascripts_base_dir, "serviceworker-companion.js")
14
- template "manifest.json",
15
- File.join(javascripts_base_dir, "manifest.json")
11
+ template "manifest.json", javascripts_dir("manifest.json.erb")
12
+ template "serviceworker.js", javascripts_dir("serviceworker.js.erb")
13
+ template "serviceworker-companion.js", javascripts_dir("serviceworker-companion.js")
16
14
  end
17
15
 
18
16
  def create_initializer
19
- template "serviceworker.rb",
20
- File.join(initializers_dir, "serviceworker.rb")
17
+ template "serviceworker.rb", initializers_dir("serviceworker.rb")
21
18
  end
22
19
 
23
20
  def update_application_js
24
21
  ext, directive = detect_js_format
25
- append_to_file application_js_path(ext), "#{directive} require serviceworker-companion\n"
22
+ snippet = "#{directive} require serviceworker-companion\n"
23
+ append_to_file application_js_path(ext), snippet
26
24
  end
27
25
 
28
26
  def update_precompiled_assets
29
- append_to_file File.join(initializers_dir, "assets.rb"),
30
- "Rails.configuration.assets.precompile += %w[serviceworker.js]\n"
27
+ snippet = "Rails.configuration.assets.precompile += %w[serviceworker.js manifest.json]\n"
28
+ file_path = initializers_dir("assets.rb")
29
+ FileUtils.touch file_path
30
+ append_to_file file_path, snippet
31
31
  end
32
32
 
33
33
  def update_application_layout
34
- insert_into_file detect_layout,
35
- %(<link rel="manifest" href="/manifest.json" />),
36
- before: "</head>\n"
34
+ snippet = %(<link rel="manifest" href="/manifest.json" />)
35
+ snippet << %(\n<meta name="apple-mobile-web-app-capable" content="yes">)
36
+ insert_into_file detect_layout, snippet, before: "</head>\n"
37
+ end
38
+
39
+ def add_offline_html
40
+ template "offline.html", public_dir("offline.html")
37
41
  end
38
42
 
39
43
  private
40
44
 
41
45
  def application_js_path(ext)
42
- File.join(javascripts_base_dir, "application#{ext}")
46
+ javascripts_dir("application#{ext}")
43
47
  end
44
48
 
45
49
  def detect_js_format
46
- %w[.coffee .coffee.erb .js.coffee .js.coffee.erb .js .js.erb].each do |ext|
47
- next unless File.exist?(File.join(javascripts_base_dir, "application#{ext}"))
50
+ %w[.js .js.erb .coffee .coffee.erb .js.coffee .js.coffee.erb].each do |ext|
51
+ next unless File.exist?(javascripts_dir("application#{ext}"))
48
52
  return [ext, "#="] if ext.include?(".coffee")
49
53
  return [ext, "//="]
50
54
  end
@@ -52,21 +56,29 @@ module Serviceworker
52
56
 
53
57
  def detect_layout
54
58
  layouts = %w[.html.erb .html.haml .html.slim].map do |ext|
55
- File.join(layouts_base_dir, "application#{ext}")
59
+ layouts_dir("application#{ext}")
56
60
  end
57
61
  layouts.find { |layout| File.exist?(layout) }
58
62
  end
59
63
 
60
- def javascripts_base_dir
61
- File.join("app", "assets", "javascripts")
64
+ def javascripts_dir(*paths)
65
+ join("app", "assets", "javascripts", *paths)
66
+ end
67
+
68
+ def initializers_dir(*paths)
69
+ join("config", "initializers", *paths)
70
+ end
71
+
72
+ def layouts_dir(*paths)
73
+ join("app", "views", "layouts", *paths)
62
74
  end
63
75
 
64
- def initializers_dir
65
- File.join("config", "initializers")
76
+ def public_dir(*paths)
77
+ join("public", *paths)
66
78
  end
67
79
 
68
- def layouts_base_dir
69
- File.join("app", "views", "layouts")
80
+ def join(*paths)
81
+ File.expand_path(File.join(*paths), destination_root)
70
82
  end
71
83
  end
72
84
  end
@@ -1,63 +1,16 @@
1
+ <%% icon_sizes = Rails.configuration.serviceworker.icon_sizes %>
1
2
  {
2
3
  "name": "My Progressive Rails App",
3
4
  "short_name": "Progressive",
4
5
  "start_url": "/",
5
6
  "icons": [
7
+ <%% icon_sizes.map { |s| "#{s}x#{s}" }.each.with_index do |dim, i| %>
6
8
  {
7
- "src": "/icons/icon36.png",
8
- "sizes": "36x36",
9
+ "src": "<%%= image_path "serviceworker-rails/heart-#{dim}.png" %>",
10
+ "sizes": "<%%= dim %>",
9
11
  "type": "image/png"
10
- },
11
- {
12
- "src": "/icons/icon48.png",
13
- "sizes": "48x48",
14
- "type": "image/png"
15
- },
16
- {
17
- "src": "/icons/icon60.png",
18
- "sizes": "60x60",
19
- "type": "image/png"
20
- },
21
- {
22
- "src": "/icons/icon72.png",
23
- "sizes": "72x72",
24
- "type": "image/png"
25
- },
26
- {
27
- "src": "/icons/icon76.png",
28
- "sizes": "76x76",
29
- "type": "image/png"
30
- },
31
- {
32
- "src": "/icons/icon96.png",
33
- "sizes": "96x96",
34
- "type": "image/png"
35
- },
36
- {
37
- "src": "/icons/icon120.png",
38
- "sizes": "120x120",
39
- "type": "image/png"
40
- },
41
- {
42
- "src": "/icons/icon152.png",
43
- "sizes": "152x152",
44
- "type": "image/png"
45
- },
46
- {
47
- "src": "/icons/icon180.png",
48
- "sizes": "180x180",
49
- "type": "image/png"
50
- },
51
- {
52
- "src": "/icons/icon192.png",
53
- "sizes": "192x192",
54
- "type": "image/png"
55
- },
56
- {
57
- "src": "/icons/icon512.png",
58
- "sizes": "512x512",
59
- "type": "image/png"
60
- }
12
+ }<%%= i == (icon_sizes.length - 1) ? '' : ',' %>
13
+ <%% end %>
61
14
  ],
62
15
  "theme_color": "#000000",
63
16
  "background_color": "#FFFFFF",
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>You are not connected to the Internet</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>It looks like you've lost your Internet connection</h1>
62
+ <p>You may need to reconnect to Wi-Fi.</p>
63
+ </div>
64
+ </div>
65
+ </body>
66
+ </html>
@@ -1,14 +1,53 @@
1
- function onInstall() {
2
- console.log('[Serviceworker]', "Installing!");
3
- }
4
-
5
- function onActivate() {
6
- console.log('[Serviceworker]', "Activating!");
7
- }
8
-
9
- function onFetch() {
10
- }
11
-
12
- self.addEventListener('install', onInstall);
13
- self.addEventListener('activate', onActivate);
14
- self.addEventListener('fetch', onFetch);
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,17 +1,25 @@
1
+ # frozen_string_literal: true
1
2
  require "rails"
2
3
  require "rails/railtie"
3
4
  require "serviceworker"
4
5
 
5
6
  module ServiceWorker
6
- class Railtie < ::Rails::Railtie
7
+ class Engine < ::Rails::Engine
7
8
  config.serviceworker = ActiveSupport::OrderedOptions.new
8
9
  config.serviceworker.headers = {}
9
10
  config.serviceworker.routes = ServiceWorker::Router.new
10
11
  config.serviceworker.handler = ServiceWorker::Rails::Handler.new
12
+ config.serviceworker.icon_sizes = %w[36 48 60 72 76 96 120 152 180 192 512]
11
13
 
12
14
  initializer "serviceworker-rails.configure_rails_initialization", after: :load_config_initializers do
13
15
  config.serviceworker.logger ||= ::Rails.logger
14
16
 
17
+ if config.respond_to?(:assets)
18
+ config.assets.precompile += %w[serviceworker-rails/*.png]
19
+ elsif app.config.respond_to?(:assets)
20
+ app.config.assets.precompile += %w[serviceworker-rails/*.png]
21
+ end
22
+
15
23
  app.middleware.use ServiceWorker::Middleware, config.serviceworker
16
24
  end
17
25
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ServiceWorker
2
3
  class Handler
3
4
  def initialize(root = Dir.getwd)
@@ -5,4 +5,4 @@ end
5
5
 
6
6
  require "serviceworker/rails/version"
7
7
  require "serviceworker/rails/handler"
8
- require "serviceworker/railtie"
8
+ require "serviceworker/engine"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rack/file"
2
3
 
3
4
  module ServiceWorker
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module ServiceWorker
2
3
  module Rails
3
- VERSION = "0.4.0".freeze
4
+ VERSION = "0.5.1".freeze
4
5
  end
5
6
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ServiceWorker
2
3
  class Route
3
4
  attr_reader :path_pattern, :asset_pattern, :options
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
28
  spec.add_development_dependency "rack-test"
29
29
  spec.add_development_dependency "rails"
30
+ spec.add_development_dependency "appraisal", "~> 2.1.0"
30
31
  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.4.0
4
+ version: 0.5.1
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-09 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: appraisal
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
111
125
  description: Integrates ServiceWorker into the Rails asset pipeline.
112
126
  email:
113
127
  - rosskaff@gmail.com
@@ -118,6 +132,7 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rubocop.yml"
120
134
  - ".travis.yml"
135
+ - Appraisals
121
136
  - CHANGELOG.md
122
137
  - CODE_OF_CONDUCT.md
123
138
  - Gemfile
@@ -126,25 +141,43 @@ files:
126
141
  - README.md
127
142
  - Rakefile
128
143
  - bin/_guard-core
144
+ - bin/appraisal
129
145
  - bin/console
130
146
  - bin/guard
131
147
  - bin/rake
132
148
  - bin/rubocop
133
149
  - bin/setup
150
+ - gemfiles/rails_3.gemfile
151
+ - gemfiles/rails_4.gemfile
152
+ - gemfiles/rails_5.gemfile
153
+ - lib/assets/images/convert.rb
154
+ - lib/assets/images/serviceworker-rails/heart-1200x1200.png
155
+ - lib/assets/images/serviceworker-rails/heart-120x120.png
156
+ - lib/assets/images/serviceworker-rails/heart-152x152.png
157
+ - lib/assets/images/serviceworker-rails/heart-180x180.png
158
+ - lib/assets/images/serviceworker-rails/heart-192x192.png
159
+ - lib/assets/images/serviceworker-rails/heart-36x36.png
160
+ - lib/assets/images/serviceworker-rails/heart-48x48.png
161
+ - lib/assets/images/serviceworker-rails/heart-512x512.png
162
+ - lib/assets/images/serviceworker-rails/heart-60x60.png
163
+ - lib/assets/images/serviceworker-rails/heart-72x72.png
164
+ - lib/assets/images/serviceworker-rails/heart-76x76.png
165
+ - lib/assets/images/serviceworker-rails/heart-96x96.png
134
166
  - lib/generators/serviceworker/install_generator.rb
135
167
  - lib/generators/serviceworker/templates/manifest.json
168
+ - lib/generators/serviceworker/templates/offline.html
136
169
  - lib/generators/serviceworker/templates/serviceworker-companion.js
137
170
  - lib/generators/serviceworker/templates/serviceworker.js
138
171
  - lib/generators/serviceworker/templates/serviceworker.rb
139
172
  - lib/service_worker.rb
140
173
  - lib/serviceworker-rails.rb
141
174
  - lib/serviceworker.rb
175
+ - lib/serviceworker/engine.rb
142
176
  - lib/serviceworker/handler.rb
143
177
  - lib/serviceworker/middleware.rb
144
178
  - lib/serviceworker/rails.rb
145
179
  - lib/serviceworker/rails/handler.rb
146
180
  - lib/serviceworker/rails/version.rb
147
- - lib/serviceworker/railtie.rb
148
181
  - lib/serviceworker/route.rb
149
182
  - lib/serviceworker/router.rb
150
183
  - serviceworker-rails.gemspec
@@ -168,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
201
  version: '0'
169
202
  requirements: []
170
203
  rubyforge_project:
171
- rubygems_version: 2.4.5.1
204
+ rubygems_version: 2.5.2
172
205
  signing_key:
173
206
  specification_version: 4
174
207
  summary: ServiceWorker for Rails 3+