Skip to content

Commit

Permalink
Merge pull request #4517 from alphagov/presenters
Browse files Browse the repository at this point in the history
Replace HomepagePresenter with a model
  • Loading branch information
leenagupte authored Dec 19, 2024
2 parents eae338e + 9c8da0d commit 670f441
Show file tree
Hide file tree
Showing 78 changed files with 81 additions and 216 deletions.
4 changes: 0 additions & 4 deletions app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def search_component
end
helper_method :search_component

def publication_class
HomepagePresenter
end

def show_search_autocomplete?
true unless ENV["GOVUK_DISABLE_SEARCH_AUTOCOMPLETE"]
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
class ContentItem
include Withdrawable

attr_reader :attachments, :content_store_response, :content_store_hash, :body, :image,
:description, :document_type, :schema_name, :title, :base_path, :locale,
:public_updated_at
attr_reader :attachments, :base_path, :body, :content_store_hash,
:content_store_response, :description, :document_type, :image,
:links, :locale, :public_updated_at, :schema_name, :title

# SCAFFOLDING: remove the override_content_store_hash parameter when full landing page
# content items including block details are available from content-store
Expand All @@ -22,6 +22,7 @@ def initialize(content_store_response, override_content_store_hash: nil)
@base_path = content_store_hash["base_path"]
@locale = content_store_hash["locale"]
@public_updated_at = content_store_hash["public_updated_at"]
@links = content_store_hash["links"]

@attachments = get_attachments(content_store_hash.dig("details", "attachments"))

Expand Down
11 changes: 11 additions & 0 deletions app/models/homepage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Homepage < ContentItem
def popular_links
@popular_links ||= popular_links_data&.collect(&:with_indifferent_access)
end

private

def popular_links_data
@popular_links_data ||= links.dig("popular_links", 0, "details", "link_items")
end
end
27 changes: 0 additions & 27 deletions app/presenters/homepage_presenter.rb

This file was deleted.

5 changes: 2 additions & 3 deletions app/views/homepage/_popular_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%
add_view_stylesheet("popular_links")
%>

<section class="homepage-section homepage-section__popular-links">
<div class="govuk-width-container">
<div class="govuk-grid-row">
Expand All @@ -12,7 +11,7 @@
text: t("homepage.index.popular_links_heading"),
} %>
<ul class="homepage-most-viewed-list" data-module="ga4-link-tracker">
<% publication.popular_links.each_with_index do | item, index | %>
<% content_item.popular_links.each_with_index do | item, index | %>
<li class="homepage-most-viewed-list__item">
<%= render "govuk_publishing_components/components/action_link", {
text: item[:title],
Expand All @@ -25,7 +24,7 @@
'index_section': locals[:index_section],
'index_link': index + 1,
'index_section_count': locals[:index_section_count],
'index_total': t("homepage.index.popular_links").length,
'index_total': content_item.popular_links.length,
'section': "#{t("homepage.index.popular_links_heading", locale: :en)}"
}
}
Expand Down
1 change: 0 additions & 1 deletion config/locales/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ ar:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/az.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ az:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ be:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ bg:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/bn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ bn:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ cs:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,6 @@ cy:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ da:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ de:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/dr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ dr:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/el.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ el:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
13 changes: 0 additions & 13 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -660,19 +660,6 @@ en:
other_agencies: Other agencies and public bodies
other_agencies_count: 400+
popular: Popular on GOV.UK
popular_links:
- title: 'HMRC account: sign in or set up'
url: "/log-in-register-hmrc-online-services"
- title: 'Universal Credit account: sign in'
url: "/sign-in-universal-credit"
- title: 'Personal tax account: sign in or set up'
url: "/personal-tax-account"
- title: 'Self Assessment tax return: sign in'
url: "/log-in-file-self-assessment-tax-return"
- title: 'Childcare account: sign in'
url: "/sign-in-childcare-account"
- title: Check your State Pension forecast
url: "/check-state-pension"
popular_links_heading: Popular on GOV.UK
promotion_slots:
- text: Search and apply for jobs in England, Scotland and Wales.
Expand Down
1 change: 0 additions & 1 deletion config/locales/es-419.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ es-419:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ es:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/et.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ et:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/fa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ fa:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/fi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ fi:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ fr:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/gd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ gd:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/gu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ gu:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ he:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/hi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ hi:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ hr:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ hu:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/hy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ hy:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ id:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/is.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ is:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ it:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ ja:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/ka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ ka:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/kk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ kk:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ ko:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/lt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ lt:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ lv:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ ms:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
1 change: 0 additions & 1 deletion config/locales/mt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ mt:
other_agencies:
other_agencies_count:
popular:
popular_links:
popular_links_heading:
promotion_slots:
running_limited_company:
Expand Down
Loading

0 comments on commit 670f441

Please sign in to comment.