parklife 0.5.1 → 0.6.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: 0a0e894c4cba14f5f3d7dc614df86e5430dded896ddf5466048bd2b7eb224791
4
- data.tar.gz: 684afeeb534d59bb1139e5df34c3a5ff93a4c9e2c491b69b2a2a66feeba54c3c
3
+ metadata.gz: 6a1770a5f09524a3c16e3becb527d6d6fc0fdb723095b3365ee583a0a91722a4
4
+ data.tar.gz: 0be599051686b0dab89aba57dfe72813de074c694c31de876f66b9c8aeb61223
5
5
  SHA512:
6
- metadata.gz: 8e0edd657e0b2d82e17b2eb143748cd22612b72b99851ef1ad331f9641f310e09859f537dc95798e255a5868cabed63599089fe19003991d8cce86c36dba8978
7
- data.tar.gz: d82d26729d3206e07ed39b84215d9243c789066f3be32a64a9173356d70a8e588ffc60672832bb77038821249621dd2de7745cf6448f118916fbbffe3d6ee64e
6
+ metadata.gz: 4c473fd98d0162b43ff8b09399e05f827fd478b30bf33d563a21f463dcc873366c56e72ae91c3c236da5823f44154dc6f59e2ddb49f4526b1691e636fda7bcf9
7
+ data.tar.gz: 466f130fb18b8fea3deb6ff126c767009b2e9341d04deb5c0f8ee8c4705e3987d734094976a33886dd0f152cfd4ba2c1ac4c4941859ef11e703a63195b5e8bc4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## Version 0.6.0 - 2023-03-26
2
+
3
+ - Allow assigning a URI object to config.base <https://github.com/benpickles/parklife/pull/98>
4
+
5
+ - Add a `parklife config` command to output the full Parklife config <https://github.com/benpickles/parklife/pull/97>
6
+
7
+ - Improved Rails integration <https://github.com/benpickles/parklife/pull/96>
8
+
9
+ Parklife now integrates with Rails via Railties and can therefore hook into the app's configuration before it's initialised. This allows Parklife to remove the host authorisation middleware that's present in development and otherwise causes Parklife requests to receive a 403 response.
10
+
11
+ **Upgrading**: For an existing Parklife+Rails integration move requiring `parklife/rails` above requiring `config/environment` in the Parkfile.
12
+
13
+ - Prevent `Encoding::UndefinedConversionError` error when writing a binary response <https://github.com/benpickles/parklife/pull/94>
14
+
1
15
  ## Version 0.5.1 - 2023-03-22
2
16
 
3
17
  - Ensure the generated static-build script is executable. <https://github.com/benpickles/parklife/pull/89>
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
8
8
  gemspec
9
9
 
10
10
  gem 'bundler'
11
+ gem 'rails'
11
12
  gem 'rake'
12
13
  gem 'rspec'
13
14
  gem 'rubocop'
data/README.md CHANGED
@@ -23,14 +23,14 @@ $ bundle exec parklife init
23
23
  Parklife is configured with a file called `Parkfile` in the root of your project, here's an example `Parkfile` for an imaginary Rails app:
24
24
 
25
25
  ```ruby
26
+ # Load Parklife's Rails-specific integration which, among other things, allows
27
+ # you to use URL helpers within the `routes` block below.
28
+ require 'parklife/rails'
29
+
26
30
  # Load the Rails application, this gives you full access to the application's
27
31
  # environment from this file - using models for example.
28
32
  require_relative 'config/environment'
29
33
 
30
- # Load Parklife and some Rails-specific settings allowing you to use URL
31
- # helpers within the `routes` block below.
32
- require 'parklife/rails'
33
-
34
34
  Parkfile.application.routes do
35
35
  # Start from the homepage and crawl all links.
36
36
  root crawl: true
@@ -76,7 +76,7 @@ build/feed.atom
76
76
  build/sitemap.xml
77
77
  ```
78
78
 
79
- Parklife doesn't know about assets (images, CSS, etc) so you likely also need to generate those and copy them to the build directory, see the [Rails example's full build script](examples/rails/parklife-build) for how you might do this.
79
+ Parklife doesn't know about assets (images, CSS, etc) so you likely also need to generate those and copy them to the build directory, see the [Rails example's full build script](examples/rails/bin/static-build) for how you might do this.
80
80
 
81
81
  ## More examples
82
82
 
