serviceworker-rails 0.5.4 → 0.5.5

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: d17cdce006f3937428ea792d26d0230da7f160f2
4
- data.tar.gz: a732500aceef5f0ebf4e9c735cd035f0d05777e2
3
+ metadata.gz: 6e58a2ae3f4679e8cd32a024d0114d5a924a174a
4
+ data.tar.gz: 474f2390c03df7be5efb55d7f173b40dd863c259
5
5
  SHA512:
6
- metadata.gz: 884781e3a6c78d0fd5dfae678b8dc1fbcb8fed0e08d5328f085da530ea1b3458b4dc704f8ff37a52fc738410cdad37d3a7a390c2aacae14dcf9497a981e5aa97
7
- data.tar.gz: 90815d77139a1fc02a9d517475802de3e52b219878d9660e2656367e7505df43a4cebb07caaa4f7c294946c205549ab7d58f2f559867cc64c7ab52203766876f
6
+ metadata.gz: b212fcdba3d949901fb95462fda9472e9c27d241542c7303949d87eff1183e0c492c77596d01ddb70e41bb86f30e4eecd717a2403bb4edfea6da52724eb78d95
7
+ data.tar.gz: 331f5ea58dbd378e481397ff48219a80e113aff428c904a93044f6b68cf613fa7f00c9530776397a87b8fde6bfffbba78431c9ea5ba701b8cb32face5a1b2b0d
@@ -1,3 +1,9 @@
1
+ ### 0.5.5 - 2017-05-01
2
+
3
+ * bug fixes
4
+ * Ensure middleware can handle assets when a separate asset host, e.g. a CDN,
5
+ is configured
6
+
1
7
  ### 0.5.4 - 2017-02-02
2
8
 
