parklife 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +13 -2
  3. data/.rubocop.yml +30 -0
  4. data/CHANGELOG.md +25 -11
  5. data/Gemfile +7 -0
  6. data/README.md +9 -3
  7. data/Rakefile +2 -0
  8. data/bin/console +1 -0
  9. data/exe/parklife +2 -0
  10. data/lib/parklife/application.rb +9 -2
  11. data/lib/parklife/browser.rb +13 -5
  12. data/lib/parklife/cli.rb +46 -23
  13. data/lib/parklife/config.rb +2 -0
  14. data/lib/parklife/crawler.rb +11 -5
  15. data/lib/parklife/errors.rb +10 -10
  16. data/lib/parklife/rails.rb +23 -5
  17. data/lib/parklife/route.rb +2 -0
  18. data/lib/parklife/route_set.rb +2 -0
  19. data/lib/parklife/templates/Parkfile.erb +48 -0
  20. data/lib/parklife/templates/github_pages.yml +48 -0
  21. data/lib/parklife/templates/static_build.erb +28 -0
  22. data/lib/parklife/utils.rb +7 -0
  23. data/lib/parklife/version.rb +3 -1
  24. data/lib/parklife.rb +2 -0
  25. data/parklife.gemspec +6 -5
  26. metadata +8 -106
  27. data/examples/rack/.gitignore +0 -2
  28. data/examples/rack/Gemfile +0 -4
  29. data/examples/rack/Parkfile +0 -22
  30. data/examples/rails/.gitignore +0 -28
  31. data/examples/rails/Gemfile +0 -5
  32. data/examples/rails/Parkfile +0 -6
  33. data/examples/rails/Rakefile +0 -6
  34. data/examples/rails/app/assets/config/manifest.js +0 -2
  35. data/examples/rails/app/assets/images/.keep +0 -0
  36. data/examples/rails/app/assets/stylesheets/application.css +0 -15
  37. data/examples/rails/app/assets/stylesheets/global.css +0 -4
  38. data/examples/rails/app/controllers/application_controller.rb +0 -2
  39. data/examples/rails/app/controllers/posts_controller.rb +0 -9
  40. data/examples/rails/app/helpers/application_helper.rb +0 -2
  41. data/examples/rails/app/jobs/application_job.rb +0 -2
  42. data/examples/rails/app/models/application_record.rb +0 -3
  43. data/examples/rails/app/models/post.rb +0 -5
  44. data/examples/rails/app/views/layouts/application.html.erb +0 -14
  45. data/examples/rails/app/views/posts/index.html.erb +0 -7
  46. data/examples/rails/app/views/posts/show.html.erb +0 -3
  47. data/examples/rails/bin/bundle +0 -3
  48. data/examples/rails/bin/rails +0 -4
  49. data/examples/rails/bin/rake +0 -4
  50. data/examples/rails/bin/setup +0 -33
  51. data/examples/rails/bin/update +0 -28
  52. data/examples/rails/config/application.rb +0 -35
  53. data/examples/rails/config/boot.rb +0 -3
  54. data/examples/rails/config/database.yml +0 -25
  55. data/examples/rails/config/environment.rb +0 -5
  56. data/examples/rails/config/environments/development.rb +0 -53
  57. data/examples/rails/config/environments/production.rb +0 -79
  58. data/examples/rails/config/environments/test.rb +0 -36
  59. data/examples/rails/config/initializers/application_controller_renderer.rb +0 -8
  60. data/examples/rails/config/initializers/assets.rb +0 -12
  61. data/examples/rails/config/initializers/backtrace_silencers.rb +0 -7
  62. data/examples/rails/config/initializers/content_security_policy.rb +0 -25
  63. data/examples/rails/config/initializers/cookies_serializer.rb +0 -5
  64. data/examples/rails/config/initializers/filter_parameter_logging.rb +0 -4
  65. data/examples/rails/config/initializers/inflections.rb +0 -16
  66. data/examples/rails/config/initializers/mime_types.rb +0 -4
  67. data/examples/rails/config/initializers/wrap_parameters.rb +0 -14
  68. data/examples/rails/config/locales/en.yml +0 -33
  69. data/examples/rails/config/routes.rb +0 -5
  70. data/examples/rails/config.ru +0 -5
  71. data/examples/rails/data/1-hello-from-parklife.txt +0 -3
  72. data/examples/rails/data/2-hello-again.txt +0 -3
  73. data/examples/rails/data/3-magic-number.txt +0 -3
  74. data/examples/rails/db/migrate/20190507172823_create_posts.rb +0 -11
  75. data/examples/rails/db/schema.rb +0 -24
  76. data/examples/rails/db/seeds.rb +0 -10
  77. data/examples/rails/parklife-build +0 -25
  78. data/examples/rails/public/404.html +0 -67
  79. data/examples/rails/public/422.html +0 -67
  80. data/examples/rails/public/500.html +0 -66
  81. data/examples/rails/public/apple-touch-icon-precomposed.png +0 -0
  82. data/examples/rails/public/apple-touch-icon.png +0 -0
  83. data/examples/rails/public/favicon.ico +0 -0
  84. data/examples/rails/public/robots.txt +0 -1
  85. data/examples/sinatra/.gitignore +0 -2
  86. data/examples/sinatra/Gemfile +0 -4
  87. data/examples/sinatra/Parkfile +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97be6505f9a1ac2cf9b5b2f5864b6a73fbf110c173043b991a32b04892c8e865
