pwa 1.2.0 → 2.0.0
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +55 -9
- data/app/controllers/pwa/apps_controller.rb +19 -0
- data/app/helpers/pwa_helper.rb +1 -1
- data/app/views/pwa/apps/manifest.json.erb +1 -0
- data/app/views/pwa/apps/offline.html.erb +1 -0
- data/config/routes.rb +2 -1
- data/lib/generators/pwa/app_generator.rb +21 -0
- data/lib/generators/pwa/install_generator.rb +21 -0
- data/lib/generators/templates/{manifest.json → app/manifest.json.erb} +2 -2
- data/lib/generators/templates/{view.html.erb → app/offline.html.erb} +0 -0
- data/lib/generators/templates/install/initializer.rb +7 -0
- data/lib/generators/templates/{service_worker.js → install/service-worker.js} +2 -2
- data/lib/pwa.rb +4 -0
- data/lib/pwa/app.rb +25 -0
- data/lib/pwa/configuration.rb +26 -0
- data/lib/pwa/version.rb +1 -1
- metadata +15 -9
- data/app/controllers/pwa/offline_controller.rb +0 -8
- data/lib/generators/pwa_generator.rb +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4b16d74767980ee9dee6f68fe6028b9f155e160cca22043e1a2d3772c6158cd
|
|
4
|
+
data.tar.gz: b336abd47c05fb18c8bbae000d0704b8faa932034073c4726a04c4d5b17073fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b56b33826665907804b226bb31aa4ae442b41eaa6145ac9304044550ea46fda5ec5a50ed93238db27cbf817818cda540559717cf1c1c4e4467d778bee78d39b1
|
|
7
|
+
data.tar.gz: c25377415c2bdff4f98e315b98f1f126eb3101606233bc4e610b9f7bdbd3d32842612a1190053bf87e3ca8ca608b390ffa8a16142ae0ac62333c182a717baa63
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -23,9 +23,13 @@ If a PWA is not enough and you want to bring your Web App into the store - check
|
|
|
23
23
|
|
|
24
24
|
* [Installation](#installation)
|
|
25
25
|
* [Usage](#usage)
|
|
26
|
-
* [
|
|
26
|
+
* [Quick start](#quick-start)
|
|
27
|
+
* [Apps](#apps)
|
|
28
|
+
* [Manifest](#manifest)
|
|
29
|
+
* [Offline pages](#offline-pages)
|
|
27
30
|
* [Service worker](#service-worker)
|
|
28
31
|
* [Views](#views)
|
|
32
|
+
* [Configuration](#configuration)
|
|
29
33
|
* [To Do](#to-do)
|
|
30
34
|
* [Contributing](#contributing)
|
|
31
35
|
* [Contributors](#contributors)
|
|
@@ -56,9 +60,24 @@ If you always want to be up to date fetch the latest from GitHub in your `Gemfil
|
|
|
56
60
|
gem 'pwa', github: 'jonhue/pwa'
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
### Quick start
|
|
60
68
|
|
|
61
|
-
|
|
69
|
+
Run the generators:
|
|
70
|
+
|
|
71
|
+
$ rails g pwa:install
|
|
72
|
+
$ rails g pwa:app -n "App"
|
|
73
|
+
|
|
74
|
+
Noew define your app:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
Pwa.configure do |config|
|
|
78
|
+
config.define_app 'App'
|
|
79
|
+
end
|
|
80
|
+
```
|
|
62
81
|
|
|
63
82
|
Add the following to the `head` tag of your layout file:
|
|
64
83
|
|
|
@@ -75,18 +94,31 @@ Make sure to add the required javascript in `app/assets/javascripts/application.
|
|
|
75
94
|
Lastly, go to your routes file (`config/routes.rb`) and mount the `Pwa::Engine` class:
|
|
76
95
|
|
|
77
96
|
```ruby
|
|
78
|
-
mount Pwa::Engine, at: '
|
|
97
|
+
mount Pwa::Engine, at: ''
|
|
79
98
|
```
|
|
80
99
|
|
|
81
|
-
**Note:** The path `Pwa::Engine`
|
|
100
|
+
**Note:** The path `Pwa::Engine` is being mounted at, is currently required to be `''`.
|
|
82
101
|
|
|
83
|
-
|
|
102
|
+
### Apps
|
|
84
103
|
|
|
85
|
-
|
|
104
|
+
Progressive Web Apps for Rails allows for multiple Progressive Web Apps per Rails app:
|
|
86
105
|
|
|
87
|
-
|
|
106
|
+
```ruby
|
|
107
|
+
Pwa.configure do |config|
|
|
108
|
+
config.define_app 'Example', ['example.com', 'localhost:3000', 'lvh.me:3000']
|
|
109
|
+
config.define_app 'Subdomain', ['subdomain.example.com', 'subdomain.lvh.me:3000']
|
|
110
|
+
end
|
|
111
|
+
```
|
|
88
112
|
|
|
89
|
-
|
|
113
|
+
**Note:** You can omit the array of URL scopes if you have just one PWA.
|
|
114
|
+
|
|
115
|
+
#### Manifest
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
#### Offline pages
|
|
120
|
+
|
|
121
|
+
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.
|
|
90
122
|
|
|
91
123
|
### Service worker
|
|
92
124
|
|
|
@@ -114,6 +146,20 @@ To detect whether or not your app is currently being used as a Progressive Web A
|
|
|
114
146
|
|
|
115
147
|
---
|
|
116
148
|
|
|
149
|
+
## Configuration
|
|
150
|
+
|
|
151
|
+
You can configure Pwa by passing a block to `configure`. This can be done in `config/initializers/pwa.rb`:
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
Pwa.configure do |config|
|
|
155
|
+
config.define_app 'App', ['example.com']
|
|
156
|
+
end
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
* `define_app` Define apps with a name and URL scopes.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
117
163
|
## To Do
|
|
118
164
|
|
|
119
165
|
[Here](https://github.com/jonhue/pwa/projects/1) is the full list of current projects.
|
|
@@ -0,0 +1,19 @@
|
|
|
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)[0]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
data/app/helpers/pwa_helper.rb
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render "pwa/apps/manifests/#{@app.safe_name}" %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render "pwa/apps/offline/#{@app.safe_name}" %>
|
data/config/routes.rb
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
require 'rails/generators/migration'
|
|
3
|
+
|
|
4
|
+
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'
|
|
11
|
+
|
|
12
|
+
class_option :name, desc: 'App name', type: :string, default: 'index', aliases: '-n'
|
|
13
|
+
|
|
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
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
require 'rails/generators/migration'
|
|
3
|
+
|
|
4
|
+
module Pwa
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
include Rails::Generators::Migration
|
|
8
|
+
|
|
9
|
+
source_root File.join File.dirname(__FILE__), '../templates/install'
|
|
10
|
+
desc 'Install Progressive Web Apps for Rails'
|
|
11
|
+
|
|
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
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ var preLoad = function() {
|
|
|
6
6
|
console.log('[PWA] Install Event processing');
|
|
7
7
|
return caches.open('pwa-offline').then(function(cache) {
|
|
8
8
|
console.log('[PWA] Cached index and offline page during Install');
|
|
9
|
-
return cache.addAll(['/
|
|
9
|
+
return cache.addAll(['/offline']);
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -43,7 +43,7 @@ var returnFromCache = function(request) {
|
|
|
43
43
|
return caches.open('pwa-offline').then(function(cache) {
|
|
44
44
|
return cache.match(request).then(function(matching) {
|
|
45
45
|
if( !matching || matching.status == 404 ) {
|
|
46
|
-
return cache.match('
|
|
46
|
+
return cache.match('offline');
|
|
47
47
|
} else {
|
|
48
48
|
return matching;
|
|
49
49
|
};
|
data/lib/pwa.rb
CHANGED
data/lib/pwa/app.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
21
|
+
self.apps << ::Pwa::App.new(name, scope)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
data/lib/pwa/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pwa
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
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-01-
|
|
11
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -61,14 +61,20 @@ files:
|
|
|
61
61
|
- CHANGELOG.md
|
|
62
62
|
- LICENSE
|
|
63
63
|
- README.md
|
|
64
|
-
- app/controllers/pwa/
|
|
64
|
+
- app/controllers/pwa/apps_controller.rb
|
|
65
65
|
- app/helpers/pwa_helper.rb
|
|
66
|
+
- app/views/pwa/apps/manifest.json.erb
|
|
67
|
+
- app/views/pwa/apps/offline.html.erb
|
|
66
68
|
- config/routes.rb
|
|
67
|
-
- lib/generators/
|
|
68
|
-
- lib/generators/
|
|
69
|
-
- lib/generators/templates/
|
|
70
|
-
- lib/generators/templates/
|
|
69
|
+
- lib/generators/pwa/app_generator.rb
|
|
70
|
+
- lib/generators/pwa/install_generator.rb
|
|
71
|
+
- lib/generators/templates/app/manifest.json.erb
|
|
72
|
+
- lib/generators/templates/app/offline.html.erb
|
|
73
|
+
- lib/generators/templates/install/initializer.rb
|
|
74
|
+
- lib/generators/templates/install/service-worker.js
|
|
71
75
|
- lib/pwa.rb
|
|
76
|
+
- lib/pwa/app.rb
|
|
77
|
+
- lib/pwa/configuration.rb
|
|
72
78
|
- lib/pwa/engine.rb
|
|
73
79
|
- lib/pwa/version.rb
|
|
74
80
|
- vendor/assets/javascripts/pwa.js
|
|
@@ -82,10 +88,10 @@ post_install_message: |
|
|
|
82
88
|
|
|
83
89
|
There are two more steps to take:
|
|
84
90
|
|
|
85
|
-
1) Run `rails g pwa`
|
|
91
|
+
1) Run `rails g pwa:install` and `rails g pwa:install -n "Application Name"`
|
|
86
92
|
2) Mount engine in `config/routes.rb`:
|
|
87
93
|
|
|
88
|
-
mount Pwa::Engine, at: '
|
|
94
|
+
mount Pwa::Engine, at: ''
|
|
89
95
|
|
|
90
96
|
|
|
91
97
|
Learn more at https://github.com/jonhue/pwa
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
require 'rails/generators/migration'
|
|
3
|
-
|
|
4
|
-
class PwaGenerator < Rails::Generators::Base
|
|
5
|
-
|
|
6
|
-
include Rails::Generators::Migration
|
|
7
|
-
|
|
8
|
-
source_root File.join File.dirname(__FILE__), 'templates'
|
|
9
|
-
desc 'Install Progressive Web Apps for Rails'
|
|
10
|
-
|
|
11
|
-
def create_view
|
|
12
|
-
template 'view.html.erb', 'app/views/pwa/offline/index.html.erb'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def create_manifest
|
|
16
|
-
template 'manifest.json', 'public/manifest.json'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def create_service_worker
|
|
20
|
-
template 'service_worker.js', 'public/pwa-sw.js'
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
end
|