Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
WIP

FIX - add welsh for take_part content_item

WIP

WIP

WIP

WIP

Fix locale language_names

Remove chat promo helper

WIP

Update factory to fix links

Add available translations into model

Remove specific model

Add translations methods to locales helper

Simplify

Simplify nav bars

Fix

FIX
  • Loading branch information
KludgeKML committed Sep 5, 2024
1 parent 94e1cb4 commit f388c5c
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/take_part_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TakePartController < ContentItemsController
helper_method :view_context

def content_item_slug
request.path
end
end
30 changes: 30 additions & 0 deletions app/helpers/locale_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,34 @@ module LocaleHelper
def lang_attribute(locale)
"lang=#{locale}" unless I18n.default_locale.to_s == locale.to_s
end

def native_language_name_for(locale)
I18n.t("language_names.#{locale}", locale:)
end

def translations_for_nav(translations)
translations.map do |translation|
{
locale: translation["locale"],
base_path: translation["base_path"],
text: native_language_name_for(translation["locale"]),
}.tap do |h|
h[:active] = true if h[:locale] == I18n.locale.to_s
end
end
end

def t_locale_fallback(key, options = {})
options[:locale] = I18n.locale
options[:fallback] = nil
translation = I18n.t(key, **options)

if translation.nil? || translation.downcase.include?("translation missing")
I18n.default_locale
end
end

def page_text_direction
I18n.t("i18n.direction", locale: I18n.locale, default: "ltr")
end
end
6 changes: 6 additions & 0 deletions app/helpers/machine_readable_metadata_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MachineReadableMetadataHelper
def machine_readable_metadata(content_item, args)
locals = { content_item: content_item.to_h }.merge(args)
render("govuk_publishing_components/components/machine_readable_metadata", locals)
end
end
10 changes: 10 additions & 0 deletions app/helpers/title_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module TitleHelper
def title_and_context(title, document_type, view_context)
{
title:,
context: I18n.t("content_item.schema_name.#{document_type}", count: 1),
context_locale: view_context.t_locale_fallback("content_item.schema_name.#{document_type}", count: 1),
average_title_length: "long",
}
end
end
6 changes: 6 additions & 0 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ def initialize(content_store_response)

delegate :to_h, to: :content_store_response
delegate :cache_control, to: :content_store_response

def available_translations
translations = content_store_response["links"]["available_translations"] || []

translations.sort_by { |t| t["locale"] == I18n.default_locale.to_s ? "" : t["locale"] }
end
end
10 changes: 10 additions & 0 deletions app/models/content_item_factory.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
class ContentItemFactory
def self.build(content_hash)
content_hash["links"]["ordered_related_items"] = ordered_related_items(content_hash["links"]) if content_hash["links"]

content_item_class(content_hash).new(content_hash)
end

def self.content_item_class(_content_hash)
ContentItem
end

def self.ordered_related_items(links)
return [] if links["ordered_related_items_overrides"].present?

links["ordered_related_items"].presence || links.fetch(
"suggested_ordered_related_items", []
)
end
end
11 changes: 11 additions & 0 deletions app/views/shared/_footer_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% @contextual_footer = capture do %>
<%= render 'govuk_publishing_components/components/contextual_footer', content_item: @content_item.to_h %>
<% end %>

<% if @contextual_footer.present? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= @contextual_footer %>
</div>
</div>
<% end %>
3 changes: 3 additions & 0 deletions app/views/shared/_sidebar_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="govuk-grid-column-one-third">
<%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: @content_item.to_h %>
</div>
6 changes: 6 additions & 0 deletions app/views/shared/_translations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if @content_item.available_translations.any? %>
<div class="govuk-grid-column-one-third">
<%= render 'govuk_publishing_components/components/translation_nav',
translations: translations_for_nav(@content_item.available_translations) %>
</div>
<% end %>
37 changes: 37 additions & 0 deletions app/views/take_part/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<% content_for :title do %>
<%= @content_item.title %> - GOV.UK
<% end %>

<% content_for :extra_head_content do %>
<%= machine_readable_metadata(@content_item, schema: :article) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title', title_and_context(@content_item.title, @content_item.document_type, view_context).except(:average_title_length) %>
<%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %>
</div>

<%= render 'shared/translations' %>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="content-bottom-margin">
<%= render 'components/figure',
src: @content_item.image["url"],
alt: @content_item.image["alt_text"],
credit: @content_item.image["credit"],
caption: @content_item.image["caption"] if @content_item.image %>

<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction
} do %>
<%= raw(@content_item.body) %>
<% end %>
</div>
</div>
<%= render 'shared/sidebar_navigation' %>
</div>

<%= render 'shared/footer_navigation' %>
12 changes: 12 additions & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ cy:
components:
figure:
image_credit: 'Delwedd gan: %{credit}'
content_item:
schema_name:
take_part:
few:
many:
one: Cymryd rhan
other: Cymryd rhan
two:
zero:
continue: Parhau
cookies:
always_on: Mae angen iddynt fod ymlaen bob amser.
Expand Down Expand Up @@ -812,6 +821,9 @@ cy:
universal_credit:
most_active:
'no': Na
language_names:
cy: Cymraeg
en:
or:
place:
children_social_care: Gallwch alw'r tîm gofal cymdeithasol i blant yn y cyngor yn
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ en:
components:
figure:
image_credit: 'Image credit: %{credit}'
content_item:
schema_name:
take_part:
one: Take part
other: Take part
continue: Continue
cookies:
always_on: They always need to be on.
Expand Down Expand Up @@ -651,6 +656,9 @@ en:
link: /vat-rates
'no': 'No'
or: or
language_names:
cy: Welsh
en: English
place:
children_social_care: You can call the children's social care team at the council in
go_to_website: Go to their website
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@

get "/media/:id/:filename/preview", to: "csv_preview#show", filename: /[^\/]+/

get "/government/placeholder", to: "placeholder#show"
scope "/government" do
get "/placeholder", to: "placeholder#show"
scope "/get-involved" do
get "/take-part/:slug", to: "take_part#show"
end
end

# route API errors to the error handler
constraints ApiErrorRoutingConstraint.new do
Expand Down
24 changes: 24 additions & 0 deletions spec/system/take_part_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
RSpec.describe "TakePart" do
before do
content_store_has_example_item("/government/get-involved/take-part/tp1", schema: :take_part)
end

context "/government/get-involved/take-part/:slug" do
it "displays the take_part page" do
visit "/government/get-involved/take-part/tp1"

expect(page).to have_title("Become a councillor - GOV.UK")

expect(page).to have_css("h1", text: "Become a councillor")
expect(page).to have_text("All councils are led by democratically elected councillors who set the vision and direction, and represent their local community.")

assert page.has_text?("There are roughly 20,000 local councillors in England. Councillors are elected to the local council to represent their own local community, so they must either live or work in the area.")
end

it "does not display a single page notification button" do
visit "/government/get-involved/take-part/tp1"

expect(page).not_to have_css(".gem-c-single-page-notification-button")
end
end
end

0 comments on commit f388c5c

Please sign in to comment.