parklife-sinatra 0.2.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/Appraisals +17 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +8 -0
- data/gemfiles/sinatra_3.x.gemfile +11 -0
- data/gemfiles/sinatra_4.0.gemfile +11 -0
- data/gemfiles/sinatra_4.1.gemfile +11 -0
- data/gemfiles/sinatra_4.2.gemfile +11 -0
- data/lib/parklife/sinatra/build_integration.rb +22 -0
- data/lib/parklife/sinatra/version.rb +6 -0
- data/lib/parklife/sinatra.rb +9 -0
- data/lib/parklife-sinatra.rb +2 -0
- data/test/parklife/sinatra_test.rb +43 -0
- metadata +86 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4f8fd65347eb1d8299aabdd1c8dbdaaf3c568b3a28a2399aa49bb5105e9f3c13
|
|
4
|
+
data.tar.gz: 1b8cb1e5e36b3de325a45d86d8f5aba9bf20c81a69bc46327ad5c9a857607f58
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1142f2dd06751a189e4712115748ae0bc9c29d4d28dbc2b23bf4d396d9dbad428683dbdc17c6c09c4d5ccd479f62242f1e5a6d0e4618a573b8b44776a3ad5608
|
|
7
|
+
data.tar.gz: 1ba39d822b5cf03756dfa94d0248cc13e9aafafe77c43b04ce83c47ad38d329ba304d587d2311eb335589b79fd5c372723bb7d67b7ff6088cb9165cd6f08adfc
|
data/Appraisals
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
appraise 'sinatra_3.x' do
|
|
4
|
+
gem 'sinatra', '~> 3.0'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
appraise 'sinatra_4.0' do
|
|
8
|
+
gem 'sinatra', '~> 4.0.0'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
appraise 'sinatra_4.1' do
|
|
12
|
+
gem 'sinatra', '~> 4.1.0'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
appraise 'sinatra_4.2' do
|
|
16
|
+
gem 'sinatra', '~> 4.2.0'
|
|
17
|
+
end
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"parklife-sinatra" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["spideryoung@gmail.com"](mailto:"spideryoung@gmail.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ben Pickles
|
|
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,89 @@
|
|
|
1
|
+
# Parklife::Sinatra
|
|
2
|
+
|
|
3
|
+
[](https://github.com/benpickles/parklife-sinatra/actions/workflows/main.yml)
|
|
4
|
+
|
|
5
|
+
Parklife's Sinatra integration ensures Sinatra's host authorization is disabled during a `parklife` build.
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
Add the gem to your application's `Gemfile`:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
gem 'parklife-sinatra'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Parklife is configured with a file called `Parkfile` in the root of your project, here's an example `Parkfile` for an imaginary Sinatra app:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
# Assuming your Sinatra app lives in ./app.rb:
|
|
19
|
+
require_relative 'app'
|
|
20
|
+
|
|
21
|
+
Parklife.application.configure do |config|
|
|
22
|
+
# For a Sinatra "classic" app:
|
|
23
|
+
config.app = Sinatra::Application
|
|
24
|
+
|
|
25
|
+
# Or for Sinatra modular style:
|
|
26
|
+
# config.app = App
|
|
27
|
+
#
|
|
28
|
+
# The Parklife extension must be registered for a modular style Sinatra app:
|
|
29
|
+
# App.register Parklife::Sinatra
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Parkfile.application.routes do
|
|
33
|
+
# Start from the homepage and crawl all links.
|
|
34
|
+
root crawl: true
|
|
35
|
+
|
|
36
|
+
# Some extra paths that aren't discovered while crawling.
|
|
37
|
+
get '/feed.atom'
|
|
38
|
+
get '/sitemap.xml'
|
|
39
|
+
|
|
40
|
+
# A couple more hidden pages.
|
|
41
|
+
get '/easter_egg', crawl: true
|
|
42
|
+
|
|
43
|
+
# Services typically allow a custom 404 page.
|
|
44
|
+
get '/404.html'
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Listing the routes included in the above Parklife application with `parklife routes` would output the following:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ bundle exec parklife routes
|
|
52
|
+
/ crawl=true
|
|
53
|
+
/feed.atom
|
|
54
|
+
/sitemap.xml
|
|
55
|
+
/easter_egg crawl=true
|
|
56
|
+
/404.html
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Now you can run `parklife build` which will fetch all the routes and save them to the `build` directory ready to be served as a static site. Inspecting the build directory might look like this:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
$ find build -type f
|
|
63
|
+
build/404.html
|
|
64
|
+
build/about/index.html
|
|
65
|
+
build/blog/index.html
|
|
66
|
+
build/blog/2019/03/07/developers-developers-developers/index.html
|
|
67
|
+
build/blog/2019/04/21/modern-life-is-rubbish/index.html
|
|
68
|
+
build/blog/2019/05/15/introducing-parklife/index.html
|
|
69
|
+
build/easter_egg/index.html
|
|
70
|
+
build/easter_egg/surprise/index.html
|
|
71
|
+
build/index.html
|
|
72
|
+
build/location/index.html
|
|
73
|
+
build/feed.atom
|
|
74
|
+
build/sitemap.xml
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Parklife doesn't know about assets (images, CSS, etc) so you likely also need to generate those and copy them to the build directory.
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/benpickles/parklife-sinatra>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/benpickles/parklife-sinatra/blob/main/CODE_OF_CONDUCT.md).
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
86
|
+
|
|
87
|
+
## Code of Conduct
|
|
88
|
+
|
|
89
|
+
Everyone interacting in the Parklife::Sinatra project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/benpickles/parklife-sinatra/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'sinatra/base'
|
|
3
|
+
|
|
4
|
+
module Parklife
|
|
5
|
+
module Sinatra
|
|
6
|
+
module BuildIntegration
|
|
7
|
+
def self.registered(app)
|
|
8
|
+
# Disable Rack::Protection::HostAuthorization middleware so that
|
|
9
|
+
# fetching a page with Parklife works in development without manual
|
|
10
|
+
# intervention.
|
|
11
|
+
#
|
|
12
|
+
# It's safe to disable this security feature at this point because it's
|
|
13
|
+
# only included when running a `parklife` command.
|
|
14
|
+
if app.settings.respond_to?(:host_authorization)
|
|
15
|
+
app.set(:host_authorization, permitted_hosts: [])
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Sinatra.register Parklife::Sinatra::BuildIntegration
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Only require the build integration when running from a Parklife CLI command.
|
|
4
|
+
#
|
|
5
|
+
# This means that the gem can safely be included in the app's Gemfile without
|
|
6
|
+
# applying any of its build-time tweaks.
|
|
7
|
+
if defined?(Parklife::CLI)
|
|
8
|
+
require_relative 'sinatra/build_integration'
|
|
9
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
require 'minitest/pride'
|
|
4
|
+
|
|
5
|
+
describe 'Parklife/Sinatra integration' do
|
|
6
|
+
def build_dir
|
|
7
|
+
'example-app/build'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def build_paths
|
|
11
|
+
Dir.glob('**/*', base: build_dir).select { |path|
|
|
12
|
+
File.file?(File.join(build_dir, path))
|
|
13
|
+
}.sort
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def parklife(cmd)
|
|
17
|
+
Dir.chdir('example-app') do
|
|
18
|
+
capture_subprocess_io do
|
|
19
|
+
system("bundle exec parklife #{cmd}")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'host authorization middleware is disabled by default (i.e. it works)' do
|
|
25
|
+
parklife 'build'
|
|
26
|
+
|
|
27
|
+
assert_equal(
|
|
28
|
+
[
|
|
29
|
+
'index.html',
|
|
30
|
+
'hello/bar/index.html',
|
|
31
|
+
'hello/baz/index.html',
|
|
32
|
+
'hello/foo/index.html',
|
|
33
|
+
].sort,
|
|
34
|
+
build_paths
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'a custom base is interpreted correctly' do
|
|
39
|
+
parklife 'build --base /custom'
|
|
40
|
+
content = File.read(File.join(build_dir, 'index.html'))
|
|
41
|
+
assert_match %r{<a href="/custom/hello/foo">foo</a>}, content
|
|
42
|
+
end
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: parklife-sinatra
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ben Pickles
|
|
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: parklife
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.8'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.8'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: sinatra
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
email:
|
|
41
|
+
- spideryoung@gmail.com
|
|
42
|
+
executables: []
|
|
43
|
+
extensions: []
|
|
44
|
+
extra_rdoc_files: []
|
|
45
|
+
files:
|
|
46
|
+
- Appraisals
|
|
47
|
+
- CHANGELOG.md
|
|
48
|
+
- CODE_OF_CONDUCT.md
|
|
49
|
+
- LICENSE.txt
|
|
50
|
+
- README.md
|
|
51
|
+
- Rakefile
|
|
52
|
+
- gemfiles/sinatra_3.x.gemfile
|
|
53
|
+
- gemfiles/sinatra_4.0.gemfile
|
|
54
|
+
- gemfiles/sinatra_4.1.gemfile
|
|
55
|
+
- gemfiles/sinatra_4.2.gemfile
|
|
56
|
+
- lib/parklife-sinatra.rb
|
|
57
|
+
- lib/parklife/sinatra.rb
|
|
58
|
+
- lib/parklife/sinatra/build_integration.rb
|
|
59
|
+
- lib/parklife/sinatra/version.rb
|
|
60
|
+
- test/parklife/sinatra_test.rb
|
|
61
|
+
homepage: https://parklife.dev/sinatra
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
changelog_uri: https://github.com/benpickles/parklife-sinatra/blob/main/CHANGELOG.md
|
|
66
|
+
homepage_uri: https://parklife.dev/sinatra
|
|
67
|
+
rubygems_mfa_required: 'true'
|
|
68
|
+
source_code_uri: https://github.com/benpickles/parklife-sinatra
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 2.5.0
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubygems_version: 3.6.9
|
|
84
|
+
specification_version: 4
|
|
85
|
+
summary: Sinatra integration for Parklife
|
|
86
|
+
test_files: []
|