4
- data.tar.gz: edd6ec37ae40bc0250bbb43ddaa9020a88d6e0884d0957dcb0888a0ab15cb9d0
3
+ metadata.gz: 6faa171e9fe5ae60f6285af884bbd5b19b96942dc5fefb106912c89137a2ff78
4
+ data.tar.gz: 8ffe432c9e9e5f374c61d4f3c3a6123532e699c9d4d9cfc5be87524d778e8008
5
5
  SHA512:
6
- metadata.gz: 80877ef06ba4a6cde8dea7ea58f1bea6ee02a7bba095a26f3644454ecdfa7b567895a00d6b55b53fb0b3d1c365b3d93ee3c0fdca137130a85e0f612e15aea782
7
- data.tar.gz: ce193737f065bcbb63d0350c5e01001c2b83a56e313d8fc2e3994ce653efd8937f7f83695589134d1f12f2cb2e0ce07df76601d102add3f911bfa313c608e7d2
6
+ metadata.gz: 48d14b37c34b2ed4c35fd73f7d53628962440ede84b0b64b65b33d1e02d3db787aa321ff45b637d4f9e3d80386c09ebaada5cd27fd78165beeaf09ce4c8a10ef
7
+ data.tar.gz: 6b30a2348133bd7ca05c19740f4cd73a8bf3de59b05f8a34d1c04d8008df79df3c2a8a42f5c66bf2376030c96413c5b99075e0ef17489685b229fdff6511436c
@@ -26,9 +26,9 @@ jobs:
26
26
  - uses: ruby/setup-ruby@v1
27
27
  with:
28
28
  bundler-cache: true
29
- ruby-version: '2.7'
29
+ ruby-version: '3.2'
30
30
  working-directory: examples/rails
31
- - run: ./parklife-build
31
+ - run: bin/static-build
32
32
  working-directory: examples/rails
33
33
  - run: test -f build/index.html
34
34
  working-directory: examples/rails
@@ -65,3 +65,14 @@ jobs:
65
65
  bundler-cache: true
66
66
  ruby-version: ${{ matrix.ruby }}
67
67
  - run: bundle exec rspec
