heroku_error_pages 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcbc58c8c09a48ecfc080524888410620dd4c0e56e35cb37efb29398e814d7d4
4
- data.tar.gz: dc633286704481c7a6c1b111f0c2b0231c6528b35ed2f32574ecedb6fdc096a1
3
+ metadata.gz: 8d0d64ddb46d74b54d79d049e8f2dd750716764bac20ccae63f2f862cff2bca3
4
+ data.tar.gz: 8e38951b360be3e1410c18510688b94e68d621d6b3271b2feb868ffa5acdbc23
5
5
  SHA512:
6
- metadata.gz: e718a4161a2ebc3d01596981fe636abc1fa7d1a49124593fac8a1d3fe1460eb70fde2a764e4f5c5a6dcfca2d754fa80b2609c558fbc1fea3fe72809619afa4ea
7
- data.tar.gz: bd8a9ac179af8087514b18fee7fced133a79c4eed86afbfcb16669cce4b6c53266452f15b42bcf7f9ba30e37c78adda387bb313cf0861be78bb4dc7b26387574
6
+ metadata.gz: a2acff799e9ee551dabe2eebca7487525e93536529ca800c135c4b3e228a366db0f07cb7567f29f7e72b86fd77e193374edef8db5529c5d669b718be2fbd730a
7
+ data.tar.gz: a687320e52b1f8fed12b233f16afbfefbfdd1365e0d7bba79d59441ca538ec91057da45e39b54de8626e1cc7c79e4f43d67db777028a9c418aba852e375a9dd1
data/README.md CHANGED
@@ -32,12 +32,11 @@ HerokuErrorPages.configure do |config|
32
32
 
33
33
  # at least one page must be configured
34
34
  config.configure_error_page(
35
- s3_path: 'application_error.html', # where the html will be stored in your S3 bucket
36
35
  template: 'errors/show', # the Rails template to render
37
36
  assigns: { # optional, any variables to assign to the template
38
37
  status: :internal_server_error
39
38
  },
40
- controller: ErrorsController # optional, defaults to ActionController::Base
39
+ layout: 'public' # optional, defaults to 'application'
41
40
  )
42
41
 
43
42
  config.configure_maintenance_page(
@@ -11,21 +11,19 @@ module HerokuErrorPages
11
11
  @aws_region = "us-east-1"
12
12
  end
13
13
 
14
- def configure_error_page(s3_path:, template:, assigns: nil, controller: nil)
14
+ def configure_error_page(template:, assigns: nil, layout: nil)
15
15
  @error_page = PageConfig.new(
16
- s3_path: s3_path,
17
16
  template: template,
18
17
  assigns: assigns,
19
- controller: controller
18
+ layout: layout
20
19
  )
21
20
  end
22
21
 
23
- def config_maintenance_page(s3_path:, template:, assigns: nil, controller: nil)
22
+ def configure_maintenance_page(template:, assigns: nil, layout: nil)
24
23
  @maintenance_page = PageConfig.new(
25
- s3_path: s3_path,
26
24
  template: template,
27
25
  assigns: assigns,
28
- controller: controller
26
+ layout: layout
29
27
  )
30
28
  end
31
29
  end
@@ -2,13 +2,12 @@
2
2
 
3
3
  module HerokuErrorPages
4
4
  class PageConfig
5
- attr_accessor :s3_path, :template, :assigns, :controller
5
+ attr_accessor :template, :assigns, :layout
6
6
 
7
- def initialize(s3_path:, template:, assigns:, controller:)
8
- @s3_path = s3_path
7
+ def initialize(template:, assigns:, layout:)
9
8
  @template = template
10
9
  @assigns = assigns || {}
11
- @controller = controller || ActionController::Base
10
+ @layout = layout || "application"
12
11
  end
13
12
  end
14
13
  end
@@ -4,14 +4,14 @@ module HerokuErrorPages
4
4
  class Renderer
5
5
  class << self
6
6
  def render_html(page_config)
7
- new(page_config.template, page_config.assigns, page_config.controller).html
7
+ new(page_config.template, page_config.assigns, page_config.layout).html
8
8
  end
9
9
  end
10
10
 
11
- def initialize(template, assigns, controller)
11
+ def initialize(template, assigns, layout)
12
12
  @template = template
13
13
  @assigns = assigns
14
- @controller = controller
14
+ @layout = layout
15
15
  end
16
16
 
17
17
  def html
@@ -20,14 +20,15 @@ module HerokuErrorPages
20
20
 
21
21
  private
22
22
 
23
- attr_reader :template, :assigns, :controller
23
+ attr_reader :template, :assigns, :layout
24
24
 
25
25
  def generate_html
26
- controller = Class.new(controller) do
26
+ controller = Class.new(ActionController::Base) do
27
27
  self.asset_host = nil
28
+ self.relative_url_root = "/#{HerokuErrorPages::S3_PREFIX}"
28
29
  end
29
30
 
30
- controller.render(template: template, assigns: assigns)
31
+ controller.render(template: template, assigns: assigns, layout: layout)
31
32
  end
32
33
  end
33
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HerokuErrorPages
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -6,8 +6,13 @@ require_relative "heroku_error_pages/page_config"
6
6
  require_relative "heroku_error_pages/railtie"
7
7
  require_relative "heroku_error_pages/renderer"
8
8
  require_relative "heroku_error_pages/public_asset"
9
+ require "aws-sdk-s3"
9
10
 
10
11
  module HerokuErrorPages
12
+ S3_PREFIX = "heroku_error_pages"
13
+ ERROR_PAGE = "error_page.html"
14
+ MAINTENANCE_PAGE = "maintenance_page.html"
15
+
11
16
  class << self
12
17
  def config
13
18
  @config ||= Config.new
@@ -28,19 +33,22 @@ module HerokuErrorPages
28
33
  region: config.aws_region
29
34
  )
