Skip to content

Commit 798eaff

Browse files
committed
Updating model and view component
Initial setup of mocks and testing
1 parent e0f0384 commit 798eaff

File tree

15 files changed

+112
-49
lines changed

15 files changed

+112
-49
lines changed
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
# frozen_string_literal: true
22

33
class Cms::FooterComponent < ViewComponent::Base
4+
attr_reader :data
5+
46
def initialize(data:)
57
@data = data
68
end
79

810
def company_logo
9-
@data.data_models.first
11+
data_models_by_type(Cms::Models::Images::Image).first
1012
end
1113

1214
def funding_logo
13-
@data.data_models.second
15+
data_models_by_type(Cms::Models::Images::Image).second
16+
end
17+
18+
def company_url
19+
find_text_field(0)&.value
20+
end
21+
22+
def funding_url
23+
find_text_field(1)&.value
1424
end
1525

1626
def link_blocks
17-
@data.data_models.last.link_block
27+
data_models_by_type(Cms::Models::Meta::FooterLinkBlock).first&.process_blocks
28+
end
29+
30+
private
31+
32+
def data_models_by_type(type)
33+
data.data_models.select { |model| model.is_a?(type) }
34+
end
35+
36+
def find_text_field(index)
37+
data_models_by_type(Cms::Models::Data::TextField)[index]
1838
end
1939
end

app/components/cms/footer_component/footer_component.html.erb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22
<%= row.with_column("full") do %>
33
<div class="cms-footer-component-wrapper">
44
<div>
5-
<%= render company_logo.render %>
5+
<a href="<%= company_url %>">
6+
<%= render company_logo.render %>
7+
</a>
68
<p class="govuk-body-s cms-footer-component--funding-text">Funded by</p>
7-
<%= render funding_logo.render %>
9+
<a href="<%= funding_url %>">
10+
<%= render funding_logo.render %>
11+
</a>
812
</div>
9-
1013
<% link_blocks.each do |block| %>
1114
<div class="cms-footer-component__link-block">
1215
<% block[:links].each do |link| %>
13-
<div>
14-
<%= link_to link[:link_text], link[:url], class: "govuk-footer__link ncce-link ncce-link--on-dark" %>
15-
<% if link[:icon][:data] %>
16-
ICON
17-
<% end %>
18-
</div>
16+
<%= render link.render %>
1917
<% end %>
2018
</div>
2119
<% end %>

app/components/cms/footer_component/footer_component.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
img {
66
width: 125px;
7-
8-
@include govuk-media-query($until: desktop) {
9-
width: 80px;
10-
}
117
}
128

139
&--funding-text {
@@ -31,5 +27,14 @@
3127
display: flex;
3228
flex-direction: column;
3329
gap: 12px;
30+
31+
.cms-icon-row {
32+
margin-top: 0;
33+
34+
img {
35+
width: 20px !important;
36+
height: 20px !important;
37+
}
38+
}
3439
}
3540
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# frozen_string_literal: true
22

33
class Cms::LinkWithIconComponent < ViewComponent::Base
4-
def initialize(link_text:, url:, icon:)
4+
def initialize(link_text:, url:, icon: nil, additional_classes: nil)
55
@link_text = link_text
66
@url = url
77
@icon = icon
8+
@additional_classes = additional_classes
89
end
910

1011
def call
1112
content_tag :div, class: "cms-icon-row" do
12-
concat(render(@icon.render))
13-
concat(link_to(@link_text, @url))
13+
if @icon
14+
concat(render(@icon.render))
15+
end
16+
concat(link_to(@link_text, @url, class: @additional_classes))
1417
end
1518
end
1619
end

app/services/cms/models/dynamic_components/content_blocks/link_with_icon.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ module Models
33
module DynamicComponents
44
module ContentBlocks
55
class LinkWithIcon
6-
attr_accessor :link_text, :url, :icon
6+
attr_accessor :link_text, :url, :icon, :additional_classes
77

8-
def initialize(link_text:, url:, icon:)
8+
def initialize(link_text:, url:, icon:, additional_classes:)
99
@link_text = link_text
1010
@url = url
1111
@icon = icon
12+
@additional_classes = additional_classes
1213
end
1314

1415
def render
15-
Cms::LinkWithIconComponent.new(link_text:, url:, icon:)
16+
Cms::LinkWithIconComponent.new(link_text:, url:, icon:, additional_classes:)
1617
end
1718
end
1819
end

app/services/cms/models/meta/footer.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/services/cms/models/meta/footer_link_block.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ def initialize(link_block:)
99
end
1010

1111
def process_blocks
12-
@link_block.each do |block|
13-
block
12+
@link_block.map do |block|
13+
{
14+
links: block[:links].map do |link|
15+
link
16+
end
17+
}
1418
end
1519
end
16-
17-
def render
18-
Cms::FooterComponent.new(link_block:)
19-
end
2020
end
2121
end
2222
end

app/services/cms/providers/strapi/factories/model_factory.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,20 @@ def self.to_footer(strapi_data, _all_data)
161161
{
162162
link_block: strapi_data.map do |link|
163163
{
164-
links: link[:link].map { |l| {link_text: l[:linkText], url: l[:url], icon: l[:icon]} }
164+
links: link[:link].map {
165+
Models::DynamicComponents::ContentBlocks::LinkWithIcon.new(
166+
link_text: _1[:linkText],
167+
url: _1[:url],
168+
icon: _1[:icon].dig(:data).nil? ? nil : Models::Images::Image.new(
169+
url: _1[:icon][:data][:attributes][:url],
170+
alt: _1[:icon][:data][:attributes][:alternativeText],
171+
caption: _1[:icon][:data][:attributes][:caption],
172+
default_size: :small,
173+
formats: _1[:icon][:data][:attributes][:formats]
174+
),
175+
additional_classes: ["govuk-footer__link", "ncce-link", "ncce-link--on-dark"]
176+
)
177+
}
165178
}
166179
end
167180
}

app/services/cms/providers/strapi/mocks/dynamic_components/content_blocks/link_with_icon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class LinkWithIcon < StrapiMock
1010
attribute(:linkText) { Faker::Lorem.sentence }
1111
attribute(:url) { Faker::Internet.url }
1212
attribute(:icon) { Images::Image.generate_raw_data }
13+
attribute(:additional_classes) {}
1314
end
1415
end
1516
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module Meta
6+
class FooterLinkBlock < StrapiMock
7+
attribute(:link_block) { Array.new(3) { DynamicComponents::ContentBlocks::LinkWithIcon.as_model } }
8+
end
9+
end
10+
end
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)