bard-staging_banner 0.2.0 → 0.3.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: 73e3bddbb020b1a98d81b0ea6a26e85274a5388ee254a97ca8f5c1fe37b47c6c
4
- data.tar.gz: 18acc6a44d8c3402b5e4f97c43b85646755d926c05e7a8112ee41e814de04f49
3
+ metadata.gz: 2575c1a7289bff8ecb865ed511d0a6f8bb3bdf0648aee3cf4f64b2b7d0840542
4
+ data.tar.gz: 1448e0ae9c1d8fcdbcbd5eb6cc65efb5210f15c36884b4f568675e156659047d
5
5
  SHA512:
6
- metadata.gz: 4bdcccc1f36341fe7c972380a618282a677a877e05ce981f52a14ff5aa950479bcbddd7ccf0fcd42a003009f73fd28aab27049d5ea33c1cedf95736a87e3fa15
7
- data.tar.gz: 0452244ba489e5b1ab794ed221e03b027683ea330bc0d16a3e7056da6f6bfe1b4e292d2f02d2816ebbc29b381636e0bfb94923d1e2ea2c23440008d3b91249e4
6
+ metadata.gz: 29ad9d47cdbf3ed0e72b05aa4042af9560ecd7a14ac00990c22ce96f7fbb598a9a81f36f46840702db364aba9f97156d68b828a3863627a6357618f38da5a8f5
7
+ data.tar.gz: 5347e2b4cc34326830526d030c2444ab3b17d8ff5493f35fd4d9b116aa5fa27d5d59290fdaf43870673b81421a4fbccb0831bc78fe059dab5a71d3e3ffe4b20f
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
@@ -15,5 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency "letter_opener_web"
18
20
  end
19
21
 
@@ -7,7 +7,7 @@ module Bard
7
7
 
8
8
  def call env
9
9
  @status, @headers, @body = @app.call(env)
10
- return [@status, @headers, @body] unless html?
10
+ return [@status, @headers, @body] unless html? && !letter_opener_web?(env)
11
11
 
12
12
  response = Rack::Response.new([], @status, @headers)
13
13
  @body.each do |fragment|
@@ -24,17 +24,28 @@ module Bard
24
24
  @headers["Content-Type"] =~ /html/
25
25
  end
26
26
 
27
+ def letter_opener_web? env
28
+ env["SCRIPT_NAME"].start_with?("/mails")
29
+ end
30
+
31
+ def mail_count
32
+ LetterOpenerWeb::Letter.search.length
33
+ end
34
+
27
35
  def inject response
28
- markup = <<~HTML
29
- <div id="staging-banner-top"></div>
30
- <div id="staging-banner-bottom"></div>
36
+ count = mail_count
37
+ mail_link = %(<a href="/mails">(#{mail_count})</a>) if count > 0
38
+ html = %w[upper-left upper-right bottom-left bottom-right].map do |corner|
39
+ %(<div class="staging-banner" id="#{corner}">Staging #{mail_link}</div>)
40
+ end.join("\n")
41
+
42
+ markup = html + <<~CSS
31
43
  <style>
32
- #staging-banner-top:before, #staging-banner-top:after, #staging-banner-bottom:before, #staging-banner-bottom:after {
44
+ .staging-banner {
33
45
  display: flex;
34
46
  justify-content: center;
35
47
  align-items: flex-end;
36
48
  padding: 30px 0 10px;
37
- content: "Staging";
38
49
  width: 200px;
39
50
  background: yellow;
40
51
  color: #0f0f0f;
@@ -48,31 +59,31 @@ module Bard
48
59
  transform-origin: 50% 50%;
49
60
  }
50
61
 
51
- #staging-banner-top:before {
62
+ #upper-left {
52
63
  top: 0;
53
64
  left: 0;
54
65
  transform: rotate(-45deg) translate(-52px, -60px);
55
66
  }
56
67
 
57
- #staging-banner-top:after {
68
+ #upper-right {
58
69
  top: 0;
59
70
  right: 0;
60
71
  transform: rotate(45deg) translate(52px, -60px);
61
72
  }
62
73
 
63
- #staging-banner-bottom:before {
74
+ #bottom-left {
64
75
  bottom: 0;
65
76
  left: 0;
66
77
  transform: rotate(225deg) translate(52px, -60px);
67
78
  }
68
79
 
69
- #staging-banner-bottom:after {
80
+ #bottom-right {
70
81
  bottom: 0;
71
82
  right: 0;
72
83
  transform: rotate(-225deg) translate(-52px, -60px);
73
84
  }
74
85
  </style>
75
- HTML
86
+ CSS
76
87
  response.gsub(%r{</body>}, "#{markup}</body>")
77
88
  end
78
89
  end
@@ -1,5 +1,5 @@
1
1
  module Bard
2
2
  module StagingBanner
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,10 +1,22 @@
1
1
  require "bard/staging_banner/version"
2
2
  require "bard/staging_banner/middleware"
3
+ require "letter_opener_web"
3
4
 
4
5
  module Bard
5
6
  module StagingBanner
6
7
  class Engine < ::Rails::Engine
7
- config.app_middleware.use Middleware if Rails.env.staging?
8
+ if Rails.env.staging?
9
+ config.app_middleware.use Middleware
10
+ end
11
+
12
+ if !Rails.env.production?
13
+ config.action_mailer.delivery_method = :letter_opener
14
+ initializer "bard-staging_banner.mount_letter_opener_web" do |app|
15
+ app.routes.append do
16
+ mount LetterOpenerWeb::Engine, at: "/mails"
17
+ end
18
+ end
19
+ end
8
20
  end
9
21
  end
10
22
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-staging_banner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: letter_opener_web
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Middleware to inject an annoying banner on every page in the staging
14
28
  environment
15
29
  email:
@@ -46,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  requirements: []
49
- rubygems_version: 3.0.3
63
+ rubygems_version: 3.1.6
50
64
  signing_key:
51
65
  specification_version: 4
52
66
  summary: Middleware to inject an annoying banner on every page in the staging environment