pwa 4.0.4 → 4.0.5

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: 02526d09194fef00e23397bb5ebd9d64ac9bd7eb16ed732a9ca9aa1d967ee1cf
4
- data.tar.gz: 7255bbba581943f3ad41a6df455966ad13b936b07c96dde2d4b20e91eb5b6bcf
3
+ metadata.gz: c68c3a4139644a4c822ef4fbe2f936d9d5ba77dbc5bce4e923e548d6b23cbf11
4
+ data.tar.gz: 4a6579f0c4b6d2870259356120edb5d7122c394891d538bd035d887ada96bc93
5
5
  SHA512:
6
- metadata.gz: ba19e0f45aef7ab901b56b06d0b10c1e9082e9d0502ddd82d5cfcdb78bbffd28d1485463f7de1d588f3e05ffdd09321645df22f2fb9664e878396654b41efa16
7
- data.tar.gz: 2a1ea7518c06dfc2dcd50596c5a2981e1308e13930006bf2f1d4c6daa0f2881365484e96aea1d17a3f7d79122e547a6e422d0105b6aa77c486740c1c77f27c34
6
+ metadata.gz: 4c4c231793d21253b628c85289aa7e454de852b85533a660278a61e7349394c050b6e2742dcfeae3393096206a832c71f9aca98109501fa2681a3ff4fafe28b5
7
+ data.tar.gz: a0e7d149368d756950f0fa5f01181392ab13b6d6d0a7e08e92108cbcbcac9499235d8d0123051a19cc8c02cb5e8f17e82f5fc35804d810eb2d411a44b1f88fd8
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Jonas Hübotter
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonas Hübotter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,234 +1,234 @@
1
- # Progressive Web Apps for Rails
2
-
3
- [![Gem Version](https://badge.fury.io/rb/pwa.svg)](https://badge.fury.io/rb/pwa) <img src="https://travis-ci.org/jonhue/pwa.svg?branch=master" />
4
-
5
- This gem only provides the foundation you can build your Progressive Web App upon. It simplifies adding a service worker and a manifest to your app, so it can be recognized as an PWA and be accessed without a network connection.
6
-
7
- [Google](https://developers.google.com/web/progressive-web-apps/) defines Progressive Web Apps as:
8
-
9
- * **Reliable** - Load instantly and never show the downasaur, even in uncertain network conditions.
10
- * This is handled by Progressive Web Apps for Rails.
11
- * **Fast** - Respond quickly to user interactions with silky smooth animations and no janky scrolling.
12
- * There are two technologies helping you with performance: *Turbolinks* & *AMP*. When you are using Turbolinks, use [TurbolinksAnimate](https://github.com/jonhue/turbolinks-animate) to get XHR requests + smooth page transitions that add some delight to using to your app. If you want to use AMP, take a look at [amp-html](https://github.com/jonhue/amp-html), an Accelerated Mobile Pages library for Rails apps.
13
- * **Engaging** - Feel like a natural app on the device, with an immersive user experience.
14
- * When you think about making your app more engaging, you can't get around user-notifications. OneSignal is a powerful (& free) solution. With [OnSignal](https://github.com/jonhue/onsignal) and [notification-pusher-onesignal](https://github.com/jonhue/notifications-rails/tree/master/notification-pusher/notification-pusher-onesignal) adding native notification capabilities to your app becomes dead simple.
15
-
16
- ---
17
-
18
- If a PWA is not enough and you want to bring your Web App into the store - check out [NativeGap](https://github.com/NativeGap/nativegap-rails).
19
-
20
- ---
21
-
22
- ## Table of Contents
23
-
24
- * [Installation](#installation)
25
- * [Usage](#usage)
26
- * [Quick start](#quick-start)
27
- * [Apps](#apps)
28
- * [Manifest](#manifest)
29
- * [Offline pages](#offline-pages)
30
- * [Themes](#themes)
31
- * [Service worker](#service-worker)
32
- * [Styles](#styles)
33
- * [Configuration](#configuration)
34
- * [To Do](#to-do)
35
- * [Contributing](#contributing)
36
- * [Contributors](#contributors)
37
- * [Semantic versioning](#semantic-versioning)
38
- * [License](#license)
39
-
40
- ---
41
-
42
- ## Installation
43
-
44
- Progressive Web Apps for Rails works with Rails 5 onwards. You can add it to your `Gemfile` with:
45
-
46
- ```ruby
47
- gem 'pwa'
48
- ```
49
-
50
- And then execute:
51
-
52
- $ bundle
53
-
54
- Or install it yourself as:
55
-
56
- $ gem install pwa
57
-
58
- If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
59
-
60
- ```ruby
61
- gem 'pwa', github: 'jonhue/pwa'
62
- ```
63
-
64
- ---
65
-
66
- ## Usage
67
-
68
- ### Quick start
69
-
70
- Run the generators:
71
-
72
- $ rails g mozaic:install
73
- $ rails g pwa:install
74
- $ rails g pwa:app -n "App"
75
-
76
- Now define your app:
77
-
78
- ```ruby
79
- Pwa.configure do |config|
80
- config.define_app 'App'
81
- end
82
- ```
83
-
84
- Add the following to the `head` tag of your layout file:
85
-
86
- ```haml
87
- = component 'pwa/manifest', url: request.base_url
88
- ```
89
-
90
- Now add the `pwa-rails` NPM package and initialize it:
91
-
92
- ```js
93
- import ProgressiveWebApp from 'pwa-rails';
94
- document.addEventListener( 'turbolinks:load', () => {
95
- const progressiveWebApp = new ProgressiveWebApp();
96
- })
97
- ```
98
-
99
- **Note:** If the name of the service worker is not the default `/pwa-sw.js` you can specify a custom path: `new ProgressiveWebApp('/custom-path.js')`
100
-
101
- Lastly, go to your routes file (`config/routes.rb`) and mount the `Pwa::Engine` class:
102
-
103
- ```ruby
104
- mount Pwa::Engine, at: ''
105
- ```
106
-
107
- **Note:** The path `Pwa::Engine` is being mounted at, is currently required to be `''`.
108
-
109
- ### Apps
110
-
111
- Progressive Web Apps for Rails allows for multiple Progressive Web Apps per Rails app:
112
-
113
- ```ruby
114
- Pwa.configure do |config|
115
- config.define_app 'Subdomain', ['subdomain.example.com', 'subdomain.lvh.me:3000']
116
- config.define_app 'Example', ['example.com', 'localhost:3000', 'lvh.me:3000']
117
- end
118
- ```
119
-
120
- **Note:** You can omit the array of URL scopes if you have just one PWA.
121
-
122
- When looking for an app, the first app specified with a matching scope will be used.
123
-
124
- #### Manifest
125
-
126
- The app generator generates a manifest file located in the `app/views/pwa/apps/manifests` directory. It is accessible through `/manifest.json`. You can customize it to your liking.
127
-
128
- #### Offline pages
129
-
130
- Progressive Web Apps for Rails automatically stores a copy of the offline page (`app/views/pwa/apps/offline/_app.html.erb`) in the users cache, so your app is accessible at any time, even if requested URLs have not been cached yet.
131
-
132
- ### Themes
133
-
134
- Progressive Web Apps for Rails simplifies adding themes reflected in browsers to your site. Add the following to the `head` tag in your layout file:
135
-
136
- ```haml
137
- = component 'pwa/theme', default: '#000000'
138
- ```
139
-
140
- **Note:** `default` falls back to `#FFFFFF`.
141
-
142
- You can now override the default theme color from your views:
143
-
144
- ```haml
145
- - area :pwa_theme, '#FF0000'
146
- ```
147
-
148
- ### Service worker
149
-
150
- The generator also generates a service worker which caches visited pages to the local storage so they can get accessed even if the device has no network connection.
151
-
152
- You can customize the page that shows up when a requested page has not been cached by editing the contents of `app/views/pwa/offline/index.html.erb`
153
-
154
- **Note:** When using Progressive Web Apps for Rails with a service worker provided by a third party service like OneSignal, remove the require statement from `app/assets/javascripts/application.js` and manually import your apps service worker in the third party script:
155
-
156
- ```js
157
- importScripts('https://example.com/pwa-sw.js');
158
- ```
159
-
160
- ### Styles
161
-
162
- To detect whether or not your app is currently being used as a Progressive Web App, you can use CSS media queries:
163
-
164
- ```css
165
- @media all and (display-mode: standalone) {
166
- /* ... */
167
- }
168
- ```
169
-
170
- **Note:** Make sure to use `fullscreen` instead of `standalone` if that is your PWA display mode.
171
-
172
- ---
173
-
174
- ## Configuration
175
-
176
- You can configure Pwa by passing a block to `configure`. This can be done in `config/initializers/pwa.rb`:
177
-
178
- ```ruby
179
- Pwa.configure do |config|
180
- config.define_app 'App', ['example.com']
181
- end
182
- ```
183
-
184
- * `define_app` Define apps with a name and URL scopes.
185
-
186
- ---
187
-
188
- ## To Do
189
-
190
- [Here](https://github.com/jonhue/pwa/projects/1) is the full list of current projects.
191
-
192
- To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/pwa/issues/new).
193
-
194
- ---
195
-
196
- ## Contributing
197
-
198
- We hope that you will consider contributing to Progressive Web Apps for Rails. Please read this short overview for some information about how to get started:
199
-
200
- [Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
201
-
202
- ### Contributors
203
-
204
- Give the people some :heart: who are working on this project. See them all at:
205
-
206
- https://github.com/jonhue/pwa/graphs/contributors
207
-
208
- ### Semantic Versioning
209
-
210
- Progressive Web Apps for Rails follows Semantic Versioning 2.0 as defined at http://semver.org.
211
-
212
- ## License
213
-
214
- MIT License
215
-
216
- Copyright (c) 2018 Jonas Hübotter
217
-
218
- Permission is hereby granted, free of charge, to any person obtaining a copy
219
- of this software and associated documentation files (the "Software"), to deal
220
- in the Software without restriction, including without limitation the rights
221
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
222
- copies of the Software, and to permit persons to whom the Software is
223
- furnished to do so, subject to the following conditions:
224
-
225
- The above copyright notice and this permission notice shall be included in all
226
- copies or substantial portions of the Software.
227
-
228
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
229
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
230
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
231
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
232
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
233
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
234
- SOFTWARE.
1
+ # Progressive Web Apps for Rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pwa.svg)](https://badge.fury.io/rb/pwa) <img src="https://travis-ci.org/jonhue/pwa.svg?branch=master" />
4
+
5
+ This gem only provides a foundation upon which you can build your Progressive Web App. It simplifies adding a service worker and a manifest to your app, so that it can be recognized as an PWA and as such accessed without a network connection.
6
+
7
+ [Google](https://developers.google.com/web/progressive-web-apps/) defines Progressive Web Apps as:
8
+
9
+ * **Reliable** - Load instantly and never show the downasaur, even in uncertain network conditions.
10
+ * This is handled by Progressive Web Apps for Rails.
11
+ * **Fast** - Respond quickly to user interactions with silky smooth animations and no janky scrolling.
12
+ * There are two technologies helping you with performance: *Turbolinks* & *AMP*. When you are using Turbolinks, use [TurbolinksAnimate](https://github.com/jonhue/turbolinks-animate) to get XHR requests + smooth page transitions that add some delight to using to your app. If you want to use AMP, take a look at [amp-html](https://github.com/jonhue/amp-html), an Accelerated Mobile Pages library for Rails apps.
13
+ * **Engaging** - Feel like a natural app on the device, with an immersive user experience.
14
+ * When you think about making your app more engaging, you can't get around user-notifications. OneSignal is a powerful (& free) solution. With [OnSignal](https://github.com/jonhue/onsignal) and [notification-pusher-onesignal](https://github.com/jonhue/notifications-rails/tree/master/notification-pusher/notification-pusher-onesignal) adding native notification capabilities to your app becomes dead simple.
15
+
16
+ ---
17
+
18
+ If a PWA is not enough and you want to bring your Web App into the store - check out [NativeGap](https://github.com/NativeGap/nativegap-rails).
19
+
20
+ ---
21
+
22
+ ## Table of Contents
23
+
24
+ * [Installation](#installation)
25
+ * [Usage](#usage)
26
+ * [Quick start](#quick-start)
27
+ * [Apps](#apps)
28
+ * [Manifest](#manifest)
29
+ * [Offline pages](#offline-pages)
30
+ * [Themes](#themes)
31
+ * [Service worker](#service-worker)
32
+ * [Styles](#styles)
33
+ * [Configuration](#configuration)
34
+ * [To Do](#to-do)
35
+ * [Contributing](#contributing)
36
+ * [Contributors](#contributors)
37
+ * [Semantic versioning](#semantic-versioning)
38
+ * [License](#license)
39
+
40
+ ---
41
+
42
+ ## Installation
43
+
44
+ Progressive Web Apps for Rails works with Rails 5 onwards. You can add it to your `Gemfile` with:
45
+
46
+ ```ruby
47
+ gem 'pwa'
48
+ ```
49
+
50
+ And then execute:
51
+
52
+ $ bundle
53
+
54
+ Or install it yourself as:
55
+
56
+ $ gem install pwa
57
+
58
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
59
+
60
+ ```ruby
61
+ gem 'pwa', github: 'jonhue/pwa'
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Usage
67
+
68
+ ### Quick start
69
+
70
+ Run the generators:
71
+
72
+ $ rails g mozaic:install
73
+ $ rails g pwa:install
74
+ $ rails g pwa:app -n "App"
75
+
76
+ Now define your app:
77
+
78
+ ```ruby
79
+ Pwa.configure do |config|
80
+ config.define_app 'App'
81
+ end
82
+ ```
83
+
84
+ Add the following to the `head` tag of your layout file:
85
+
86
+ ```haml
87
+ = component 'pwa/manifest', url: request.base_url
88
+ ```
89
+
90
+ Now add the `pwa-rails` NPM package and initialize it:
91
+
92
+ ```js
93
+ import ProgressiveWebApp from 'pwa-rails';
94
+ document.addEventListener( 'turbolinks:load', () => {
95
+ const progressiveWebApp = new ProgressiveWebApp();
96
+ })
97
+ ```
98
+
99
+ **Note:** If the name of the service worker is not the default `/pwa-sw.js` you can specify a custom path: `new ProgressiveWebApp('/custom-path.js')`
100
+
101
+ Lastly, go to your routes file (`config/routes.rb`) and mount the `Pwa::Engine` class:
102
+
103
+ ```ruby
104
+ mount Pwa::Engine, at: ''
105
+ ```
106
+
107
+ **Note:** The path `Pwa::Engine` is being mounted at, is currently required to be `''`.
108
+
109
+ ### Apps
110
+
111
+ Progressive Web Apps for Rails allows for multiple Progressive Web Apps per Rails app:
112
+
113
+ ```ruby
114
+ Pwa.configure do |config|
115
+ config.define_app 'Subdomain', ['subdomain.example.com', 'subdomain.lvh.me:3000']
116
+ config.define_app 'Example', ['example.com', 'localhost:3000', 'lvh.me:3000']
117
+ end
118
+ ```
119
+
120
+ **Note:** You can omit the array of URL scopes if you have just one PWA.
121
+
122
+ When looking for an app, the first app specified with a matching scope will be used.
123
+
124
+ #### Manifest
125
+
126
+ The app generator generates a manifest file located in the `app/views/pwa/apps/manifests` directory. It is accessible through `/manifest.json`. You can customize it to your liking.
127
+
128
+ #### Offline pages
129
+
130
+ Progressive Web Apps for Rails automatically stores a copy of the offline page (`app/views/pwa/apps/offline/_app.html.erb`) in the users cache, so your app is accessible at all times, even if requested URLs have not been cached yet.
131
+
132
+ ### Themes
133
+
134
+ Progressive Web Apps for Rails simplifies adding themes reflected in browsers to your site. Add the following to the `head` tag in your layout file:
135
+
136
+ ```haml
137
+ = component 'pwa/theme', default: '#000000'
138
+ ```
139
+
140
+ **Note:** `default` falls back to `#FFFFFF`.
141
+
142
+ You can now override the default theme color from your views:
143
+
144
+ ```haml
145
+ - area :pwa_theme, '#FF0000'
146
+ ```
147
+
148
+ ### Service worker
149
+
150
+ The generator also generates a service worker which caches visited pages to the local storage so they can get accessed even if the device has no network connection.
151
+
152
+ You can customize the page that shows up when a requested page has not been cached by editing the contents of `app/views/pwa/offline/index.html.erb`
153
+
154
+ **Note:** When using Progressive Web Apps for Rails with a service worker provided by a third party service like OneSignal, remove the NPM package and manually import your apps service worker in the third party script:
155
+
156
+ ```js
157
+ importScripts('https://example.com/pwa-sw.js');
158
+ ```
159
+
160
+ ### Styles
161
+
162
+ To detect whether or not your app is currently being used as a Progressive Web App, you can use CSS media queries:
163
+
164
+ ```css
165
+ @media all and (display-mode: standalone) {
166
+ /* ... */
167
+ }
168
+ ```
169
+
170
+ **Note:** Make sure to use `fullscreen` instead of `standalone` if that is your PWA display mode.
171
+
172
+ ---
173
+
174
+ ## Configuration
175
+
176
+ You can configure Pwa by passing a block to `configure`. This can be done in `config/initializers/pwa.rb`:
177
+
178
+ ```ruby
179
+ Pwa.configure do |config|
180
+ config.define_app 'App', ['example.com']
181
+ end
182
+ ```
183
+
184
+ * `define_app` Define apps with a name and URL scopes.
185
+
186
+ ---
187
+
188
+ ## To Do
189
+
190
+ [Here](https://github.com/jonhue/pwa/projects/1) is the full list of current projects.
191
+
192
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/pwa/issues/new).
193
+
194
+ ---
195
+
196
+ ## Contributing
197
+
198
+ We hope that you will consider contributing to Progressive Web Apps for Rails. Please read this short overview for some information about how to get started:
199
+
200
+ [Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
201
+
202
+ ### Contributors
203
+
204
+ Give the people some :heart: who are working on this project. See them all at:
205
+
206
+ https://github.com/jonhue/pwa/graphs/contributors
207
+
208
+ ### Semantic Versioning
209
+
210
+ Progressive Web Apps for Rails follows Semantic Versioning 2.0 as defined at http://semver.org.
211
+
212
+ ## License
213
+
214
+ MIT License
215
+
216
+ Copyright (c) 2018 Jonas Hübotter
217
+
218
+ Permission is hereby granted, free of charge, to any person obtaining a copy
219
+ of this software and associated documentation files (the "Software"), to deal
220
+ in the Software without restriction, including without limitation the rights
221
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
222
+ copies of the Software, and to permit persons to whom the Software is
223
+ furnished to do so, subject to the following conditions:
224
+
225
+ The above copyright notice and this permission notice shall be included in all
226
+ copies or substantial portions of the Software.
227
+
228
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
229
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
230
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
231
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
232
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
233
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
234
+ SOFTWARE.
@@ -1,19 +1,17 @@
1
- module Pwa
2
- class AppsController < ApplicationController
3
-
4
- before_action :get_app
5
-
6
- def manifest
7
- end
8
-
9
- def offline
10
- end
11
-
12
- private
13
-
14
- def get_app
15
- @app = Pwa::App.find_by_url(request.original_url).first
16
- end
17
-
18
- end
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Pwa
4
+ class AppsController < ApplicationController
5
+ before_action :set_app
6
+
7
+ def manifest; end
8
+
9
+ def offline; end
10
+
11
+ private
12
+
13
+ def set_app
14
+ @app = Pwa::App.find_by_url(request.original_url).first
15
+ end
16
+ end
17
+ end
File without changes
@@ -1 +1 @@
1
- <meta name="theme-color" content="<%= area :pwa_theme, options[:default] %>">
1
+ <meta name="theme-color" content="<%= area :pwa_theme, options[:default] %>">
@@ -1 +1 @@
1
- <%= render "pwa/apps/manifests/#{@app.safe_name}" %>
1
+ <%= render "pwa/apps/manifests/#{@app.safe_name}" %>
@@ -1 +1 @@
1
- <%= render "pwa/apps/offline/#{@app.safe_name}" %>
1
+ <%= render "pwa/apps/offline/#{@app.safe_name}" %>
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
- Pwa::Engine.routes.draw do
2
-
3
- get 'offline', to: 'pwa/apps#offline'
4
- get 'manifest', to: 'pwa/apps#manifest', defaults: { format: :json }
5
-
6
- end
1
+ # frozen_string_literal: true
2
+
3
+ Pwa::Engine.routes.draw do
4
+ get 'offline', to: 'pwa/apps#offline'
5
+ get 'manifest', to: 'pwa/apps#manifest', defaults: { format: :json }
6
+ end
@@ -1,21 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
  require 'rails/generators/migration'
3
5
 
4
6
  module Pwa
5
- class AppGenerator < Rails::Generators::Base
6
-
7
- include Rails::Generators::Migration
8
-
9
- source_root File.join File.dirname(__FILE__), '../templates/app'
10
- desc 'Generate a Progressive Web Apps for Rails app'
7
+ class AppGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
11
9
 
12
- class_option :name, desc: 'App name', type: :string, default: 'index', aliases: '-n'
10
+ source_root File.join File.dirname(__FILE__), '../templates/app'
11
+ desc 'Generate a Progressive Web Apps for Rails app'
13
12
 
14
- def create_files
15
- @name = options[:name].parameterize.underscore
16
- template 'manifest.json.erb', "app/views/pwa/apps/manifests/_#{@name}.json"
17
- template 'offline.html.erb', "app/views/pwa/apps/offline/_#{@name}.html.erb"
18
- end
13
+ class_option :name, desc: 'App name', type: :string, default: 'index',
14
+ aliases: '-n'
19
15
 
16
+ def create_files
17
+ @name = options[:name].parameterize.underscore
18
+ template 'manifest.json.erb',
19
+ "app/views/pwa/apps/manifests/_#{@name}.json"
20
+ template 'offline.html.erb',
21
+ "app/views/pwa/apps/offline/_#{@name}.html.erb"
20
22
  end
23
+ end
21
24
  end
@@ -1,21 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
  require 'rails/generators/migration'
3
5
 
4
6
  module Pwa
5
- class InstallGenerator < Rails::Generators::Base
6
-
7
- include Rails::Generators::Migration
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
8
9
 
9
- source_root File.join File.dirname(__FILE__), '../templates/install'
10
- desc 'Install Progressive Web Apps for Rails'
10
+ source_root File.join File.dirname(__FILE__), '../templates/install'
11
+ desc 'Install Progressive Web Apps for Rails'
11
12
 
12
- def create_initializer
13
- template 'initializer.rb', 'config/initializers/pwa.rb'
14
- end
15
-
16
- def create_files
17
- template 'service-worker.js', 'public/pwa-sw.js'
18
- end
13
+ def create_initializer
14
+ template 'initializer.rb', 'config/initializers/pwa.rb'
15
+ end
19
16
 
17
+ def create_files
18
+ template 'service-worker.js', 'public/pwa-sw.js'
20
19
  end
20
+ end
21
21
  end
@@ -1,22 +1,22 @@
1
- {
2
- "short_name": "<%= options[:name].titleize %>",
3
- "name": "<%= options[:name].titleize %>",
4
- "start_url": "/",
5
- "scope": "/",
6
- "display": "standalone",
7
- "background_color": "#FFFFFF",
8
- "description": "",
9
- "theme_color": "#000000",
10
- "orientation": "portrait",
11
- "dir": "rtl",
12
- "lang": "en-US",
13
- "icons": [{
14
- "src": "/70x70.png",
15
- "sizes": "70x70",
16
- "type": "image/png"
17
- }, {
18
- "src": "/192x192.png",
19
- "sizes": "192x192",
20
- "type": "image/png"
21
- }]
22
- }
1
+ {
2
+ "short_name": "<%= options[:name].titleize %>",
3
+ "name": "<%= options[:name].titleize %>",
4
+ "start_url": "/",
5
+ "scope": "/",
6
+ "display": "standalone",
7
+ "background_color": "#FFFFFF",
8
+ "description": "",
9
+ "theme_color": "#000000",
10
+ "orientation": "portrait",
11
+ "dir": "rtl",
12
+ "lang": "en-US",
13
+ "icons": [{
14
+ "src": "/70x70.png",
15
+ "sizes": "70x70",
16
+ "type": "image/png"
17
+ }, {
18
+ "src": "/192x192.png",
19
+ "sizes": "192x192",
20
+ "type": "image/png"
21
+ }]
22
+ }
@@ -1,4 +1,4 @@
1
- <h1>You are offline</h1>
2
- <p>
3
- Return later with internet conectivity :)
4
- </p>
1
+ <h1>You are offline</h1>
2
+ <p>
3
+ Return later with internet conectivity.
4
+ </p>
@@ -1,7 +1,9 @@
1
- Pwa.configure do |config|
2
-
3
- # Define Progressive Web Apps for Rails apps
4
- # config.define_app 'Subdomain', ['subdomain.example.com', 'subdomain.lvh.me:3000']
5
- # config.define_app 'Example', ['example.com', 'localhost:3000', 'lvh.me:3000']
6
-
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ Pwa.configure do |config|
4
+ # Define Progressive Web Apps for Rails apps
5
+ # config.define_app 'Subdomain', ['subdomain.example.com',
6
+ # 'subdomain.lvh.me:3000']
7
+ # config.define_app 'Example', ['example.com', 'localhost:3000',
8
+ # 'lvh.me:3000']
9
+ end
@@ -1,52 +1,49 @@
1
- self.addEventListener( 'install', function(event) {
2
- event.waitUntil(preLoad());
3
- });
4
-
5
- var preLoad = function() {
6
- console.log('[PWA] Install Event processing');
7
- return caches.open('pwa-offline').then(function(cache) {
8
- console.log('[PWA] Cached index and offline page during Install');
9
- return cache.addAll(['/offline']);
10
- });
11
- }
12
-
13
- self.addEventListener( 'fetch', function(event) {
14
- console.log('[PWA] The service worker is serving the asset');
15
- event.respondWith(checkResponse(event.request).catch(function() {
16
- return returnFromCache(event.request);
17
- }));
18
- event.waitUntil(addToCache(event.request));
19
- });
20
-
21
- var checkResponse = function(request) {
22
- return new Promise(function( fulfill, reject ) {
23
- fetch(request).then(function(response) {
24
- if( response.status !== 404 ) {
25
- fulfill(response);
26
- } else {
27
- reject();
28
- };
29
- }, reject)
30
- });
31
- };
32
-
33
- var addToCache = function(request) {
34
- return caches.open('pwa-offline').then(function(cache) {
35
- return fetch(request).then(function(response) {
36
- console.log( '[PWA] Add page to cache: ', response.url );
37
- return cache.put( request, response );
38
- });
39
- });
40
- };
41
-
42
- var returnFromCache = function(request) {
43
- return caches.open('pwa-offline').then(function(cache) {
44
- return cache.match(request).then(function(matching) {
45
- if( !matching || matching.status == 404 ) {
46
- return cache.match('offline');
47
- } else {
48
- return matching;
49
- };
50
- });
51
- });
52
- };
1
+ self.addEventListener('install', function(event) {
2
+ event.waitUntil(preLoad());
3
+ });
4
+
5
+ var preLoad = function() {
6
+ return caches.open('pwa-offline').then(function(cache) {
7
+ return cache.addAll(['/offline']);
8
+ });
9
+ };
10
+
11
+ self.addEventListener('fetch', function(event) {
12
+ event.respondWith(checkResponse(event.request).catch(function() {
13
+ return returnFromCache(event.request);
14
+ }));
15
+ event.waitUntil(addToCache(event.request));
16
+ });
17
+
18
+ var checkResponse = function(request) {
19
+ return new Promise(function(fulfill, reject) {
20
+ fetch(request).then(function(response) {
21
+ if (response.status !== 404) {
22
+ fulfill(response);
23
+ } else {
24
+ reject();
25
+ }
26
+ }, reject);
27
+ });
28
+ };
29
+
30
+ var addToCache = function(request) {
31
+ return caches.open('pwa-offline').then(function(cache) {
32
+ return fetch(request).then(function(response) {
33
+ if (request.url)
34
+ return cache.put(request, response);
35
+ });
36
+ });
37
+ };
38
+
39
+ var returnFromCache = function(request) {
40
+ return caches.open('pwa-offline').then(function(cache) {
41
+ return cache.match(request).then(function(matching) {
42
+ if (!matching || matching.status == 404) {
43
+ return cache.match('offline');
44
+ } else {
45
+ return matching;
46
+ }
47
+ });
48
+ });
49
+ };
data/lib/pwa.rb CHANGED
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwa/version'
2
4
 
3
5
  module Pwa
6
+ require 'pwa/configuration'
4
7
 
5
- require 'pwa/configuration'
6
-
7
- require 'pwa/app'
8
-
9
- require 'pwa/engine'
10
- require 'pwa/railtie'
8
+ require 'pwa/app'
11
9
 
10
+ require 'pwa/engine'
11
+ require 'pwa/railtie'
12
12
  end
data/lib/pwa/app.rb CHANGED
@@ -1,25 +1,27 @@
1
- module Pwa
2
- class App
3
-
4
- attr_accessor :name
5
- attr_accessor :scopes
6
-
7
- def initialize name, scopes = nil
8
- @name = name
9
- @scopes = scopes
10
- end
11
-
12
- def safe_name
13
- self.name.parameterize.underscore
14
- end
15
-
16
- def self.find_by_name name
17
- Pwa.configuration.apps.select { |app| app.name == name }
18
- end
19
-
20
- def self.find_by_url url
21
- Pwa.configuration.apps.select { |app| app.scopes.nil? || app.scopes.any? { |scope| url.include?(scope) } }
22
- end
23
-
24
- end
25
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Pwa
4
+ class App
5
+ attr_accessor :name
6
+ attr_accessor :scopes
7
+
8
+ def initialize(name, scopes = nil)
9
+ @name = name
10
+ @scopes = scopes
11
+ end
12
+
13
+ def safe_name
14
+ name.parameterize.underscore
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ Pwa.configuration.apps.select { |app| app.name == name }
19
+ end
20
+
21
+ def self.find_by_url(url)
22
+ Pwa.configuration.apps.select do |app|
23
+ app.scopes.nil? || app.scopes.any? { |scope| url.include?(scope) }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,26 +1,24 @@
1
- module Pwa
2
-
3
- class << self
4
- attr_accessor :configuration
5
- end
6
-
7
- def self.configure
8
- self.configuration ||= Configuration.new
9
- yield configuration
10
- end
11
-
12
- class Configuration
13
-
14
- attr_accessor :apps
15
-
16
- def initialize
17
- @apps = []
18
- end
19
-
20
- def define_app name, scope = nil
21
- self.apps << ::Pwa::App.new(name, scope)
22
- end
23
-
24
- end
25
-
26
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Pwa
4
+ class << self
5
+ attr_accessor :configuration
6
+ end
7
+
8
+ def self.configure
9
+ self.configuration ||= Configuration.new
10
+ yield configuration
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :apps
15
+
16
+ def initialize
17
+ @apps = []
18
+ end
19
+
20
+ def define_app(name, scope = nil)
21
+ @apps << ::Pwa::App.new(name, scope)
22
+ end
23
+ end
24
+ end
data/lib/pwa/engine.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'rails/railtie'
2
-
3
- module Pwa
4
- class Engine < ::Rails::Engine
5
- # isolate_namespace Pwa
6
- end
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module Pwa
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
data/lib/pwa/railtie.rb CHANGED
@@ -1,15 +1,15 @@
1
- require 'rails/railtie'
2
- require 'mozaic'
3
-
4
- module Pwa
5
- class Railtie < Rails::Railtie
6
-
7
- initializer 'pwa.mozaic' do
8
- Mozaic.configure do |config|
9
- config.define_component 'pwa/manifest', url: 'http://localhost:3000'
10
- config.define_component 'pwa/theme', default: '#FFFFFF'
11
- end
12
- end
13
-
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+ require 'mozaic'
5
+
6
+ module Pwa
7
+ class Railtie < Rails::Railtie
8
+ initializer 'pwa.mozaic' do
9
+ Mozaic.configure do |config|
10
+ config.define_component 'pwa/manifest', url: 'http://localhost:3000'
11
+ config.define_component 'pwa/theme', default: '#FFFFFF'
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/pwa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
- module Pwa
2
-
3
- VERSION = '4.0.4'
1
+ # frozen_string_literal: true
4
2
 
3
+ module Pwa
4
+ VERSION = '4.0.5'
5
5
  end
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwa
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.4
4
+ version: 4.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: mozaic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: mozaic
28
+ name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2'
33
+ version: '5.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2'
40
+ version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.7'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.7'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.52'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '0.52'
82
+ version: '0'
69
83
  description: Add a service worker and a manifest to your app, for it to be recognized
70
84
  as a PWA and accessed without a network connection.
71
85
  email: me@jonhue.me
@@ -73,7 +87,6 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - CHANGELOG.md
77
90
  - LICENSE
78
91
  - README.md
79
92
  - app/controllers/pwa/apps_controller.rb
@@ -94,7 +107,7 @@ files:
94
107
  - lib/pwa/engine.rb
95
108
  - lib/pwa/railtie.rb
96
109
  - lib/pwa/version.rb
97
- homepage: https://jonhue.me/repos/progressive-web-apps-for-rails
110
+ homepage: https://github.com/jonhue/pwa
98
111
  licenses:
99
112
  - MIT
100
113
  metadata: {}
@@ -114,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
127
  version: '0'
115
128
  requirements: []
116
129
  rubyforge_project:
117
- rubygems_version: 2.7.4
130
+ rubygems_version: 2.7.6
118
131
  signing_key:
119
132
  specification_version: 4
120
133
  summary: Progressive Web Apps for Rails
data/CHANGELOG.md DELETED
@@ -1,63 +0,0 @@
1
- # Changelog
2
-
3
- ### master
4
-
5
- * nothing yet
6
-
7
- ### 4.0.4 - 2018/03/27
8
-
9
- * bugfixes
10
- * fixed manifest URL in manifest component
11
-
12
- ### 4.0.3 - 2018/03/27
13
-
14
- * bugfixes
15
- * fixed manifest URL in manifest component
16
-
17
- ### 4.0.2 - 2018/03/27
18
-
19
- * bugfixes
20
- * fixed manifest URL in manifest component
21
-
22
- ### 4.0.1 - 2018/03/27
23
-
24
- * bugfixes
25
- * fixed manifest URL in manifest component
26
-
27
- ### 4.0.0 - 2018/03/27
28
-
29
- * features
30
- * NPM package overhaul
31
- * bugfixes
32
- * fixed manifest URL in manifest component
33
-
34
- ### 3.0.0 - 2018/02/10
35
-
36
- * features
37
- * add theme support
38
- * enhancements
39
- * use Mozaic for components
40
-
41
- ### 2.0.1 - 2018/01/26
42
-
43
- * bugfixes
44
- * fixed `wrong number of arguments` when defining apps without scopes
45
-
46
- ### 2.0.0 - 2018/01/26
47
-
48
- * features
49
- * introduced `App` class to support multiple PWAs per Rails app
50
-
51
- ### 1.2.0 - 2018/01/19
52
-
53
- * features
54
- * added `pwa_manifest` helper method
55
-
56
- ### 1.1.0 - 2018/01/17
57
-
58
- * features
59
- * generate a `manifest.json` file by running the generator
60
-
61
- ### 1.0.0 - 2018/01/14
62
-
63
- * initial release