govuk_web_banners 1.31.0 → 1.32.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 +4 -4
- data/Rakefile +12 -1
- data/app/assets/stylesheets/govuk_web_banners/dependencies.scss +1 -0
- data/app/views/govuk_web_banners/_uprating_banner.html.erb +9 -0
- data/config/govuk_web_banners/uprating_banners.yml +1 -0
- data/lib/govuk_web_banners/uprating_banner.rb +37 -0
- data/lib/govuk_web_banners/version.rb +1 -1
- data/lib/govuk_web_banners.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a3571d68045883e5fdf60e17b2f461bafc37f49bce4b3c6415390eb971fb950
|
|
4
|
+
data.tar.gz: 03bf2bc4754740f9ae7f283f8fd4e8c5bb08a88645650a6d12c05788e3311e1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 853e1c08455a797dbc02aaae5ff8b12a1d159176a947b1088d0262a7bb06e8d3d02b8f41c9f686de9185464f79bddf95f2b0cc5b16e082b2053ff0fb868cfeb7
|
|
7
|
+
data.tar.gz: 44da1a1b01a5a894d2b6e18c1c5732509b60483ac93606c7f13f5f1d4090efa940d157cd2c09bad54caac7b2273ba2e94fcccbb8c7e496bd9e57e8428811e816
|
data/Rakefile
CHANGED
|
@@ -14,6 +14,7 @@ RSpec::Core::RakeTask.new
|
|
|
14
14
|
|
|
15
15
|
require "govuk_web_banners/validators/global_banner"
|
|
16
16
|
require "govuk_web_banners/validators/recruitment_banner"
|
|
17
|
+
require "govuk_web_banners/validators/uprating_banner"
|
|
17
18
|
require "rainbow"
|
|
18
19
|
|
|
19
20
|
def output_validator_info(validator, name)
|
|
@@ -57,4 +58,14 @@ rescue StandardError => e
|
|
|
57
58
|
exit(1)
|
|
58
59
|
end
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
desc "show errors in the live uprating banner config"
|
|
62
|
+
task :check_uprating_config do
|
|
63
|
+
validator = GovukWebBanners::Validators::UpratingBanner.new(GovukWebBanners::UpratingBanner.all_banners)
|
|
64
|
+
output_validator_info(validator, "uprating banner")
|
|
65
|
+
rescue StandardError => e
|
|
66
|
+
puts(e)
|
|
67
|
+
puts Rainbow("Live uprating banner config could not be read (if there are no banners, check banner key is marked as an empty array - banners: [])").red
|
|
68
|
+
exit(1)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
task default: %i[check_global_config check_recruitment_config check_uprating_config rubocop spec]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<% uprating_banner = GovukWebBanners::UpratingBanner.for_path(request.path) %>
|
|
2
|
+
<% if uprating_banner.present? %>
|
|
3
|
+
<div class="govuk-!-margin-top-4">
|
|
4
|
+
<%= render "govuk_publishing_components/components/notice", {
|
|
5
|
+
title: uprating_banner.text,
|
|
6
|
+
show_banner_title: true
|
|
7
|
+
} %>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
banners: []
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module GovukWebBanners
|
|
2
|
+
class UpratingBanner
|
|
3
|
+
BANNER_CONFIG_FILE = "../../config/govuk_web_banners/uprating_banners.yml".freeze
|
|
4
|
+
|
|
5
|
+
def self.for_path(path)
|
|
6
|
+
active_banners.find do |banner|
|
|
7
|
+
return banner if banner.page_paths.include?(path)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.active_banners
|
|
12
|
+
all_banners.select(&:active?)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.all_banners
|
|
16
|
+
uprating_banners_urls_file_path = Rails.root.join(__dir__, BANNER_CONFIG_FILE)
|
|
17
|
+
uprating_banners_data = YAML.load_file(uprating_banners_urls_file_path)
|
|
18
|
+
uprating_banners_data["banners"].map { |attributes| UpratingBanner.new(attributes:) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
attr_reader :name, :text, :page_paths, :start_date, :end_date
|
|
22
|
+
|
|
23
|
+
def initialize(attributes:)
|
|
24
|
+
@name = attributes["name"]
|
|
25
|
+
@text = attributes["text"]
|
|
26
|
+
@page_paths = attributes["page_paths"]
|
|
27
|
+
@start_date = attributes["start_date"] ? ActiveSupport::TimeZone[GovukWebBanners::TIME_ZONE].parse(attributes["start_date"]) : Time.at(0)
|
|
28
|
+
@end_date = attributes["end_date"] ? ActiveSupport::TimeZone[GovukWebBanners::TIME_ZONE].parse(attributes["end_date"]) : Time.now + 10.years
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# NB: .between? is inclusive. To make it exclude the end date, we set the end range as
|
|
32
|
+
# 1 second earlier.
|
|
33
|
+
def active?
|
|
34
|
+
Time.zone.now.between?(start_date, end_date - 1.second)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/govuk_web_banners.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "govuk_web_banners/global_banner"
|
|
|
4
4
|
require "govuk_web_banners/emergency_banner"
|
|
5
5
|
require "govuk_web_banners/engine"
|
|
6
6
|
require "govuk_web_banners/recruitment_banner"
|
|
7
|
+
require "govuk_web_banners/uprating_banner"
|
|
7
8
|
require "govuk_web_banners/version"
|
|
8
9
|
|
|
9
10
|
module GovukWebBanners
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: govuk_web_banners
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.32.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GOV.UK Dev
|
|
@@ -179,13 +179,16 @@ files:
|
|
|
179
179
|
- app/views/govuk_web_banners/_emergency_banner.html.erb
|
|
180
180
|
- app/views/govuk_web_banners/_global_banner.html.erb
|
|
181
181
|
- app/views/govuk_web_banners/_recruitment_banner.html.erb
|
|
182
|
+
- app/views/govuk_web_banners/_uprating_banner.html.erb
|
|
182
183
|
- config/govuk_web_banners/global_banners.yml
|
|
183
184
|
- config/govuk_web_banners/recruitment_banners.yml
|
|
185
|
+
- config/govuk_web_banners/uprating_banners.yml
|
|
184
186
|
- lib/govuk_web_banners.rb
|
|
185
187
|
- lib/govuk_web_banners/emergency_banner.rb
|
|
186
188
|
- lib/govuk_web_banners/engine.rb
|
|
187
189
|
- lib/govuk_web_banners/global_banner.rb
|
|
188
190
|
- lib/govuk_web_banners/recruitment_banner.rb
|
|
191
|
+
- lib/govuk_web_banners/uprating_banner.rb
|
|
189
192
|
- lib/govuk_web_banners/version.rb
|
|
190
193
|
homepage: https://github.com/alphagov/govuk_web_banners
|
|
191
194
|
licenses:
|
|
@@ -208,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
208
211
|
- !ruby/object:Gem::Version
|
|
209
212
|
version: '0'
|
|
210
213
|
requirements: []
|
|
211
|
-
rubygems_version: 4.0.
|
|
214
|
+
rubygems_version: 4.0.9
|
|
212
215
|
specification_version: 4
|
|
213
216
|
summary: A gem to support banners on GOV.UK frontend applications
|
|
214
217
|
test_files: []
|