parklife 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c94649aadc5cc8fe79a9215950b461adfdf658ec56c396c42d3e69e9e6082d3
4
- data.tar.gz: 54c2b0b8c4f8a8a5149d10b5f649d0009e9c9f32201d85acc8960bb595ea1e9c
3
+ metadata.gz: 716fff5f3d7ad38f43c2fd071de3a69dc58363b05fb7fd3d997311855a207f04
4
+ data.tar.gz: b153dc13fb74648185401f3a512c34eee2f0ad62659723937c0354d9c7547ecd
5
5
  SHA512:
6
- metadata.gz: 3e77cf82affdd32b75f747c2a9a4bc7aaf8df14d0b847470b241b1fb34e3f98b8aea13fdb55430caff5a420e28a5ba0dc6e80d32505e315428317fb42a5fd9d6
7
- data.tar.gz: d80856454fb213de0ef217f18518d42bed3f0a4e57b870f22d2e8eaa72b1cec45123e0c84b38f875b6cd85a62f543381437c8e8200cff87a31f3b2683671f94e
6
+ metadata.gz: 7a1a022c68a6a7c77277440c926cd430ebf857a7757f42eab76b8233af84bdc4dd9407952a9465720a6a74e43d7706b8acb41a25705ebb3d0e34c9a75a11b441
7
+ data.tar.gz: 80af344c3209f6a57f147714c789d6c3d21a42cd3131186e9dbebb0e267d19258cdb297f13f273baefdb4bbd4bcba955c2c1e726ee9e218d8febaf50ec4c26c8
@@ -56,9 +56,9 @@ jobs:
56
56
  - uses: ruby/setup-ruby@v1
57
57
  with:
58
58
  bundler-cache: true
59
- ruby-version: '2.7'
59
+ ruby-version: '3.4'
60
60
  working-directory: examples/sinatra
61
- - run: bundle exec parklife build
61
+ - run: bin/static-build
62
62
  working-directory: examples/sinatra
63
63
  - run: test -f build/index.html
64
64
  working-directory: examples/sinatra
@@ -3,9 +3,56 @@ name: Tests
3
3
  on: push
4
4
 
5
5
  jobs:
6
+ rails:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ rails:
12
+ - '7.0'
13
+ - '7.1'
14
+ - '7.2'
15
+ - '8.0'
16
+ ruby:
17
+ - '2.7'
18
+ - '3.0'
19
+ - '3.1'
20
+ - '3.2'
21
+ - '3.3'
22
+ - '3.4'
23
+ exclude:
24
+ # Rails 8.0 requires Ruby 3.2.
25
+ - rails: '8.0'
26
+ ruby: '3.1'
27
+ - rails: '8.0'
28
+ ruby: '3.0'
29
+ - rails: '8.0'
30
+ ruby: '2.7'
31
+
32
+ # Rails 7.2 requires Ruby 3.1.
33
+ - rails: '7.2'
34
+ ruby: '3.0'
35
+ - rails: '7.2'
36
+ ruby: '2.7'
37
+
38
+ # Rails 7.0 doesn't work out of the box with Ruby 3.4.
39
+ - rails: '7.0'
40
+ ruby: '3.4'
41
+ env:
42
+ BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
43
+ name: Rails (Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }})
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ bundler-cache: true
49
+ ruby-version: ${{ matrix.ruby }}
50
+ - run: bundle exec rspec --pattern "spec/**/*rails*"
51
+
6
52
  rspec:
7
53
  runs-on: ubuntu-latest
8
54
  strategy:
55
+ fail-fast: false
9
56
  matrix:
10
57
  ruby:
11
58
  - '2.7'
@@ -13,22 +60,50 @@ jobs:
13
60
  - '3.1'
14
61
  - '3.2'
15
62
  - '3.3'
16
- name: Ruby ${{ matrix.ruby }} RSpec
63
+ - '3.4'
64
+ name: RSpec (Ruby ${{ matrix.ruby }})
17
65
  steps:
18
- - uses: actions/checkout@v3
66
+ - uses: actions/checkout@v4
19
67
  - uses: ruby/setup-ruby@v1
20
68
  with:
21
69
  bundler-cache: true
22
70
  ruby-version: ${{ matrix.ruby }}
23
- - run: bundle exec rspec
71
+ - run: bundle exec rspec --exclude-pattern "spec/**/*rails*,spec/**/*sinatra*"
24
72
 
25
73
  rubocop:
26
74
  runs-on: ubuntu-latest
27
75
  name: RuboCop
28
76
  steps:
29
- - uses: actions/checkout@v3
77
+ - uses: actions/checkout@v4
30
78
  - uses: ruby/setup-ruby@v1
