pwa_manifest_generator 0.1.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 +7 -0
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +8 -0
- data/lib/generators/pwa_manifest_generator/install/install_generator.rb +16 -0
- data/lib/generators/pwa_manifest_generator/install/templates/manifest.json.erb +31 -0
- data/lib/pwa_manifest_generator/builder.rb +48 -0
- data/lib/pwa_manifest_generator/edge_side_panel.rb +18 -0
- data/lib/pwa_manifest_generator/freezeable.rb +36 -0
- data/lib/pwa_manifest_generator/html_array.rb +10 -0
- data/lib/pwa_manifest_generator/icon.rb +20 -0
- data/lib/pwa_manifest_generator/intent.rb +30 -0
- data/lib/pwa_manifest_generator/launch_handler.rb +25 -0
- data/lib/pwa_manifest_generator/manifest_map.rb +65 -0
- data/lib/pwa_manifest_generator/screenshot.rb +20 -0
- data/lib/pwa_manifest_generator/shortcut.rb +27 -0
- data/lib/pwa_manifest_generator/url_handler.rb +32 -0
- data/lib/pwa_manifest_generator/version.rb +5 -0
- data/lib/pwa_manifest_generator.rb +19 -0
- data/sig/pwa_manifest_generator.rbs +4 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e4de717efb25a84a9df654237942cfc49308a731fb327f9b3d83482daa89b330
|
4
|
+
data.tar.gz: 98df6a149dc625d31e49ac829213ac609ac04f209041bbbc04aa2db7a4ad7b80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b31e309fe098da37fb8bdb44d675e9b53c2be274889a1395326686201d6b832d5792b129f00f64583bdf15e5d9611887d566e8047e7ea2ed6f4dcfad6c20544f
|
7
|
+
data.tar.gz: 32b014e3cd7fbeb82201a4bc77f64565cf37e29612e60af3a2175003c75923e098d86710e3545677d4432c42749410b4efad28e25a45dc393c85590099aab9b4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# RuboCop configuration for pwa_manifest_generator
|
2
|
+
Rails/OutputSafety:
|
3
|
+
Enabled: false
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Enabled: false
|
6
|
+
Metrics/MethodLength:
|
7
|
+
Enabled: false
|
8
|
+
Metrics/CyclomaticComplexity:
|
9
|
+
Enabled: false
|
10
|
+
Naming/PredicateMethod:
|
11
|
+
Enabled: false
|
12
|
+
Lint/DuplicateBranch:
|
13
|
+
Enabled: false
|
14
|
+
Gemspec/RequiredRubyVersion:
|
15
|
+
Enabled: false
|
16
|
+
Minitest/UselessAssertion:
|
17
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Daniel Laloush
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# PwaManifestGenerator
|
2
|
+
|
3
|
+
A Rails engine and gem for generating and managing PWA (Progressive Web App) manifests with advanced configuration, validation, and Rails generator support.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
- Strongly-typed manifest builder with validation
|
7
|
+
- Rails generator to install and override `pwa/manifest.json.erb`
|
8
|
+
- Supports all modern PWA manifest fields, including advanced keys (shortcuts, screenshots, edge_side_panel, etc.)
|
9
|
+
- Extensible and testable Ruby code
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'pwa_manifest_generator', github: 'Dandush03/pwa_manifest_generator'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Rails Setup
|
27
|
+
Run the install generator to copy the manifest template:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
bin/rails generate pwa_manifest_generator:install
|
31
|
+
```
|
32
|
+
|
33
|
+
This will override `app/views/pwa/manifest.json.erb` with a template that uses your Rails config.
|
34
|
+
|
35
|
+
### Configuration Example
|
36
|
+
In an initializer (e.g. `config/initializers/pwa.rb`):
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
PwaManifestGenerator::Builder.config do |pwa|
|
40
|
+
pwa.name = 'My App'
|
41
|
+
pwa.short_name = 'App'
|
42
|
+
pwa.start_url = '/'
|
43
|
+
# ...set other keys as needed
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
### Manifest Template
|
48
|
+
The generated `manifest.json.erb` will use your configuration and output a valid PWA manifest.
|
49
|
+
|
50
|
+
## Development
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Run tests with:
|
52
|
+
|
53
|
+
```sh
|
54
|
+
rake test
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Dandush03/pwa_manifest_generator.
|
59
|
+
|
60
|
+
## License
|
61
|
+
MIT License. See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module PwaManifestGenerator
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc 'Installs a manifest.json.erb for PWA configuration.'
|
10
|
+
|
11
|
+
def copy_manifest
|
12
|
+
template 'manifest.json.erb', 'app/views/pwa/manifest.json.erb', force: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%- pwa = Rails.application.config.pwa %>
|
2
|
+
{
|
3
|
+
"name": "<%= pwa.name %>",
|
4
|
+
"short_name": "<%= pwa.short_name %>",
|
5
|
+
"description": "<%= pwa.description %>",
|
6
|
+
"start_url": "<%= pwa.start_url %>",
|
7
|
+
"display": "<%= pwa.display_setting %>",
|
8
|
+
"id": "<%= pwa.id %>",
|
9
|
+
"iarc_rating_id": "<%= pwa.iarc_rating_id %>",
|
10
|
+
"launch_handler": <%= pwa.launch_handler.to_html %>,
|
11
|
+
"lang": "<%= I18n.locale %>",
|
12
|
+
"categories": <%= pwa.categories.to_html %>,
|
13
|
+
"orientation": "<%= pwa.orientation %>",
|
14
|
+
"display_override": <%= pwa.display_override.to_html %>,
|
15
|
+
"intent_filters": <%= pwa.intent.filters.to_html %>,
|
16
|
+
"url_handlers": <%= pwa.url_handlers.to_html %>,
|
17
|
+
"icons": <%= pwa.icons.to_html %>,
|
18
|
+
"prefer_related_applications": <%= pwa.prefer_related_applications %>,
|
19
|
+
"related_applications": <%= pwa.related_applications.to_html %>,
|
20
|
+
"scope_extensions": <%= pwa.scope_extensions.to_html %>,
|
21
|
+
"file_handlers": <%= pwa.file_handlers.to_html %>,
|
22
|
+
"dir": "<%= dir_ltr? ? 'ltr' : 'rtl' %>",
|
23
|
+
"edge_side_panel": <%= pwa.edge_side_panel %>,
|
24
|
+
"protocol_handlers": <%= pwa.protocol_handlers.to_html %>,
|
25
|
+
"screenshots": <%= pwa.screenshots.to_html %>,
|
26
|
+
"shortcuts": <%= pwa.shortcuts.to_html %>,
|
27
|
+
"handle_links": <%= pwa.handle_links %>,
|
28
|
+
"scope": "<%= pwa.scope %>",
|
29
|
+
"theme_color": "<%= pwa.theme_color %>",
|
30
|
+
"background_color": "<%= pwa.background_color %>"
|
31
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'freezeable'
|
4
|
+
require_relative 'manifest_map'
|
5
|
+
require_relative 'launch_handler'
|
6
|
+
require_relative 'intent'
|
7
|
+
require_relative 'url_handler'
|
8
|
+
|
9
|
+
module PwaManifestGenerator
|
10
|
+
class Builder
|
11
|
+
include Freezeable
|
12
|
+
|
13
|
+
attr_accessor(*ManifestMap::KEYS)
|
14
|
+
|
15
|
+
# Singleton instance for Rails config
|
16
|
+
def self.instance
|
17
|
+
@instance ||= new
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# Rails-style config method (class and instance)
|
22
|
+
def self.config(&block)
|
23
|
+
instance.config(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def config
|
27
|
+
yield self if block_given?
|
28
|
+
self.class.freeze_config!(self)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@launch_handler = LaunchHandler.new
|
34
|
+
@intent = Intent.new
|
35
|
+
@url_handlers = UrlHandler.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_key!(key)
|
39
|
+
ManifestMap.ensure_valid_key(self, key)
|
40
|
+
# Deep validation for nested objects
|
41
|
+
value = send(key)
|
42
|
+
if value.respond_to?(:valid?) && !value.valid?
|
43
|
+
raise ArgumentError, "Invalid value for #{key}: #{value.inspect}"
|
44
|
+
end
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
require 'json'
|
5
|
+
module PwaManifestGenerator
|
6
|
+
class EdgeSidePanel
|
7
|
+
attr_accessor :preferred_width
|
8
|
+
|
9
|
+
def initialize(preferred_width: 400)
|
10
|
+
@preferred_width = preferred_width
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_html
|
14
|
+
json = { preferred_width: @preferred_width }.to_json
|
15
|
+
json.respond_to?(:html_safe) ? json.html_safe : json
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PwaManifestGenerator
|
4
|
+
module Freezeable
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def freeze_config!(instance)
|
11
|
+
PwaManifestGenerator::ManifestMap::KEYS.each do |key|
|
12
|
+
var = "@#{key}"
|
13
|
+
unless instance.instance_variable_defined?(var)
|
14
|
+
instance.instance_variable_set(var, PwaManifestGenerator::ManifestMap.default_value_for(key))
|
15
|
+
end
|
16
|
+
instance.validate_key!(key) unless instance.send(key).nil?
|
17
|
+
|
18
|
+
value = instance.instance_variable_get(var)
|
19
|
+
# Only define singleton methods on this instance
|
20
|
+
instance.define_singleton_method(key) { value }
|
21
|
+
instance.define_singleton_method("#{key}=") do |_value|
|
22
|
+
raise ArgumentError, 'Cannot modify frozen PWA configuration'
|
23
|
+
end
|
24
|
+
|
25
|
+
if instance.send(:"#{key}").respond_to?(:freeze_config!)
|
26
|
+
instance.send(:"#{key}").freeze_config!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
instance.define_singleton_method(:instance_variable_set) do |_name, _value|
|
31
|
+
raise ArgumentError, 'Cannot modify frozen PWA configuration'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PwaManifestGenerator
|
4
|
+
class Icon
|
5
|
+
attr_accessor :src, :sizes, :type, :purpose
|
6
|
+
|
7
|
+
def initialize(src:, sizes:, type:, purpose: nil)
|
8
|
+
@src = src
|
9
|
+
@sizes = sizes
|
10
|
+
@type = type
|
11
|
+
@purpose = purpose
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
h = { src: @src, sizes: @sizes, type: @type }
|
16
|
+
h[:purpose] = @purpose if @purpose
|
17
|
+
h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
5
|
+
require_relative 'freezeable'
|
6
|
+
require_relative 'html_array'
|
7
|
+
|
8
|
+
module PwaManifestGenerator
|
9
|
+
class Intent
|
10
|
+
include Freezeable
|
11
|
+
|
12
|
+
attr_reader :filters
|
13
|
+
|
14
|
+
def initialize(filters = [])
|
15
|
+
@filters = HTMLArray.new(filters)
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
@filters.all? do |filter|
|
20
|
+
filter.is_a?(Hash) && filter.key?(:scope_url_scheme) &&
|
21
|
+
filter.key?(:scope_url_host) && filter.key?(:scope_url_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_html
|
26
|
+
html = @filters.to_html
|
27
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'freezeable'
|
4
|
+
require_relative 'html_array'
|
5
|
+
|
6
|
+
module PwaManifestGenerator
|
7
|
+
class LaunchHandler
|
8
|
+
include Freezeable
|
9
|
+
|
10
|
+
attr_accessor :client_mode
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@client_mode = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid?
|
17
|
+
@client_mode.is_a?(Array)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_html
|
21
|
+
json = { client_mode: @client_mode }.to_json
|
22
|
+
json.respond_to?(:html_safe) ? json.html_safe : json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'html_array'
|
4
|
+
|
5
|
+
module PwaManifestGenerator
|
6
|
+
class ManifestMap
|
7
|
+
KEYS_TYPE_MAP = {
|
8
|
+
name: String, short_name: String, description: String, start_url: String,
|
9
|
+
scope: String, theme_color: String, background_color: String, display_setting: String,
|
10
|
+
id: String, iarc_rating_id: String, launch_handler: Hash, categories: Array,
|
11
|
+
orientation: String, display_override: Array, intent: Array, url_handlers: Array, icons: Array,
|
12
|
+
screenshots: Array, prefer_related_applications: [TrueClass, FalseClass], related_applications: Array,
|
13
|
+
scope_extensions: Array, file_handlers: Array, edge_side_panel: String, protocol_handlers: Array,
|
14
|
+
shortcuts: Array, handle_links: [TrueClass, FalseClass]
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
KEYS = KEYS_TYPE_MAP.keys.freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def ensure_valid_key(instance, key)
|
21
|
+
raise ArgumentError, "Unknown key: #{key}" unless KEYS.include?(key)
|
22
|
+
|
23
|
+
case key
|
24
|
+
when :launch_handler, :intent, :url_handlers
|
25
|
+
# Custom handler validation can be implemented here
|
26
|
+
when :prefer_related_applications, :handle_links
|
27
|
+
unless KEYS_TYPE_MAP[key].include?(instance.send(key).class)
|
28
|
+
raise ArgumentError, "Invalid type for #{key}: #{instance.send(key).class}"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
unless instance.send(key).is_a?(KEYS_TYPE_MAP[key])
|
32
|
+
raise ArgumentError, "Invalid type for #{key}: #{instance.send(key).class}"
|
33
|
+
end
|
34
|
+
|
35
|
+
if instance.send(key).is_a?(Array)
|
36
|
+
instance.instance_variable_set("@#{key}",
|
37
|
+
HTMLArray.new(instance.send(key)))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def key_valid?(key)
|
44
|
+
KEYS.include?(key)
|
45
|
+
end
|
46
|
+
|
47
|
+
def default_value_for(key)
|
48
|
+
case key
|
49
|
+
when :name then 'AppName'
|
50
|
+
when :short_name then 'AppName'
|
51
|
+
when :description then 'A Progressive Web App'
|
52
|
+
when :start_url then '/'
|
53
|
+
when :scope then '/'
|
54
|
+
when :theme_color, :background_color then '#FFFFFF'
|
55
|
+
when :display_setting then 'standalone'
|
56
|
+
when :orientation then 'any'
|
57
|
+
when :display_override then %w[standalone window-controls-overlay minimal-ui]
|
58
|
+
when :categories, :icons, :screenshots, :intent, :url_handlers, :related_applications,
|
59
|
+
:scope_extensions, :file_handlers, :protocol_handlers, :shortcuts then []
|
60
|
+
when :prefer_related_applications, :handle_links then false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PwaManifestGenerator
|
4
|
+
class Screenshot
|
5
|
+
attr_accessor :src, :sizes, :type, :label
|
6
|
+
|
7
|
+
def initialize(src:, sizes:, type:, label: nil)
|
8
|
+
@src = src
|
9
|
+
@sizes = sizes
|
10
|
+
@type = type
|
11
|
+
@label = label
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
h = { src: @src, sizes: @sizes, type: @type }
|
16
|
+
h[:label] = @label if @label
|
17
|
+
h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'icon'
|
4
|
+
|
5
|
+
module PwaManifestGenerator
|
6
|
+
class Shortcut
|
7
|
+
attr_accessor :name, :url, :description, :icons
|
8
|
+
|
9
|
+
def initialize(name:, url:, description:, icons: [])
|
10
|
+
@name = name
|
11
|
+
@url = url
|
12
|
+
@description = description
|
13
|
+
@icons = icons.map do |icon|
|
14
|
+
icon.is_a?(Icon) ? icon : Icon.new(**icon)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
{
|
20
|
+
name: @name,
|
21
|
+
url: @url,
|
22
|
+
description: @description,
|
23
|
+
icons: @icons.map(&:to_h)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'freezeable'
|
4
|
+
|
5
|
+
module PwaManifestGenerator
|
6
|
+
class UrlHandler
|
7
|
+
include Freezeable
|
8
|
+
|
9
|
+
attr_reader :scope
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@scope = Struct.new(:matches, :launch_url).new([], 'https://localhost:3000')
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
@scope.matches.all? do |match|
|
17
|
+
match.is_a?(String) && match.start_with?('http://', 'https://')
|
18
|
+
end &&
|
19
|
+
@scope.launch_url.is_a?(String) && @scope.launch_url.start_with?('http://', 'https://')
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_html
|
23
|
+
json = {
|
24
|
+
scope: {
|
25
|
+
matches: @scope.matches,
|
26
|
+
launch_url: @scope.launch_url
|
27
|
+
}
|
28
|
+
}.to_json
|
29
|
+
json.respond_to?(:html_safe) ? json.html_safe : json
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'pwa_manifest_generator/version'
|
4
|
+
require_relative 'pwa_manifest_generator/freezeable'
|
5
|
+
require_relative 'pwa_manifest_generator/html_array'
|
6
|
+
require_relative 'pwa_manifest_generator/manifest_map'
|
7
|
+
require_relative 'pwa_manifest_generator/intent'
|
8
|
+
require_relative 'pwa_manifest_generator/launch_handler'
|
9
|
+
require_relative 'pwa_manifest_generator/url_handler'
|
10
|
+
require_relative 'pwa_manifest_generator/builder'
|
11
|
+
require_relative 'pwa_manifest_generator/edge_side_panel'
|
12
|
+
require_relative 'pwa_manifest_generator/icon'
|
13
|
+
require_relative 'pwa_manifest_generator/shortcut'
|
14
|
+
require_relative 'pwa_manifest_generator/screenshot'
|
15
|
+
|
16
|
+
module PwaManifestGenerator
|
17
|
+
class Error < StandardError; end
|
18
|
+
# Main gem entry point. Use PwaManifestGenerator::Builder for configuration.
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pwa_manifest_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Laloush
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '7.0'
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '9.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '7.0'
|
29
|
+
- - "<"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '9.0'
|
32
|
+
description: " This gem helps you generate, validate, and manage Progressive Web
|
33
|
+
App (PWA) manifests in your Rails application, with advanced configuration, validation,
|
34
|
+
and generator support. See https://github.com/Dandush03/pwa_manifest_generator for
|
35
|
+
details.\n"
|
36
|
+
email:
|
37
|
+
- d.laloush@outlook.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- ".rubocop.yml"
|
43
|
+
- CHANGELOG.md
|
44
|
+
- CODE_OF_CONDUCT.md
|
45
|
+
- LICENSE.txt
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/generators/pwa_manifest_generator/install/install_generator.rb
|
49
|
+
- lib/generators/pwa_manifest_generator/install/templates/manifest.json.erb
|
50
|
+
- lib/pwa_manifest_generator.rb
|
51
|
+
- lib/pwa_manifest_generator/builder.rb
|
52
|
+
- lib/pwa_manifest_generator/edge_side_panel.rb
|
53
|
+
- lib/pwa_manifest_generator/freezeable.rb
|
54
|
+
- lib/pwa_manifest_generator/html_array.rb
|
55
|
+
- lib/pwa_manifest_generator/icon.rb
|
56
|
+
- lib/pwa_manifest_generator/intent.rb
|
57
|
+
- lib/pwa_manifest_generator/launch_handler.rb
|
58
|
+
- lib/pwa_manifest_generator/manifest_map.rb
|
59
|
+
- lib/pwa_manifest_generator/screenshot.rb
|
60
|
+
- lib/pwa_manifest_generator/shortcut.rb
|
61
|
+
- lib/pwa_manifest_generator/url_handler.rb
|
62
|
+
- lib/pwa_manifest_generator/version.rb
|
63
|
+
- sig/pwa_manifest_generator.rbs
|
64
|
+
homepage: https://github.com/Dandush03/pwa_manifest_generator
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
homepage_uri: https://github.com/Dandush03/pwa_manifest_generator
|
69
|
+
source_code_uri: https://github.com/Dandush03/pwa_manifest_generator
|
70
|
+
changelog_uri: https://github.com/Dandush03/pwa_manifest_generator/releases
|
71
|
+
rubygems_mfa_required: 'true'
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 3.0.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.7.0
|
87
|
+
specification_version: 4
|
88
|
+
summary: A Rails engine and gem for generating and managing PWA manifests.
|
89
|
+
test_files: []
|