parklife 0.4.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 +22 -13
  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 +2 -0
  11. data/lib/parklife/browser.rb +13 -5
  12. data/lib/parklife/cli.rb +33 -12
  13. data/lib/parklife/config.rb +2 -0
  14. data/lib/parklife/crawler.rb +8 -2
  15. data/lib/parklife/errors.rb +6 -13
  16. data/lib/parklife/rails.rb +25 -3
  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 -21
  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 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32db274b9f5ec6ce7c56203a391c30c2d541bb8f319bc1b4130b22a2ed85bcf3
4
- data.tar.gz: dce6ff9a4911863acb4fdb19c134f822d729a4ced0df62799fc69853154e412f
3
+ metadata.gz: 6faa171e9fe5ae60f6285af884bbd5b19b96942dc5fefb106912c89137a2ff78
4
+ data.tar.gz: 8ffe432c9e9e5f374c61d4f3c3a6123532e699c9d4d9cfc5be87524d778e8008
5
5
  SHA512:
6
- metadata.gz: 434a2acf5bd27046330a6f4c954dcf7908e3672db1e9ce08e985b833f299273306b4535115093f8f18517210605da098e347bcd03a3481106e3c35958da5df5a
7
- data.tar.gz: 43249f1f24c7f932da0fd3d949b9d2590274ae7360d86a4f70f268c2a566dde1cf946aa6ba665a89c9bd5bbb5d5b6ee3ef714edbb7f4acbd34000045ac72dff5
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,25 +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
+
1
10
  ## Version 0.4.0 - 2023-03-01
2
11
 
3
- - Add a `parklife --version` command.
4
- - No need to `require parklife` from the Parkfile.
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>
5
14
 
6
15
  ## Version 0.3.0 - 2023-02-26
7
16
 
8
- - Allow overriding `config.base` from the CLI build command with the `--base` option.
9
- - Support mounting the app at a path.
10
- - Remove Capybara and use Rack::Test directly.
11
- - Rename `config.rack_app` to `config.app`.
12
- - Don't save the response when `on_404=:skip`.
13
- - More accurate progress dots.
14
- - Default `build_dir` to `build`.
15
- - Fix build paths when `build_dir` isn't a full path.
16
- - 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>
17
26
 
18
27
  ## Version 0.2.0 - 2023-02-21
19
28
 
20
29
  - First official version hosted on [RubyGems.org](https://rubygems.org/gems/parklife).
21
- - Provide alternatives to blowing up if a 404 is encountered.
22
- - 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>
23
32
 
24
33
  ## Version 0.1.0 - 2019-04-26
25
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'
@@ -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,28 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parklife'
2
4
  require 'thor'
3
5
 
4
6
  module Parklife
5
7
  class CLI < Thor
6
- desc 'build', 'create a production build'
7
- option :base, desc: 'set config.base at build-time - overrides the Parkfile setting'
8
- def build
9
- # Parkfile config overrides.
10
- application.config.base = options[:base] if options[:base]
8
+ include Thor::Actions
9
+ source_root File.expand_path('templates', __dir__)
10
+
11
+ class_option :base, desc: 'Override config.base configured in the Parkfile'
11
12
 
13
+ desc 'build', 'Create a production build'
14
+ def build
12
15
  application.build
13
16
  end
14
17
 
15
- 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'
16
34
  def routes
17
- application.routes.each do |route|
18
- print route.path
19
- print "\tcrawl=true" if route.crawl
20
- puts
21
- end
35
+ shell.print_table(
36
+ application.routes.map { |route|
37
+ [route.path, route.crawl ? "crawl=true" : nil]
38
+ }
39
+ )
22
40
  end
23
41
 
24
42
  map '--version' => :version
25
- desc 'version', 'output the current version of Parklife'
43
+ desc 'version', 'Output the current version of Parklife'
26
44
  def version
27
45
  puts Parklife::VERSION
28
46
  end
@@ -36,6 +54,9 @@ module Parklife
36
54
  # Reach inside the consuming app's directory to apply its Parklife
37
55
  # config.
38
56
  app.load_Parkfile(File.join(Dir.pwd, 'Parkfile'))
57
+
58
+ # Runtime overrides.
59
+ app.config.base = options[:base] if options[:base]
39
60
  }
40
61
  end
41
62
  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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parklife
2
4
  Error = Class.new(StandardError)
3
5
  BuildDirNotDefinedError = Class.new(Error)
@@ -5,28 +7,19 @@ module Parklife
5
7
 
6
8
  class HTTPError < Error
7
9
  def initialize(status, path)
8
- @status = status
9
- @path = path
10
- end
11
-
12
- def message
13
- %Q(#{@status} response from path "#{@path}")
10
+ super %Q(#{status} response from path "#{path}")
14
11
  end
15
12
  end
16
13
 
17
14
  class ParkfileLoadError < Error
18
15
  def initialize(path)
19
- @path = path
20
- end
21
-
22
- def message
23
- %Q(Cannot load Parkfile "#{@path}")
16
+ super %Q(Cannot load Parkfile "#{path}")
24
17
  end
25
18
  end
26
19
 
27
20
  class RailsNotDefinedError < Error
28
- def message
29
- '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
30
23
  end
31
24
  end
32
25
  end
@@ -1,7 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  raise Parklife::RailsNotDefinedError unless defined?(Rails)
2
4
 
3
- # Allow use of the consuming Rails application's route helpers from within the
4
- # block when defining Parklife routes.
5
- Parklife::RouteSet.include(Rails.application.routes.url_helpers)
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
+ }
15
+
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
6
22
 
7
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.4.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
 
data/parklife.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('../lib', __FILE__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'parklife/version'
@@ -16,13 +18,16 @@ Gem::Specification.new do |spec|
16
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
17
19
  spec.metadata = {
18
20
  'changelog_uri' => 'https://github.com/benpickles/parklife/blob/main/CHANGELOG.md',
21
+ 'rubygems_mfa_required' => 'true',
19
22
  'source_code_uri' => 'https://github.com/benpickles/parklife',
20
23
  }
21
24
 
25
+ spec.required_ruby_version = '>= 2.5.0'
26
+
22
27
  # Specify which files should be added to the gem when it is released.
23
28
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
29
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(examples|spec)/}) }
26
31
  end
27
32
  spec.bindir = 'exe'
28
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -31,8 +36,4 @@ Gem::Specification.new do |spec|
31
36
  spec.add_dependency 'nokogiri'
32
37
  spec.add_dependency 'rack-test'
33
38
  spec.add_dependency 'thor'
34
-
35
- spec.add_development_dependency 'bundler'
36
- spec.add_development_dependency 'rake'
37
- spec.add_development_dependency 'rspec'
38
39
  end