31
79
  with:
32
80
  bundler-cache: true
33
81
  ruby-version: '3.2'
34
82
  - run: bundle exec rubocop
83
+
84
+ sinatra:
85
+ runs-on: ubuntu-latest
86
+ strategy:
87
+ fail-fast: false
88
+ matrix:
89
+ ruby:
90
+ - '2.7'
91
+ - '3.0'
92
+ - '3.1'
93
+ - '3.2'
94
+ - '3.3'
95
+ - '3.4'
96
+ sinatra:
97
+ - '3.x'
98
+ - '4.0'
99
+ - '4.1'
100
+ env:
101
+ BUNDLE_GEMFILE: gemfiles/sinatra_${{ matrix.sinatra }}.gemfile
102
+ name: Rails (Ruby ${{ matrix.ruby }} / Sinatra ${{ matrix.sinatra }})
103
+ steps:
104
+ - uses: actions/checkout@v4
105
+ - uses: ruby/setup-ruby@v1
106
+ with:
107
+ bundler-cache: true
108
+ ruby-version: ${{ matrix.ruby }}
109
+ - run: bundle exec rspec --pattern "spec/**/*sinatra*"
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
+ /gemfiles/*.gemfile.lock
7
8
  /pkg/
8
9
  /spec/examples.txt
9
10
  /spec/reports/
data/.rubocop.yml CHANGED
@@ -2,6 +2,7 @@ AllCops:
2
2
  NewCops: enable
3
3
  Exclude:
4
4
  - examples/**/*
5
+ - gemfiles/*
5
6
  - vendor/**/*
6
7
  SuggestExtensions: false
7
8
  TargetRubyVersion: 2.5
data/Appraisals ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'rails_7.0' do
4
+ gem 'concurrent-ruby', '< 1.3.5'
5
+ gem 'rails', '~> 7.0.0'
6
+ end
7
+
8
+ appraise 'rails_7.1' do
9
+ gem 'rails', '~> 7.1.0'
10
+ end
11
+
12
+ appraise 'rails_7.2' do
13
+ gem 'rails', '~> 7.2.0'
14
+ end
15
+
16
+ appraise 'rails_8.0' do
17
+ gem 'rails', '~> 8.0.0'
18
+ end
19
+
20
+ appraise 'sinatra_3.x' do
21
+ gem 'sinatra', '~> 3.0'
22
+ end
23
+
24
+ appraise 'sinatra_4.0' do
25
+ gem 'sinatra', '~> 4.0.0'
26
+ end
27
+
28
+ appraise 'sinatra_4.1' do
29
+ gem 'sinatra', '~> 4.1.0'
30
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Version 0.7.0 - 2025-02-03
2
+
3
+ - Add support for Rails 8 and add test infrastructure to ensure future compatibility with Rails 7.0, 7.1, and 8.0. <https://github.com/benpickles/parklife/pull/115>, <https://github.com/benpickles/parklife/pull/117>, <https://github.com/benpickles/parklife/pull/121>
4
+ - Improve out-of-the-box compatibility with Rails by reading `default_url_options`, `relative_url_root`, and `force_ssl` settings on boot and applying them to Parklife's `config.base` (`force_ssl` has been set to `true` in `production.rb` since Rails 7.1). <https://github.com/benpickles/parklife/pull/118>
5
+ - Improve out-of-the-box compatibility with Sinatra 4.1 which has host authorisation middleware enabled by default in development mode and would otherwise respond to Parklife requests with a 403 status. Additionally the generated Sinatra production build script now sets the environment variable `APP_ENV=production` to enable production mode. <https://github.com/benpickles/parklife/pull/123>, <https://github.com/benpickles/parklife/pull/122>
6
+ - When discovering HTML links ignore `<a>` elements without an `href`. <https://github.com/benpickles/parklife/pull/107>
7
+
1
8
  ## Version 0.6.1 - 2024-08-23
2
9
 
3
10
  - Don't error when the public directory doesn't exist <https://github.com/benpickles/parklife/pull/105>
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in parklife.gemspec
8
8
  gemspec
9
9
 
10
+ gem 'appraisal'
10
11
  gem 'bundler'
11
- gem 'rails'
12
12
  gem 'rake'
13
13
  gem 'rspec'
14
14
  gem 'rubocop'
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "concurrent-ruby", "< 1.3.5"
11
+ gem "rails", "~> 7.0.0"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "rails", "~> 7.1.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "rails", "~> 7.2.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "rails", "~> 8.0.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "sinatra", "~> 3.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "sinatra", "~> 4.0.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rubocop"
10
+ gem "sinatra", "~> 4.1.0"
11
+
12
+ gemspec path: "../"
data/lib/parklife/cli.rb CHANGED
@@ -26,6 +26,7 @@ module Parklife
26
26
  ['nested_index', application.config.nested_index],
