Skip to content

Commit

Permalink
Add TakePartController
Browse files Browse the repository at this point in the history
- add view and helpers
- convert test suite to RSpec on move
- add take_part translation keys used in title_helper to formats
  section in localisation files (in government-frontend this
  was in content_item.schema_name.*)
- note that we explicitly remove the content-bottom-margin div
  class that was immediately inside the 2/3rds column. This is
  a style used in a handful of government-frontend document
  types which (on review with frontend developers) does not
  really fix the problem it's trying to fix (insufficient bottom
  margin on some tablet-sized devices). This has been captured
  as alphagov/govuk_publishing_components#4220
  to be fixed properly in the components gem.

Commit audit trail:
- app/views/take_part/show.html.erb alphagov/government-frontend@e858440
- app/helpers/machine_readable_metadata_helper.rb alphagov/government-frontend@5fb924e
- app/helpers/title_helper.rb alphagov/government-frontend@08db76d
- spec/system/take_part_spec.rb alphagov/government-frontend@6ecd50c
  • Loading branch information
KludgeKML committed Oct 31, 2024
1 parent bb1d817 commit a5d2d41
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/controllers/take_part_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TakePartController < ContentItemsController
def content_item_slug
request.path
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)
{
title:,
context: I18n.t("formats.#{document_type}", count: 1),
context_locale: t_locale_fallback("formats.#{document_type}", count: 1),
average_title_length: "long",
}
end
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_headers do %>
<%= machine_readable_metadata(@content_item, schema: :article) %>
<meta name="description" content="<%= strip_tags(@content_item.description) %>">
<% 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).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">
<%= 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>
<%= render 'shared/sidebar_navigation' %>
</div>

<%= render 'shared/footer_navigation' %>
7 changes: 7 additions & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ cy:
start_again: Dechrau eto
your_answers: Eich atebion
start_now: Dechrau nawr
take_part:
few:
many:
one: Cymryd rhan
other: Cymryd rhan
two:
zero:
transaction:
before_you_start: Cyn i chi ddechrau
more_information: Rhagor o wybodaeth
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ en:
start_again: Start again
your_answers: Your answers
start_now: Start now
take_part:
one: Take part
other: Take part
transaction:
before_you_start: Before you start
more_information: More information
Expand Down
10 changes: 8 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@
# Media previews
get "/media/:id/:filename/preview", to: "csv_preview#show", filename: /[^\/]+/

# Placeholder for attachments being virus-scanned
get "/government/placeholder", to: "placeholder#show"
scope "/government" do
# Placeholder for attachments being virus-scanned
get "/placeholder", to: "placeholder#show"

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

# Simple Smart Answer pages
constraints FormatRoutingConstraint.new("simple_smart_answer") 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 a5d2d41

Please sign in to comment.