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 +4 -4
- data/.gitignore +1 -0
- data/bard-staging_banner.gemspec +2 -0
- data/lib/bard/staging_banner/middleware.rb +22 -11
- data/lib/bard/staging_banner/version.rb +1 -1
- data/lib/bard/staging_banner.rb +13 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2575c1a7289bff8ecb865ed511d0a6f8bb3bdf0648aee3cf4f64b2b7d0840542
|
4
|
+
data.tar.gz: 1448e0ae9c1d8fcdbcbd5eb6cc65efb5210f15c36884b4f568675e156659047d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29ad9d47cdbf3ed0e72b05aa4042af9560ecd7a14ac00990c22ce96f7fbb598a9a81f36f46840702db364aba9f97156d68b828a3863627a6357618f38da5a8f5
|
7
|
+
data.tar.gz: 5347e2b4cc34326830526d030c2444ab3b17d8ff5493f35fd4d9b116aa5fa27d5d59290fdaf43870673b81421a4fbccb0831bc78fe059dab5a71d3e3ffe4b20f
|
data/.gitignore
CHANGED
data/bard-staging_banner.gemspec
CHANGED
@@ -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
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
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
|
-
#
|
62
|
+
#upper-left {
|
52
63
|
top: 0;
|
53
64
|
left: 0;
|
54
65
|
transform: rotate(-45deg) translate(-52px, -60px);
|
55
66
|
}
|
56
67
|
|
57
|
-
#
|
68
|
+
#upper-right {
|
58
69
|
top: 0;
|
59
70
|
right: 0;
|
60
71
|
transform: rotate(45deg) translate(52px, -60px);
|
61
72
|
}
|
62
73
|
|
63
|
-
#
|
74
|
+
#bottom-left {
|
64
75
|
bottom: 0;
|
65
76
|
left: 0;
|
66
77
|
transform: rotate(225deg) translate(52px, -60px);
|
67
78
|
}
|
68
79
|
|
69
|
-
#
|
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
|
-
|
86
|
+
CSS
|
76
87
|
response.gsub(%r{</body>}, "#{markup}</body>")
|
77
88
|
end
|
78
89
|
end
|
data/lib/bard/staging_banner.rb
CHANGED
@@ -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
|
-
|
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.
|
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:
|
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.
|
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
|