27
27
  ['on_404', application.config.on_404.inspect],
28
28
  ['parklife/rails', defined?(::Parklife::Railtie) ? 'enabled' : '-'],
29
+ ['parklife/sinatra', defined?(::Parklife::Sinatra) ? 'enabled' : '-'],
29
30
  ['reporter', reporter == $stdout ? '$stdout' : reporter],
30
31
  ])
31
32
  end
@@ -8,7 +8,7 @@ module Parklife
8
8
  # default_url_options and relative_url_root to match.
9
9
  def base=(value)
10
10
  super.tap { |uri|
11
- Rails.application.default_url_options = {
11
+ app.default_url_options = {
12
12
  host: Utils.host_with_port(uri),
13
13
  protocol: uri.scheme,
14
14
  }
@@ -19,6 +19,12 @@ module Parklife
19
19
  end
20
20
  end
21
21
 
22
+ module RailsRouteSetRefinements
23
+ def default_url_options
24
+ Rails.application.default_url_options
25
+ end
26
+ end
27
+
22
28
  class Railtie < Rails::Railtie
23
29
  initializer 'parklife.disable_host_authorization' do |app|
24
30
  # The offending middleware is included in Rails (6+) development mode and
@@ -37,16 +43,27 @@ module Parklife
37
43
  if defined?(ActionDispatch::HostAuthorization)
38
44
  app.middleware.delete(ActionDispatch::HostAuthorization)
39
45
  end
40
- end
41
46
 
42
- config.after_initialize do
43
- Parklife.application.config.app = Rails.application
47
+ Parklife.application.config.app = app
44
48
 
45
49
  # Allow use of the Rails application's route helpers when defining
46
50
  # Parklife routes in the block form.
47
- Parklife.application.routes.singleton_class.include(Rails.application.routes.url_helpers)
51
+ Parklife.application.routes.singleton_class.include(RailsRouteSetRefinements)
52
+ Parklife.application.routes.singleton_class.include(app.routes.url_helpers)
48
53
 
49
54
  Parklife.application.config.extend(RailsConfigRefinements)
50
55
  end
56
+
57
+ config.after_initialize do |app|
58
+ # Read the Rails app's URL config and apply it to Parklife's so that the
59
+ # Rails config can be used as the single source of truth.
60
+ host, protocol = app.default_url_options.values_at(:host, :protocol)
61
+ protocol = 'https' if app.config.force_ssl
62
+ path = ActionController::Base.relative_url_root
63
+
64
+ Parklife.application.config.base.scheme = protocol if protocol
65
+ Parklife.application.config.base.host = host if host
66
+ Parklife.application.config.base.path = path if path
67
+ end
51
68
  end
52
69
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sinatra/base'
4
+
5
+ module Parklife
6
+ module Sinatra
7
+ def self.registered(app)
8
+ # Disable Rack::Protection::HostAuthorization middleware so that fetching
9
+ # a page with Parklife works in development. It's safe to do here because
10
+ # it will only be executed when this file is explicitly required in a
11
+ # Parkfile and not in general when the app is running in a web server.
12
+ if app.settings.respond_to?(:host_authorization)
13
+ app.set(:host_authorization, permitted_hosts: [])
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Sinatra.register Parklife::Sinatra
@@ -2,7 +2,11 @@
2
2
  require 'parklife/rails'
3
3
  require_relative 'config/environment'
4
4
  <% else -%>
5
- # Assuming your Rack app lives in ./app.rb:
5
+ <% if options[:sinatra] -%>
6
+ require 'parklife/sinatra'
7
+
8
+ <% end -%>
9
+ # Assuming your <%= options[:sinatra] ? 'Sinatra' : 'Rack' %> app lives in ./app.rb:
6
10
  require_relative 'app'
7
11
  <% end -%>
8
12
 
@@ -11,8 +15,9 @@ Parklife.application.configure do |config|
11
15
  # For a Sinatra "classic" app:
12
16
  config.app = Sinatra::Application
13
17
  #
14
- # Or for Sinatra modular style:
18
+ # For a modular-style Sinatra app the Parklife extension must be explicitly registered:
15
19
  # config.app = App
20
+ # App.register Parklife::Sinatra
16
21
 
17
22
  <% elsif !options[:rails] -%>
18
23
  config.app = App
@@ -15,11 +15,11 @@ jobs:
15
15
  build:
16
16
  runs-on: ubuntu-latest
17
17
  steps:
18
- - uses: actions/checkout@v3
18
+ - uses: actions/checkout@v4
19
19
  - uses: ruby/setup-ruby@v1
20
20
  with:
21
21
  bundler-cache: true
22
- - uses: actions/configure-pages@v3
22
+ - uses: actions/configure-pages@v5
23
23
  id: pages
24
24
 
25
25
  # Build with Parklife and use its GitHub Pages URL (either its custom
@@ -27,7 +27,7 @@ jobs:
27
27
  - run: bin/static-build --base "${{ steps.pages.outputs.base_url }}"
28
28
 
29
29
  - name: Upload artifact
30
- uses: actions/upload-pages-artifact@v1
30
+ uses: actions/upload-pages-artifact@v3
31
31
  if: github.ref == 'refs/heads/main' # Only upload on main branch.
32
32
  with:
33
33
  path: build/
@@ -45,4 +45,4 @@ jobs:
45
45
  steps:
46
46
  - name: Deploy to GitHub Pages
47
47
  id: deployment
48
- uses: actions/deploy-pages@v1
48
+ uses: actions/deploy-pages@v4
@@ -3,8 +3,7 @@
3
3
  set -eu
4
4
 
5
5
  <% if options[:rails] -%>
6
- # You probably need to run the app in production mode to ensure the correct
7
- # asset URLs are referenced.
6
+ # Run the app in production mode to ensure correct asset URLs are generated etc.
8
7
  export RAILS_ENV=production
9
8
  export SECRET_KEY_BASE=dummy
10
9
 
@@ -17,6 +16,10 @@ export SECRET_KEY_BASE=dummy
17
16
  # missing assets in production.
18
17
  bundle exec rails assets:precompile
19
18
 
19
+ <% elsif options[:sinatra] -%>
20
+ # Run the app in production mode.
21
+ export APP_ENV=production
22
+
20
23
  <% end -%>
21
24
  # Build with Parklife - and forward arguments sent to this script.
22
25
  bundle exec parklife build "$@"
@@ -39,7 +39,7 @@ module Parklife
39
39
 
40
40
  def scan_for_links(html)
41
41
  doc = Nokogiri::HTML.parse(html)
42
- doc.css('a').each do |a|
42
+ doc.css('a[href]').each do |a|
43
43
  uri = URI.parse(a[:href])
44
44
 
45
45
  # Don't visit a URL that belongs to a different domain - for now this is
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parklife
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parklife
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Pickles
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
10
+ date: 2025-02-03 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nokogiri
@@ -52,7 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description:
56
54
  email:
57
55
  - spideryoung@gmail.com
58
56
  executables:
@@ -65,6 +63,7 @@ files:
65
63
  - ".gitignore"
66
64
  - ".rspec"
67
65
  - ".rubocop.yml"
66
+ - Appraisals
68
67
  - CHANGELOG.md
69
68
  - CODE_OF_CONDUCT.md
70
69
  - Gemfile
@@ -74,6 +73,13 @@ files:
74
73
  - bin/console
75
74
  - bin/setup
76
75
  - exe/parklife
76
+ - gemfiles/rails_7.0.gemfile
77
+ - gemfiles/rails_7.1.gemfile
78
+ - gemfiles/rails_7.2.gemfile
79
+ - gemfiles/rails_8.0.gemfile
80
+ - gemfiles/sinatra_3.x.gemfile
81
+ - gemfiles/sinatra_4.0.gemfile
82
+ - gemfiles/sinatra_4.1.gemfile
77
83
  - lib/parklife.rb
78
84
  - lib/parklife/application.rb
79
85
  - lib/parklife/browser.rb
@@ -84,6 +90,7 @@ files:
84
90
  - lib/parklife/rails.rb
85
91
  - lib/parklife/route.rb
86
92
  - lib/parklife/route_set.rb
93
+ - lib/parklife/sinatra.rb
87
94
  - lib/parklife/templates/Parkfile.erb
88
95
  - lib/parklife/templates/github_pages.yml
89
96
  - lib/parklife/templates/static_build.erb
@@ -98,7 +105,6 @@ metadata:
98
105
  homepage_uri: https://parklife.dev
99
106
  rubygems_mfa_required: 'true'
100
107
  source_code_uri: https://github.com/benpickles/parklife
101
- post_install_message:
102
108
  rdoc_options: []
103
109
  require_paths:
104
110
  - lib
@@ -113,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
119
  - !ruby/object:Gem::Version
114
120
  version: '0'
115
121
  requirements: []
116
- rubygems_version: 3.5.17
117
- signing_key:
122
+ rubygems_version: 3.6.2
118
123
  specification_version: 4
119
124
  summary: Convert a Rack app into a static HTML site.
120
125
  test_files: []