68
+
69
+ rubocop:
70
+ runs-on: ubuntu-latest
71
+ name: RuboCop
72
+ steps:
73
+ - uses: actions/checkout@v3
74
+ - uses: ruby/setup-ruby@v1
75
+ with:
76
+ bundler-cache: true
77
+ ruby-version: '3.2'
78
+ - run: bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - examples/**/*
5
+ - vendor/**/*
6
+ SuggestExtensions: false
7
+ TargetRubyVersion: 2.5
8
+
9
+ Layout:
10
+ Enabled: false
11
+
12
+ Layout/EmptyLineAfterMagicComment:
13
+ Enabled: true
14
+
15
+ Lint/AmbiguousBlockAssociation:
16
+ Enabled: false
17
+
18
+ Metrics:
19
+ Enabled: false
20
+
21
+ Naming:
22
+ Enabled: false
23
+
24
+ Style:
25
+ Enabled: false
26
+
27
+ Style/FrozenStringLiteralComment:
28
+ Enabled: true
29
+ Exclude:
30
+ - spec/**/*
data/CHANGELOG.md CHANGED
@@ -1,20 +1,34 @@
1
+ ## Version 0.5.0 - 2023-03-12
2
+
3
+ - RuboCop. <https://github.com/benpickles/parklife/pull/87>
4
+ - Allow passing a --base to all `parklife` commands. <https://github.com/benpickles/parklife/pull/85>
5
+ - Configure Rails default_url_options and relative_url_root when setting Parklife base. <https://github.com/benpickles/parklife/pull/85>
6
+ - Add `parklife get PATH` command to fetch and output a path. <https://github.com/benpickles/parklife/pull/83>
7
+ - Add a `parklife init` command to create a starter Parkfile and friends. <https://github.com/benpickles/parklife/pull/82>
8
+ - Fix the HOST header for a non-standard port. <https://github.com/benpickles/parklife/pull/81>
9
+
10
+ ## Version 0.4.0 - 2023-03-01
11
+
12
+ - Add a `parklife --version` command. <https://github.com/benpickles/parklife/pull/80>
13
+ - No need to `require parklife` from the Parkfile. <https://github.com/benpickles/parklife/pull/79>
14
+
1
15
  ## Version 0.3.0 - 2023-02-26
2
16
 
3
- - Allow overriding `config.base` from the CLI build command with the `--base` option.
4
- - Support mounting the app at a path.
5
- - Remove Capybara and use Rack::Test directly.
6
- - Rename `config.rack_app` to `config.app`.
7
- - Don't save the response when `on_404=:skip`.
8
- - More accurate progress dots.
9
- - Default `build_dir` to `build`.
10
- - Fix build paths when `build_dir` isn't a full path.
11
- - Ignore pathless links - for instance #fragments and mailto.
17
+ - Allow overriding `config.base` from the CLI build command with the `--base` option. <https://github.com/benpickles/parklife/pull/78>
18
+ - Support mounting the app at a path. <https://github.com/benpickles/parklife/pull/78>
19
+ - Remove Capybara and use Rack::Test directly. <https://github.com/benpickles/parklife/pull/78>
20
+ - Rename `config.rack_app` to `config.app`. <https://github.com/benpickles/parklife/pull/78>
21
+ - Don't save the response when `on_404=:skip`. <https://github.com/benpickles/parklife/pull/77>
22
+ - More accurate progress dots. <https://github.com/benpickles/parklife/pull/75>
23
+ - Default `build_dir` to `build`. <https://github.com/benpickles/parklife/pull/73>
24
+ - Fix build paths when `build_dir` isn't a full path. <https://github.com/benpickles/parklife/pull/73>
25
+ - Ignore pathless links - for instance #fragments and mailto. <https://github.com/benpickles/parklife/pull/72>
12
26
 
13
27
  ## Version 0.2.0 - 2023-02-21
14
28
 