3
9
  * bug fixes
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/rossta/serviceworker-rails.svg?branch=master)](https://travis-ci.org/rossta/serviceworker-rails)
4
4
  [![Code Climate](https://codeclimate.com/github/rossta/serviceworker-rails/badges/gpa.svg)](https://codeclimate.com/github/rossta/serviceworker-rails)
5
- [![Coverage Status](https://coveralls.io/repos/github/rossta/serviceworker-rails/badge.svg?branch=master)](https://coveralls.io/github/rossta/serviceworker-rails?branch=master)
6
5
 
7
6
  Turn your Rails app into a Progressive Web App. Use [Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) with the Rails asset pipeline.
8
7
 
@@ -100,9 +99,11 @@ Create a JavaScript file called `app/assets/javascripts/serviceworker.js.erb`:
100
99
  // app/assets/javascripts/serviceworker.js.erb
101
100
  console.log('[Service Worker] Hello world!');
102
101
 
102
+ var CACHE_NAME = 'v1-cached-assets'
103
+
103
104
  function onInstall(event) {
104
105
  event.waitUntil(
105
- caches.open('cached-assets-v1').then(function prefill(cache) {
106
+ caches.open(CACHE_NAME).then(function prefill(cache) {
106
107
  return cache.addAll([
107
108
  '<%= asset_path "application.js" %>',
108
109
  '<%= asset_path "application.css" %>',
@@ -239,7 +240,7 @@ function onFetch(event) {
239
240
  // See https://jakearchibald.com/2014/offline-cookbook/#on-network-response for more examples
240
241
  }
241
242
 
242
- self.addEventListener('install', onInstall);
243
+ self.addEventListener('fetch', onFetch);
243
244
  ```
244
245
 
245
246
  ## Configuration
@@ -6,11 +6,10 @@ gem "rails", "~> 3.2"
6
6
  gem "test-unit", "~> 3.0"
7
7
 
8
8
  group :development, :test do
9
- gem "rubocop", "0.39.0"
9
+ gem "guard", :require => false
10
+ gem "guard-minitest", :require => false
10
11
  gem "pry"
11
12
  gem "pry-byebug", :platforms => [:mri]
12
- gem "guard"
13
- gem "guard-minitest"
14
13
  end
15
14
 
16
15
  gemspec :path => "../"
@@ -5,11 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.2"
6
6
 
7
7
  group :development, :test do
8
- gem "rubocop", "0.39.0"
8
+ gem "guard", :require => false
9
+ gem "guard-minitest", :require => false
9
10
  gem "pry"
10
11
  gem "pry-byebug", :platforms => [:mri]
11
- gem "guard"
12
- gem "guard-minitest"
13
12
  end
14
13
 
15
14
  gemspec :path => "../"
@@ -5,11 +5,10 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 5.0"
6
6
 
7
7
  group :development, :test do
8
- gem "rubocop", "0.39.0"
8
+ gem "guard", :require => false
9
+ gem "guard-minitest", :require => false
9
10
  gem "pry"
10
11
  gem "pry-byebug", :platforms => [:mri]
11
- gem "guard"
12
- gem "guard-minitest"
13
12
  end
14
13
 
15
14
  gemspec :path => "../"
@@ -31,9 +31,14 @@ module Serviceworker
31
31
  end
32
32
 
33
33
  def update_application_layout
34
+ layout = detect_layout
34
35
  snippet = %(<link rel="manifest" href="/manifest.json" />)
35
36
  snippet << %(\n<meta name="apple-mobile-web-app-capable" content="yes">)
36
- insert_into_file detect_layout, snippet, before: "</head>\n"
37
+ unless layout
38
+ conditional_warn "Could not locate application layout. To insert manifest tags manually, use:\n\n#{snippet}\n"
39
+ return
40
+ end
41
+ insert_into_file layout, snippet, before: "</head>\n"
37
42
  end
38
43
 
39
44
  def add_offline_html
@@ -55,7 +60,7 @@ module Serviceworker
55
60
  end
56
61
 
57
62
  def detect_layout
58
- layouts = %w[.html.erb .html.haml .html.slim].map do |ext|
63
+ layouts = %w[.html.erb .html.haml .html.slim .erb .haml .slim].map do |ext|
59
64
  layouts_dir("application#{ext}")
60
65
  end
61
66
  layouts.find { |layout| File.exist?(layout) }
@@ -80,6 +85,14 @@ module Serviceworker
80
85
  def join(*paths)
81
86
  File.expand_path(File.join(*paths), destination_root)
82
87
  end
88
+
89
+ def conditional_warn(warning)
90
+ silenced? or warn warning
91
+ end
92
+
93
+ def silenced?
94
+ ENV["RAILS_ENV"] == "test"
95
+ end
83
96
  end
84
97
  end
85
98
  end
@@ -55,7 +55,7 @@
55
55
  </head>
56
56
 
57
57
  <body>
58
- <!-- This file lives in public/404.html -->
58
+ <!-- This file lives in public/offline.html -->
59
59
  <div class="dialog">
60
60
  <div>
61
61
  <h1>It looks like you've lost your Internet connection</h1>
@@ -29,7 +29,25 @@ module ServiceWorker
29
29
  end
30
30
 
31
31
  def asset_path(path)
32
- ::ActionController::Base.helpers.asset_path(path)
32
+ if controller_helpers.respond_to?(:compute_asset_path)
33
+ controller_helpers.compute_asset_path(path)
34
+ else
35
+ logical_asset_path(path)
36
+ end
37
+ end
38
+
39
+ def controller_helpers
40
+ ::ActionController::Base.helpers
41
+ end
42
+
43
+ def logical_asset_path(path)
44
+ asset_path = controller_helpers.asset_path(path)
45
+ uri = URI.parse(asset_path)
46
+ uri.host = nil
47
+ uri.scheme = nil
48
+ uri.to_s
49
+ rescue URI::InvalidURIError
50
+ asset_path
33
51
  end
34
52
  end
35
53
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module ServiceWorker
3
3
  module Rails
4
- VERSION = "0.5.4".freeze
4
+ VERSION = "0.5.5".freeze
5
5
  end
6
6
  end
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rubocop", "0.46.0"
30
30
  spec.add_development_dependency "rails"
31
31
  spec.add_development_dependency "appraisal", "~> 2.1.0"
32
- spec.add_development_dependency "coveralls"
32
+ spec.add_development_dependency "simplecov"
33
33
  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.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Kaffenberger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.1.0
139
139
  - !ruby/object:Gem::Dependency
140
- name: coveralls
140
+ name: simplecov
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  version: '0'
230
230
  requirements: []
231
231
  rubyforge_project:
232
- rubygems_version: 2.5.1
232
+ rubygems_version: 2.5.2
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: ServiceWorker for Rails 3+