Skip to content

Commit e0f0384

Browse files
committed
Initial work setting up Footer in Strapi with queries, models and created a new view component
Basic styling and layout on the component completed
1 parent 7a7ef6a commit e0f0384

File tree

13 files changed

+212
-84
lines changed

13 files changed

+212
-84
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::FooterComponent < ViewComponent::Base
4+
def initialize(data:)
5+
@data = data
6+
end
7+
8+
def company_logo
9+
@data.data_models.first
10+
end
11+
12+
def funding_logo
13+
@data.data_models.second
14+
end
15+
16+
def link_blocks
17+
@data.data_models.last.link_block
18+
end
19+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<%= render GovGridRowComponent.new(additional_classes: "cms-footer-component", padding: {top: 0, bottom: 0}) do |row| %>
2+
<%= row.with_column("full") do %>
3+
<div class="cms-footer-component-wrapper">
4+
<div>
5+
<%= render company_logo.render %>
6+
<p class="govuk-body-s cms-footer-component--funding-text">Funded by</p>
7+
<%= render funding_logo.render %>
8+
</div>
9+
10+
<% link_blocks.each do |block| %>
11+
<div class="cms-footer-component__link-block">
12+
<% 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>
19+
<% end %>
20+
</div>
21+
<% end %>
22+
</div>
23+
<% end %>
24+
<% end %>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.cms-footer-component {
2+
color: $white;
3+
height: 100%;
4+
5+
img {
6+
width: 125px;
7+
8+
@include govuk-media-query($until: desktop) {
9+
width: 80px;
10+
}
11+
}
12+
13+
&--funding-text {
14+
color: $white;
15+
font-size: 14px;
16+
margin: 10px 0;
17+
}
18+
19+
&-wrapper {
20+
display: flex;
21+
justify-content: space-between;
22+
23+
@include govuk-media-query($until: desktop) {
24+
flex-wrap: wrap;
25+
justify-content: flex-start;
26+
gap: 2rem;
27+
}
28+
}
29+
30+
&__link-block {
31+
display: flex;
32+
flex-direction: column;
33+
gap: 12px;
34+
}
35+
}

app/controllers/application_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
55

66
before_action :authenticate
77
before_action :access_cms_header
8+
before_action :access_cms_footer
89

910
def authenticate
1011
return unless ENV["BASIC_AUTH_PASSWORD"]
@@ -20,6 +21,12 @@ def access_cms_header
2021
@cms_header = nil
2122
end
2223

24+
def access_cms_footer
25+
@cms_footer = Cms::Singles::Footer.get
26+
rescue ActiveRecord::RecordNotFound
27+
@cms_footer = nil
28+
end
29+
2330
def authenticate_user!
2431
redirect_to(helpers.create_account_url) unless current_user
2532
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Cms
2+
module Models
3+
module Meta
4+
class Footer
5+
attr_accessor :image
6+
7+
def initialize(image:)
8+
@image = image
9+
end
10+
11+
def render
12+
Cms::FooterComponent.new(link_block:)
13+
end
14+
end
15+
end
16+
end
17+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Cms
2+
module Models
3+
module Meta
4+
class FooterLinkBlock
5+
attr_accessor :link_block
6+
7+
def initialize(link_block:)
8+
@link_block = link_block
9+
end
10+
11+
def process_blocks
12+
@link_block.each do |block|
13+
block
14+
end
15+
end
16+
17+
def render
18+
Cms::FooterComponent.new(link_block:)
19+
end
20+
end
21+
end
22+
end
23+
end

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ module ModelFactory
1414
Models::DynamicZones::EnrichmentDynamicZone => :to_dynamic_zone,
1515
Models::Collections::EnrichmentList => :to_enrichment_list,
1616
Models::Images::FeaturedImage => :to_featured_image,
17+
Models::Images::Image => :to_image,
1718
Models::Meta::HeaderMenu => :to_menu,
19+
Models::Meta::FooterLinkBlock => :to_footer,
1820
Models::DynamicZones::HomepageDynamicZone => :to_dynamic_zone,
1921
Models::Meta::PageTitle => :to_page_title,
2022
Models::Meta::Seo => :to_seo,
@@ -131,6 +133,19 @@ def self.to_featured_image(strapi_data, _all_data, size = :large)
131133
}
132134
end
133135

136+
def self.to_image(strapi_data, _all_data, default_size = :medium)
137+
return nil unless strapi_data.dig(:data, :attributes)
138+
139+
image_data = strapi_data[:data][:attributes]
140+
{
141+
url: image_data[:url],
142+
alt: image_data[:alternativeText],
143+
caption: image_data[:caption],
144+
formats: image_data[:formats],
145+
default_size:
146+
}
147+
end
148+
134149
def self.to_menu(strapi_data, _all_data)
135150
{
136151
menu_items: strapi_data.map do |menu_item|
@@ -142,6 +157,16 @@ def self.to_menu(strapi_data, _all_data)
142157
}
143158
end
144159

160+
def self.to_footer(strapi_data, _all_data)
161+
{
162+
link_block: strapi_data.map do |link|
163+
{
164+
links: link[:link].map { |l| {link_text: l[:linkText], url: l[:url], icon: l[:icon]} }
165+
}
166+
end
167+
}
168+
end
169+
145170
def self.to_page_title(strapi_data, _all_data)
146171
{
147172
title: strapi_data[:title],

app/services/cms/providers/strapi/queries/base_query.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class BaseQuery
1818
Models::DynamicZones::EnrichmentDynamicZone => EnrichmentDynamicZone,
1919
Models::DynamicZones::HomepageDynamicZone => HomepageDynamicZone,
2020
Models::Images::FeaturedImage => FeaturedImage,
21+
Models::Images::Image => Image,
22+
Models::Meta::FooterLinkBlock => FooterLinkBlock,
2123
Models::Meta::HeaderMenu => HeaderMenu,
2224
Models::Meta::PageTitle => PageTitle,
2325
Models::Meta::Seo => Seo,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Queries
5+
class FooterLinkBlock
6+
def self.embed(name)
7+
<<~GRAPHQL.freeze
8+
#{name} {
9+
link {
10+
linkText
11+
url
12+
#{SharedFields.image_fields("icon")}
13+
}
14+
}
15+
GRAPHQL
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Queries
5+
class Image
6+
def self.embed(name)
7+
<<~GRAPHQL.freeze
8+
#{SharedFields.image_fields(name)}
9+
GRAPHQL
10+
end
11+
end
12+
end
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)