data/lib/parklife/cli.rb CHANGED
@@ -15,6 +15,21 @@ module Parklife
15
15
  application.build
16
16
  end
17
17
 
18
+ desc 'config', 'Output the full Parklife config'
19
+ def config
20
+ reporter = application.config.reporter
21
+
22
+ shell.print_table([
23
+ ['app', application.config.app.inspect],
24
+ ['base', application.config.base.to_s],
25
+ ['build_dir', application.config.build_dir],
26
+ ['nested_index', application.config.nested_index],
27
+ ['on_404', application.config.on_404.inspect],
28
+ ['parklife/rails', defined?(::Parklife::Railtie) ? 'enabled' : '-'],
29
+ ['reporter', reporter == $stdout ? '$stdout' : reporter],
30
+ ])
31
+ end
32
+
18
33
  desc 'get PATH', 'Fetch PATH from the app and output its contents'
19
34
  def get(path)
20
35
  puts application.crawler.get(path).body
@@ -20,7 +20,7 @@ module Parklife
20
20
  end
21
21
 
22
22
  def base=(value)
23
- uri = URI.parse(value || '')
23
+ uri = URI === value ? value : URI.parse(value || '')
24
24
  uri.host ||= DEFAULT_HOST
25
25
  uri.scheme ||= DEFAULT_SCHEME
26
26
  @base = uri
@@ -16,10 +16,4 @@ module Parklife
16
16
  super %Q(Cannot load Parkfile "#{path}")
17
17
  end
18
18
  end
19
-
20
- class RailsNotDefinedError < Error
21
- def initialize(msg = 'Expected Rails to be defined, require config/environment before parklife')
22
- super
23
- end
24
- end
25
19
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- raise Parklife::RailsNotDefinedError unless defined?(Rails)
3
+ require 'rails'
4
4
 
5
5
  module Parklife
6
6
  module RailsConfigRefinements
@@ -18,12 +18,35 @@ module Parklife
18
18
  }
19
19
  end
20
20
  end
21
- end
22
21
 
23
- Parklife.application.config.app = Rails.application
22
+ class Railtie < Rails::Railtie
23
+ initializer 'parklife.disable_host_authorization' do |app|
24
+ # The offending middleware is included in Rails (6+) development mode and
25
+ # rejects a request with a 403 response if its host isn't present in the
26
+ # allowlist (a security feature). This prevents Parklife from working in
27
+ # a Rails app out of the box unless you manually add the expected
28
+ # Parklife base to the hosts allowlist or set it to nil to disable it -
29
+ # both of which aren't great because they disable the security feature
30
+ # whenever the development server is booted.
31
+ #
32
+ # https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
33
+ #
34
+ # However it's safe to remove the middleware at this point because it
35
+ # won't be executed in the normal Rails development flow, only via a
36
+ # Parkfile when parklife/rails is required.
37
+ if defined?(ActionDispatch::HostAuthorization)
38
+ app.middleware.delete(ActionDispatch::HostAuthorization)
39
+ end
40
+ end
41
+
42
+ config.after_initialize do
43
+ Parklife.application.config.app = Rails.application
24
44
 
25
- # Allow use of the Rails application's route helpers when defining Parklife
26
- # routes in the block form.
27
- Parklife.application.routes.singleton_class.include(Rails.application.routes.url_helpers)
45
+ # Allow use of the Rails application's route helpers when defining
46
+ # Parklife routes in the block form.
47
+ Parklife.application.routes.singleton_class.include(Rails.application.routes.url_helpers)
28
48
 
29
- Parklife.application.config.extend(Parklife::RailsConfigRefinements)
49
+ Parklife.application.config.extend(RailsConfigRefinements)
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  <% if options[:rails] -%>
2
- require_relative 'config/environment'
3
2
  require 'parklife/rails'
3
+ require_relative 'config/environment'
4
4
  <% else -%>
5
5
  # Assuming your Rack app lives in ./app.rb:
6
6
  require_relative 'app'
@@ -34,7 +34,7 @@ module Parklife
34
34
  build_path_for(path, index: config.nested_index)
35
35
  )
36
36
  FileUtils.mkdir_p(File.dirname(build_path))
37
- File.write(build_path, content)
37
+ File.write(build_path, content, mode: 'wb')
38
38
  end
39
39
 
40
40
  def scan_for_links(html)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parklife
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parklife
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Pickles
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-22 00:00:00.000000000 Z
11
+ date: 2023-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri