Skip to content

Commit

Permalink
Merge pull request #4290 from alphagov/hide-missing-blocks
Browse files Browse the repository at this point in the history
Hide missing blocks on landing page
  • Loading branch information
leenagupte authored Oct 16, 2024
2 parents 84afd56 + 223bd80 commit 021f26c
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 12 deletions.
7 changes: 7 additions & 0 deletions app/helpers/block_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
module BlockHelper
def render_block(block)
render("landing_page/blocks/#{block.type}", block:)
rescue ActionView::MissingTemplate
Rails.logger.warn("Missing template for block #{block.type}")
""
end

def tab_items_to_component_format(tab_items)
tab_items.map do |ti|
{
Expand Down
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_action_link.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= render "govuk_publishing_components/components/action_link", {
inverse:,
inverse: block.data["inverse"],
text: block.data["text"],
href: block.data["href"]
} %>
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_blocks_container.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="blocks-container">
<% block.children.each do |child| %>
<%= render "landing_page/blocks/#{child.type}", block: child %>
<%= render_block(child) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="app-b-card">
<div class="app-b-card__textbox">
<% block.card_content.each do |subblock| %>
<%= render "landing_page/blocks/#{subblock.type}", block: subblock, inverse: true %>
<%= render_block(subblock) %>
<% end %>
</div>
<figure class="app-b-card__figure">
Expand Down
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_featured.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="featured">
<div class="featured__child featured__child--content">
<% block.featured_content.each do |subblock| %>
<%= render "landing_page/blocks/#{subblock.type}", block: subblock, inverse: true %>
<%= render_block(subblock) %>
<% end %>
</div>
<div class="featured__child featured__child--image">
Expand Down
4 changes: 1 addition & 3 deletions app/views/landing_page/blocks/_govspeak.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<% inverse ||= false %>
<%= render "govuk_publishing_components/components/govspeak", { inverse: } do %>
<%= render "govuk_publishing_components/components/govspeak", { inverse: block.data["inverse"] } do %>
<%= block.data["content"].html_safe %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_grid_container.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<div class="grid-container">
<% block.children.each do |child| %>
<%= render "landing_page/blocks/#{child.type}", block: child %>
<%= render_block(child) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/landing_page/blocks/_hero.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="govuk-grid-column-two-thirds">
<div class="app-b-hero__textbox">
<% block.hero_content.each do |subblock| %>
<%= render "landing_page/blocks/#{subblock.type}", block: subblock, inverse: true %>
<%= render_block(subblock) %>
<% end %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/landing_page/blocks/_two_column_layout.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="govuk-grid-row">
<div class="<%= column_class_for_assymetric_columns(block.total_columns, block.left_column_size) %>">
<%= render "landing_page/blocks/#{block.left.type}", block: block.left %>
<%= render_block(block.left) %>
</div>
<div class="<%= column_class_for_assymetric_columns(block.total_columns, block.right_column_size) %>">
<%= render "landing_page/blocks/#{block.right.type}", block: block.right %>
<%= render_block(block.right) %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/landing_page/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="landing-page" id="content">
<% @content_item.blocks.each do |block| %>
<%= tag.div class: ["govuk-block__#{block.type}", ("govuk-width-container" unless block.full_width?)] do
render "landing_page/blocks/#{block.type}", block:
render_block(block)
end %>
<% end %>
<% if @content_item.blocks.empty? %>
Expand Down
8 changes: 8 additions & 0 deletions lib/data/landing_page_content_items/landing_page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ blocks:
hero_content:
blocks:
- type: govspeak
inverse: true
content: |
<h2>This is a heading</h2>
<p>Lorem ipsum...</p>
- type: action_link
inverse: true
text: "See the tasks"
href: "todo"
- type: featured
Expand All @@ -44,6 +46,7 @@ blocks:
featured_content:
blocks:
- type: govspeak
inverse: true
content: |
<h2>Title of the content</h2>
<p>Lorem ipsum dolor sit amet. In voluptas dolorum vel veniam nisi et voluptate dolores id voluptatem distinctio. Et quia accusantium At ducimus quis aut voluptates iusto aut esse suscipit.</p>
Expand Down Expand Up @@ -97,6 +100,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 1 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -105,6 +109,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 2 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -113,6 +118,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 3 govspeak title</a></h2>
- type: two_column_layout
theme: one_third_two_thirds
Expand All @@ -128,6 +134,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 1 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -136,6 +143,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 2 govspeak title goes here</a></h2>
- type: share_links
links:
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/landing_page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ blocks:
hero_content:
blocks:
- type: govspeak
inverse: true
content: |
<h2>This is a heading</h2>
<p>Lorem ipsum...</p>
- type: action_link
inverse: true
text: "See the missions"
href: "todo"
- type: featured
Expand All @@ -44,6 +46,7 @@ blocks:
featured_content:
blocks:
- type: govspeak
inverse: true
content: |
<h2>Title of the content</h2>
<p>Lorem ipsum dolor sit amet. In voluptas dolorum vel veniam nisi et voluptate dolores id voluptatem distinctio. Et quia accusantium At ducimus quis aut voluptates iusto aut esse suscipit.</p>
Expand Down Expand Up @@ -97,6 +100,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 1 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -105,6 +109,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 2 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -113,6 +118,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 3 govspeak title</a></h2>
- type: two_column_layout
theme: one_third_two_thirds
Expand All @@ -128,6 +134,7 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 1 govspeak title goes here</a></h2>
- type: card
image:
Expand All @@ -136,4 +143,5 @@ blocks:
card_content:
blocks:
- type: govspeak
inverse: true
content: <h2><a href="http://gov.uk">Title 2 govspeak title goes here</a></h2>
7 changes: 7 additions & 0 deletions spec/helpers/block_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@
end
end
end

describe "#render_block" do
it "returns an empty string when a partial template doesn't exist" do
block = double(type: "not_a_block")
expect(render_block(block)).to be_empty
end
end
end

0 comments on commit 021f26c

Please sign in to comment.