pwa 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +128 -0
- data/app/controllers/pwa/offline_controller.rb +8 -0
- data/config/routes.rb +5 -0
- data/lib/generators/pwa_generator.rb +19 -0
- data/lib/generators/templates/service_worker.js +52 -0
- data/lib/generators/templates/view.html.erb +4 -0
- data/lib/pwa.rb +7 -0
- data/lib/pwa/engine.rb +7 -0
- data/lib/pwa/version.rb +5 -0
- data/vendor/assets/javascripts/pwa.js +9 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7b6a1ba7a840009d8ff9cfd2d05199587fc08c0641bd3187c2ff4d9a6a74f47
|
4
|
+
data.tar.gz: 245d7d74734b5c6b80c1c2388de4224b283b7a2f7dcaf34f60991a2d2daf60d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95367870f106bcd063e895b8791b38c9750593841c8981094c5e0c0f70813d7f6ad68ff671f624648237c85ba032aa82836018c318df87481996513e000edbcd
|
7
|
+
data.tar.gz: 70625d53a80f4290f2591ed9cfddeb197590888576178fdec71348b4ef76a1aff64ba5286ee10674c4bccca5c3f0cb8c832235e318974078aebab5e6ed5da6d6
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +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.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
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 [devise-onseignal](https://github.com/jonhue/devise-onesignal) 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 [Native](https://github.com/NativeGap/native-rails).
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## Table of Contents
|
23
|
+
|
24
|
+
* [Installation](#installation)
|
25
|
+
* [Usage](#usage)
|
26
|
+
* [To Do](#to-do)
|
27
|
+
* [Contributing](#contributing)
|
28
|
+
* [Contributors](#contributors)
|
29
|
+
* [Semantic versioning](#semantic-versioning)
|
30
|
+
* [License](#license)
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Progressive Web Apps for Rails works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'pwa'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install pwa
|
49
|
+
|
50
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem 'pwa', github: 'jonhue/pwa'
|
54
|
+
```
|
55
|
+
|
56
|
+
Now run the generator:
|
57
|
+
|
58
|
+
$ rails g pwa
|
59
|
+
|
60
|
+
Make sure to add the required javascript in `app/assets/javascripts/application.js`:
|
61
|
+
|
62
|
+
```js
|
63
|
+
//= require pwa
|
64
|
+
```
|
65
|
+
|
66
|
+
Lastly, go to your routes file (`config/routes.rb`) and mount the `Pwa::Engine` class:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
mount Pwa::Engine, at: '/pwa'
|
70
|
+
```
|
71
|
+
|
72
|
+
**Note:** The path `Pwa::Engine` gets mounted at, is currently required to be `pwa`.
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
...
|
79
|
+
|
80
|
+
---
|
81
|
+
|
82
|
+
## To Do
|
83
|
+
|
84
|
+
[Here](https://github.com/jonhue/pwa/projects/1) is the full list of current projects.
|
85
|
+
|
86
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/pwa/issues/new).
|
87
|
+
|
88
|
+
---
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
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:
|
93
|
+
|
94
|
+
[Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
|
95
|
+
|
96
|
+
### Contributors
|
97
|
+
|
98
|
+
Give the people some :heart: who are working on this project. See them all at:
|
99
|
+
|
100
|
+
https://github.com/jonhue/pwa/graphs/contributors
|
101
|
+
|
102
|
+
### Semantic Versioning
|
103
|
+
|
104
|
+
Progressive Web Apps for Rails follows Semantic Versioning 2.0 as defined at http://semver.org.
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
MIT License
|
109
|
+
|
110
|
+
Copyright (c) 2018 Jonas Hübotter
|
111
|
+
|
112
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
113
|
+
of this software and associated documentation files (the "Software"), to deal
|
114
|
+
in the Software without restriction, including without limitation the rights
|
115
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
116
|
+
copies of the Software, and to permit persons to whom the Software is
|
117
|
+
furnished to do so, subject to the following conditions:
|
118
|
+
|
119
|
+
The above copyright notice and this permission notice shall be included in all
|
120
|
+
copies or substantial portions of the Software.
|
121
|
+
|
122
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
123
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
124
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
125
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
126
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
127
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
128
|
+
SOFTWARE.
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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_service_worker
|
16
|
+
template 'service_worker.js', 'public/pwa-sw.js'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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(['/pwa/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('pwa/offline');
|
47
|
+
} else {
|
48
|
+
return matching;
|
49
|
+
};
|
50
|
+
});
|
51
|
+
});
|
52
|
+
};
|
data/lib/pwa.rb
ADDED
data/lib/pwa/engine.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
if (navigator.serviceWorker.controller) {
|
2
|
+
console.log('[PWA] Active service worker found')
|
3
|
+
} else {
|
4
|
+
navigator.serviceWorker.register( '/pwa-sw.js', { scope: './' }).then(function(reg) {
|
5
|
+
console.log( '[PWA] ServiceWorker registration successful with scope: ', reg.scope );
|
6
|
+
}, function(err) {
|
7
|
+
console.log( '[PWA] ServiceWorker registration failed: ', err );
|
8
|
+
});
|
9
|
+
}
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pwa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Hübotter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.52'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.52'
|
55
|
+
description: Progressive Web Apps for Rails.
|
56
|
+
email: me@jonhue.me
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- CHANGELOG.md
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- app/controllers/pwa/offline_controller.rb
|
65
|
+
- config/routes.rb
|
66
|
+
- lib/generators/pwa_generator.rb
|
67
|
+
- lib/generators/templates/service_worker.js
|
68
|
+
- lib/generators/templates/view.html.erb
|
69
|
+
- lib/pwa.rb
|
70
|
+
- lib/pwa/engine.rb
|
71
|
+
- lib/pwa/version.rb
|
72
|
+
- vendor/assets/javascripts/pwa.js
|
73
|
+
homepage: https://github.com/jonhue/pwa
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message: |
|
78
|
+
**Thank you for installing Progressive Web Apps for Rails!**
|
79
|
+
|
80
|
+
|
81
|
+
There are two more steps to take:
|
82
|
+
|
83
|
+
1) Run `rails g pwa`
|
84
|
+
2) Mount engine in `config/routes.rb`:
|
85
|
+
|
86
|
+
mount Pwa::Engine, at: '/pwa'
|
87
|
+
|
88
|
+
|
89
|
+
Learn more at https://github.com/jonhue/pwa
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.3'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.4
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Progressive Web Apps for Rails
|
109
|
+
test_files: []
|