15
29
  - First official version hosted on [RubyGems.org](https://rubygems.org/gems/parklife).
16
- - Provide alternatives to blowing up if a 404 is encountered.
17
- - Add the ability to crawl a route by adding `crawl: true` to it.
30
+ - Provide alternatives to blowing up if a 404 is encountered. <https://github.com/benpickles/parklife/pull/70>
31
+ - Add the ability to crawl a route by adding `crawl: true` to it. <https://github.com/benpickles/parklife/pull/65>
18
32
 
19
33
  ## Version 0.1.0 - 2019-04-26
20
34
 
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in parklife.gemspec
6
8
  gemspec
9
+
10
+ gem 'bundler'
11
+ gem 'rake'
12
+ gem 'rspec'
13
+ gem 'rubocop'
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [Parklife](https://github.com/benpickles/parklife) is a Ruby library to render a Rack app (Rails/Sinatra/etc) to a static site so it can be served by [Netlify](https://www.netlify.com), [Now](https://zeit.co/now), [GitHub Pages](https://pages.github.com), S3, or another static server.
6
6
 
7
- ## Installation
7
+ ## Getting started
8
8
 
9
9
  Add Parklife to your application's Gemfile and run bundle install.
10
10
 
@@ -12,6 +12,12 @@ Add Parklife to your application's Gemfile and run bundle install.
12
12
  gem 'parklife'
13
13
  ```
14
14
 
15
+ Now generate a Parkfile configuration file and build script. Include some Rails- or Sinatra-specific settings by passing `--rails` or `--sinatra`, create a GitHub Actions workflow to generate your Parklife build and push it to GitHub Pages by passing `--github-pages`.
16
+
17
+ ```
18
+ $ bundle exec parklife init
19
+ ```
20
+
15
21
  ## How to use Parklife with Rails
16
22
 
17
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:
@@ -45,10 +51,10 @@ Listing the routes included in the above Parklife application with `parklife rou
45
51
 
46
52
  ```
47
53
  $ bundle exec parklife routes
48
- / crawl=true
54
+ / crawl=true
49
55
  /feed.atom
50
56
  /sitemap.xml
51
- /easter_egg crawl=true
57
+ /easter_egg crawl=true
52
58
  /404.html
53
59
  ```
54
60
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'parklife'
data/exe/parklife CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'parklife/cli'
3
5
  Parklife::CLI.start(ARGV)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'parklife/config'
3
5
  require 'parklife/crawler'
@@ -23,12 +25,17 @@ module Parklife
23
25
  crawler.start
24
26
  end
25
27
 
28
+ def configure
29
+ yield config
30
+ end
31
+
26
32
  def crawler
27
33
  @crawler ||= Crawler.new(config, @route_set)
28
34
  end
29
35
 
30
- def configure
31
- yield config
36
+ def load_Parkfile(path)
37
+ raise ParkfileLoadError.new(path) unless File.exist?(path)
38
+ load path
32
39
  end
33
40
 
34
41
  def routes(&block)
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parklife/utils'
1
4
  require 'rack/test'
2
5
 
3
6
  module Parklife
@@ -7,16 +10,21 @@ module Parklife
7
10
  def initialize(app, base)
8
11
  @app = app
9
12
  @base = base
10
- @env = {
11
- 'HTTP_HOST' => base.host,
12
- 'HTTPS' => base.scheme == 'https' ? 'on' : 'off',
13
- script_name: base.path.chomp('/'),
14
- }
15
13
  @session = Rack::Test::Session.new(app)
14
+ set_env
16
15
  end
17
16
 
18
17
  def get(path)
19
18
  session.get(path, nil, env)
20
19
  end
20
+
21
+ private
22
+ def set_env
23
+ @env = {
24
+ 'HTTP_HOST' => Utils.host_with_port(base),
25
+ 'HTTPS' => base.scheme == 'https' ? 'on' : 'off',
26
+ script_name: base.path.chomp('/'),
27
+ }
28
+ end
21
29
  end
22
30
  end
data/lib/parklife/cli.rb CHANGED
@@ -1,40 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parklife'
1
4
  require 'thor'
2
5
 
3
6
  module Parklife
4
7
  class CLI < Thor
5
- desc 'build', 'create a production build'
6
- option :base, desc: 'set config.base at build-time - overrides the Parkfile setting'
7
- def build
8
- # Parkfile config overrides.
9
- application.config.base = options[:base] if options[:base]
8
+ include Thor::Actions
9
+ source_root File.expand_path('templates', __dir__)
10
10
 
11
+ class_option :base, desc: 'Override config.base configured in the Parkfile'
12
+
13
+ desc 'build', 'Create a production build'
14
+ def build
11
15
  application.build
12
16
  end
13
17
 
14
- desc 'routes', 'list all defined routes'
18
+ desc 'get PATH', 'Fetch PATH from the app and output its contents'
19
+ def get(path)
20
+ puts application.crawler.get(path).body
21
+ end
22
+
23
+ desc 'init', 'Generate a starter Parkfile and friends'
24
+ option :github_pages, desc: 'Generate a GitHub Actions workflow to deploy to GitHub Pages', type: :boolean
25
+ option :rails, desc: 'Include some Rails-specific settings', type: :boolean
26
+ option :sinatra, desc: 'Include some Sinatra-specific settings', type: :boolean
27
+ def init
28
+ template('Parkfile.erb', 'Parkfile')
29
+ template('static_build.erb', 'bin/static-build', mode: 0755)
30
+ copy_file('github_pages.yml', '.github/workflows/parklife.yml') if options[:github_pages]
31
+ end
32
+
33
+ desc 'routes', 'List all defined routes'
15
34
  def routes
16
- application.routes.each do |route|
17
- print route.path
18
- print "\tcrawl=true" if route.crawl
19
- puts
20
- end
35
+ shell.print_table(
36
+ application.routes.map { |route|
37
+ [route.path, route.crawl ? "crawl=true" : nil]
38
+ }
39
+ )
40
+ end
41
+
42
+ map '--version' => :version
43
+ desc 'version', 'Output the current version of Parklife'
44
+ def version
45
+ puts Parklife::VERSION
21
46
  end
22
47
 
23
48
  private
24
49
  def application
25
- @application ||= begin
26
- # Reach inside the consuming app's directory to load Parklife and
27
- # apply its config. It's only at this point that the
28
- # Parklife::Application is defined.
29
- load discover_Parkfile(Dir.pwd)
30
-
31
- Parklife.application.config.reporter = $stdout
32
- Parklife.application
33
- end
34
- end
50
+ @application ||= Parklife.application.tap { |app|
51
+ # Default output to stdout (can be overridden in the Parkfile).
52
+ app.config.reporter = $stdout
53
+
54
+ # Reach inside the consuming app's directory to apply its Parklife
55
+ # config.
56
+ app.load_Parkfile(File.join(Dir.pwd, 'Parkfile'))
35
57
 
36
- def discover_Parkfile(dir)
37
- File.expand_path('Parkfile', dir)
58
+ # Runtime overrides.
59
+ app.config.base = options[:base] if options[:base]
60
+ }
38
61
  end
39
62
  end
40
63
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
  require 'uri'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parklife/browser'
2
4
  require 'parklife/route'
3
5
  require 'parklife/utils'
@@ -13,11 +15,15 @@ module Parklife
13
15
  @browser = Browser.new(config.app, config.base)
14
16
  end
15
17
 
18
+ def get(path)
19
+ browser.get(path)
20
+ end
21
+
16
22
  def start
17
23
  @routes = route_set.to_a
18
24
  @visited = Set.new
19
25
 
20
- while route = @routes.shift
26
+ while (route = @routes.shift)
21
27
  processed = process_route(route)
22
28
  config.reporter.print('.') if processed
23
29
  end
@@ -40,7 +46,7 @@ module Parklife
40
46
 
41
47
  return false if already_processed
42
48
 
43
- response = browser.get(route.path)
49
+ response = get(route.path)
44
50
 
45
51
  case response.status
46
52
  when 200
@@ -48,14 +54,14 @@ module Parklife
48
54
  when 404
49
55
  case config.on_404
50
56
  when :warn
51
- $stderr.puts HTTPError.new(path: route.path, status: 404).message
57
+ $stderr.puts HTTPError.new(404, route.path).message
52
58
  when :skip
53
59
  return false
54
60
  else
55
- raise HTTPError.new(path: route.path, status: 404)
61
+ raise HTTPError.new(404, route.path)
56
62
  end
57
63
  else
58
- raise HTTPError.new(path: route.path, status: response.status)
64
+ raise HTTPError.new(response.status, route.path)
59
65
  end
60
66
 
61
67
  Utils.save_page(route.path, response.body, config)
@@ -1,25 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parklife
2
4
  Error = Class.new(StandardError)
3
5
  BuildDirNotDefinedError = Class.new(Error)
4
6
  RackAppNotDefinedError = Class.new(Error)
5
7
 
6
8
  class HTTPError < Error
7
- def initialize(path:, status:)
8
- @path = path
9
- @status = status
9
+ def initialize(status, path)
10
+ super %Q(#{status} response from path "#{path}")
10
11
  end
12
+ end
11
13
 
12
- def message
13
- %Q(#{status} response from path "#{path}")
14
+ class ParkfileLoadError < Error
15
+ def initialize(path)
16
+ super %Q(Cannot load Parkfile "#{path}")
14
17
  end
15
-
16
- private
17
- attr_reader :path, :status
18
18
  end
19
19
 
20
20
  class RailsNotDefinedError < Error
21
- def message
22
- 'Expected Rails to be defined, require config/environment before parklife.'
21
+ def initialize(msg = 'Expected Rails to be defined, require config/environment before parklife')
22
+ super
23
23
  end
24
24
  end
25
25
  end
@@ -1,11 +1,29 @@
1
- require 'parklife/errors'
1
+ # frozen_string_literal: true
2
2
 
3
3
  raise Parklife::RailsNotDefinedError unless defined?(Rails)
4
4
 
5
- require 'parklife'
5
+ module Parklife
6
+ module RailsConfigRefinements
7
+ # When setting Parklife's base also configure the Rails app's
8
+ # default_url_options and relative_url_root to match.
9
+ def base=(value)
10
+ super.tap { |uri|
11
+ Rails.application.default_url_options = {
12
+ host: Utils.host_with_port(uri),
13
+ protocol: uri.scheme,
14
+ }
6
15
 
7
- # Allow use of the consuming Rails application's route helpers from within the
8
- # block when defining Parklife routes.
9
- Parklife::RouteSet.include(Rails.application.routes.url_helpers)
16
+ base_path = !uri.path.empty? && uri.path != '/' ? uri.path : nil
17
+ ActionController::Base.relative_url_root = base_path
18
+ }
19
+ end
20
+ end
21
+ end
10
22
 
11
23
  Parklife.application.config.app = Rails.application
24
+
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)
28
+
29
+ Parklife.application.config.extend(Parklife::RailsConfigRefinements)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parklife
2
4
  class Route
3
5
  attr_reader :crawl, :path
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
  require_relative 'route'
3
5
 
@@ -0,0 +1,48 @@
1
+ <% if options[:rails] -%>
2
+ require_relative 'config/environment'
3
+ require 'parklife/rails'
4
+ <% else -%>
5
+ # Assuming your Rack app lives in ./app.rb:
6
+ require_relative 'app'
7
+ <% end -%>
8
+
9
+ Parklife.application.configure do |config|
10
+ <% if options[:sinatra] -%>
11
+ # For a Sinatra "classic" app:
12
+ config.app = Sinatra::Application
13
+ #
14
+ # Or for Sinatra modular style:
15
+ # config.app = App
16
+
17
+ <% elsif !options[:rails] -%>
18
+ config.app = App
19
+
20
+ <% end -%>
21
+ <% if options[:github_pages] -%>
22
+ # Serve trailing slash-less URLs from GitHub Pages.
23
+ config.nested_index = false
24
+
25
+ <% end -%>
26
+ # See configuration options here:
27
+ # https://github.com/benpickles/parklife#configuration
28
+ end
29
+
30
+ Parklife.application.routes do
31
+ root crawl: true
32
+
33
+ <% if options[:rails] -%>
34
+ # Add further paths not discovered by crawling from the root - Parklife's
35
+ # Rails integration lets you use the app's route helpers:
36
+ #
37
+ # get hidden_pages_path, crawl: true
38
+ # get feed_path(format: :atom)
39
+ <% else -%>
40
+ # Add further paths not discovered by crawling from the root:
41
+ #
42
+ # get '/hidden/pages', crawl: true
43
+ # get '/feed.atom'
44
+ <% end -%>
45
+
46
+ # Services typically allow a custom 404 page.
47
+ # get '/404.html'
48
+ end
@@ -0,0 +1,48 @@
1
+ name: Parklife
2
+
3
+ on:
4
+ # Run on every push.
5
+ push:
6
+ # Allow manually triggering a build.
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+ pages: write
12
+ id-token: write
13
+
14
+ jobs:
15
+ build:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ bundler-cache: true
22
+ - uses: actions/configure-pages@v3
23
+ id: pages
24
+
25
+ # Build with Parklife and use its GitHub Pages URL (either its custom
26
+ # domain or username.github.io/repository).
27
+ - run: bin/static-build --base "${{ steps.pages.outputs.base_url }}"
28
+
29
+ - name: Upload artifact
30
+ uses: actions/upload-pages-artifact@v1
31
+ if: github.ref == 'refs/heads/main' # Only upload on main branch.
32
+ with:
33
+ path: build/
34
+
35
+ deploy:
36
+ environment:
37
+ name: github-pages
38
+ url: ${{ steps.deployment.outputs.page_url }}
39
+ runs-on: ubuntu-latest
40
+ needs: build
41
+ if: github.ref == 'refs/heads/main' # Only deploy on main branch.
42
+ concurrency:
43
+ group: deploy
44
+ cancel-in-progress: true
45
+ steps:
46
+ - name: Deploy to GitHub Pages
47
+ id: deployment
48
+ uses: actions/deploy-pages@v1
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -eu
4
+
5
+ <% if options[:rails] -%>
6
+ # You probably need to run the app in production mode to ensure the correct
7
+ # asset URLs are referenced.
8
+ export RAILS_ENV=production
9
+ export SECRET_KEY_BASE=dummy
10
+
11
+ # If your Rails app uses ActiveRecord then this is a good point to create and
12
+ # seed the database from db/seeds.rb.
13
+ # bundle exec rails db:setup
14
+
15
+ # Generate production-optimised assets with Sprockets and friends. This must be
16
+ # done before generating the Parklife build as Rails will blow up if it detects
17
+ # missing assets in production.
18
+ bundle exec rails assets:precompile
19
+
20
+ <% end -%>
21
+ # Build with Parklife - and forward arguments sent to this script.
22
+ bundle exec parklife build "$@"
23
+
24
+ # Copy all public resources to ./build.
25
+ cp -R public/* build
26
+
27
+ # List all files in the build (useful for debugging).
28
+ find build -type f | sort
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'nokogiri'
3
5
 
@@ -21,6 +23,11 @@ module Parklife
21
23
  end
22
24
  end
23
25
 
26
+ def host_with_port(uri)
27
+ default_port = uri.scheme == 'https' ? 443 : 80
28
+ uri.port == default_port ? uri.host : "#{uri.host}:#{uri.port}"
29
+ end
30
+
24
31
  def save_page(path, content, config)
25
32
  build_path = File.join(
26
33
  config.build_dir,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parklife
2
- VERSION = '0.3.0'
4
+ VERSION = '0.5.0'
3
5
  end
data/lib/parklife.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parklife/application'
2
4
  require 'parklife/version'
3
5