30
35
 
31
- deploy_page(config.error_page, s3_client)
32
- deploy_page(config.maintenance_page, s3_client)
36
+ deploy_page(config.error_page, s3_client, "error_page.html")
37
+ deploy_page(config.maintenance_page, s3_client, "maintenance_page.html")
33
38
  deploy_public_assets(s3_client)
34
39
  end
35
40
 
36
41
  private
37
42
 
38
- def deploy_page(page_config, s3_client)
43
+ def deploy_page(page_config, s3_client, page_name)
39
44
  return if page_config.nil?
40
45
 
41
- s3_object = Aws::S3::Object.new(config.s3_bucket_name, page_config.s3_path, client: s3_client)
46
+ s3_object = Aws::S3::Object.new(
47
+ config.s3_bucket_name,
48
+ "#{S3_PREFIX}/#{page_name}",
49
+ client: s3_client
50
+ )
42
51
  s3_object.put(
43
- acl: "public-read",
44
52
  body: Renderer.render_html(page_config),
45
53
  content_type: "text/html"
46
54
  )
@@ -48,13 +56,16 @@ module HerokuErrorPages
48
56
 
49
57
  def deploy_public_assets(s3_client)
50
58
  PublicAsset.all.each do |public_asset|
51
- s3_absolute_path = "#{config.s3_bucket_name}/#{public_asset.relative_path}"
59
+ s3_absolute_path = "#{config.s3_bucket_name}/#{S3_PREFIX}/#{public_asset.relative_path}"
52
60
  Rails.logger.info "Uploading #{public_asset.absolute_path} to #{s3_absolute_path}"
53
61
 
54
- s3_object = Aws::S3::Object.new(config.s3_bucket_name, public_asset.relative_path, client: s3_client)
62
+ s3_object = Aws::S3::Object.new(
63
+ config.s3_bucket_name,
64
+ "#{S3_PREFIX}/#{public_asset.relative_path}",
65
+ client: s3_client
66
+ )
55
67
  s3_object.upload_file(
56
68
  public_asset.absolute_path,
57
- acl: "public-read",
58
69
  content_type: public_asset.mime_type
59
70
  )
60
71
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_error_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaco Pretorius
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-18 00:00:00.000000000 Z
10
+ date: 2025-04-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: aws-sdk-s3