Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move speech document #4573

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Transaction start pages:

* https://www.gov.uk/government/get-involved

### Speeches

* https://www.gov.uk/government/speeches/motorcycle-testing


### Hard-coded routes

* https://www.gov.uk/ (homepage)
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $govuk-include-default-font-face: false;

// Helper stylesheets (things on more than one page layout)
@import "helpers/truncated-url";
@import "helpers/content-bottom-margin";

// frontend mixins
@import "mixins/margins";
Expand Down Expand Up @@ -64,3 +65,8 @@ $govuk-include-default-font-face: false;
.bank-hols .govuk-panel {
margin-bottom: govuk-spacing(6);
}

.inverse-background {
background: $govuk-brand-colour;
color: govuk-colour("white");
}
7 changes: 7 additions & 0 deletions app/assets/stylesheets/helpers/_content-bottom-margin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.content-bottom-margin {
margin-bottom: govuk-spacing(4);

@include govuk-media-query($from: tablet) {
@include responsive-bottom-margin;
}
}
24 changes: 24 additions & 0 deletions app/assets/stylesheets/helpers/_publisher-metadata-with-logo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "govuk_publishing_components/individual_component_support";

.metadata-logo-wrapper {
border-top: 1px solid $govuk-border-colour;
margin-left: govuk-spacing(3);
margin-right: govuk-spacing(3);
@include govuk-clearfix;

.metadata-column {
padding-left: 0;
padding-top: govuk-spacing(3);
}

.metadata-logo {
max-height: 90px;
max-width: 100%;
padding-bottom: govuk-spacing(3);
padding-top: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
float: right;
}
}
}
91 changes: 46 additions & 45 deletions app/assets/stylesheets/mixins/_margins.scss
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
@mixin responsive-bottom-margin {
margin-bottom: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-bottom: govuk-spacing(8);
}
}

@mixin responsive-top-margin {
margin-top: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-top: govuk-spacing(8);
}
}

@mixin responsive-vertical-margins {
@include responsive-bottom-margin;
@include responsive-top-margin;
}

.responsive-bottom-margin {
@include responsive-bottom-margin;
}

// Service Manuals
@mixin gutter-bottom-margin {
margin-bottom: govuk-spacing(6);
}

@mixin gutter-top-margin {
margin-top: govuk-spacing(6);
}

@mixin gutter-vertical-margins {
@include gutter-bottom-margin;
@include gutter-top-margin;
}

@mixin gutter-bottom-margin-to-double {
margin-bottom: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-bottom: govuk-spacing(9);
}
}
margin-bottom: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-bottom: govuk-spacing(8);
}
}

@mixin responsive-top-margin {
margin-top: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-top: govuk-spacing(8);
}
}

@mixin responsive-vertical-margins {
@include responsive-bottom-margin;
@include responsive-top-margin;
}

.responsive-bottom-margin {
@include responsive-bottom-margin;
}

// Service Manuals
@mixin gutter-bottom-margin {
margin-bottom: govuk-spacing(6);
}

@mixin gutter-top-margin {
margin-top: govuk-spacing(6);
}

@mixin gutter-vertical-margins {
@include gutter-bottom-margin;
@include gutter-top-margin;
}

@mixin gutter-bottom-margin-to-double {
margin-bottom: govuk-spacing(3);

@include govuk-media-query($from: tablet) {
margin-bottom: govuk-spacing(9);
}
}

5 changes: 5 additions & 0 deletions app/controllers/speech_controller.rb
deborahchua marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SpeechController < ContentItemsController
def show
@presenter = SpeechPresenter.new(@content_item)
end
end
6 changes: 5 additions & 1 deletion app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def govuk_styled_link(text, path: nil, inverse: false)
classes = "govuk-link"
classes << " govuk-link--inverse" if inverse

"<a href='#{path}' class='#{classes}'>#{text}</a>".html_safe
"<a href='#{path}' class='#{classes}'>".html_safe + text + "</a>".html_safe
end

def govuk_styled_links_list(links)
links.map { |link| govuk_styled_link(link["title"], path: link["base_path"]) }
end
end
23 changes: 23 additions & 0 deletions app/models/concerns/news_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module NewsImage
sairamya93 marked this conversation as resolved.
Show resolved Hide resolved
extend ActiveSupport::Concern

def image
content_store_hash.dig("details", "image") || default_news_image || placeholder_image
end

private

def default_news_image
organisation = content_store_hash.dig("links", "primary_publishing_organisation")
organisation[0].dig("details", "default_news_image") if organisation.present?
end

def placeholder_image
# this image has been uploaded to asset-manager
if content_store_hash["document_type"] == "world_news_story"
{ "url" => "https://assets.publishing.service.gov.uk/media/5e985599d3bf7f3fc943bbd8/UK_government_logo.jpg" }
else
{ "url" => "https://assets.publishing.service.gov.uk/media/5e59279b86650c53b2cefbfe/placeholder.jpg" }
end
end
end
27 changes: 27 additions & 0 deletions app/models/concerns/organisations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Organisations
extend ActiveSupport::Concern

included do
def linkable_organisations
organisation_links_with_emphasis
end
end

private

def organisation_links_with_emphasis
expanded_organisations.sort_by { |link| emphasised?(link) ? -1 : 1 }
end

def expanded_organisations
content_store_hash.dig("links", "organisations") || []
end

def emphasised?(link)
link["content_id"].in?(emphasised_organisations)
end

def emphasised_organisations
content_store_hash.dig("details", "emphasised_organisations") || []
end
end
32 changes: 32 additions & 0 deletions app/models/concerns/political.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Political
sairamya93 marked this conversation as resolved.
Show resolved Hide resolved
extend ActiveSupport::Concern

included do
def historically_political?
political? && historical?
end

def publishing_government
content_store_hash.dig(
"links", "government", 0, "title"
)
end
end

private

def political?
content_store_hash["details"].include?("political") && content_store_hash.dig("details", "political")
end

def historical?
government_current = content_store_hash.dig(
"links", "government", 0, "details", "current"
)

# Treat no government as not historical
return false if government_current.nil?

!government_current
end
end
40 changes: 40 additions & 0 deletions app/models/concerns/updatable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Updatable
extend ActiveSupport::Concern

included do
def updated
public_updated_at if any_updates?
end

def history
return [] unless any_updates?

reverse_chronological_change_history
end
end

private

def any_updates?
if public_updated_at && first_public_at
Time.zone.parse(public_updated_at) != Time.zone.parse(first_public_at)
else
false
end
end

def reverse_chronological_change_history
change_history.sort_by { |item| Time.zone.parse(item[:timestamp]) }.reverse
end

def change_history
changes = content_store_hash.dig("details", "change_history") || []
changes.map do |item|
{
display_time: item["public_timestamp"],
note: item["note"],
timestamp: item["public_timestamp"],
}
end
end
end
8 changes: 8 additions & 0 deletions app/models/concerns/withdrawable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ module Withdrawable
def withdrawn?
withdrawal_notice.present?
end

def withdrawn_at
withdrawal_notice["withdrawn_at"]
end

def withdrawn_explanation
withdrawal_notice["explanation"]
end
end

private
Expand Down
9 changes: 6 additions & 3 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

class ContentItem
include Withdrawable
include Organisations

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

# SCAFFOLDING: remove the override_content_store_hash parameter when full landing page
# content items including block details are available from content-store
Expand All @@ -24,6 +25,8 @@ def initialize(content_store_response, override_content_store_hash: nil)
@public_updated_at = content_store_hash["public_updated_at"]
@links = content_store_hash["links"]
@phase = content_store_hash["phase"]
@first_published_at = content_store_hash["first_published_at"]
@first_public_at = content_store_hash.dig("details", "first_public_at")

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

Expand Down
20 changes: 20 additions & 0 deletions app/models/speech.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Speech < ContentItem
include Organisations
include Political
include Updatable
include NewsImage

def related_entities
entities = linkable_organisations + (speaker || [])
entities += [speaker_without_profile] if speaker_without_profile
entities.uniq
end

def speaker
content_store_hash.dig("links", "speaker")
end

def speaker_without_profile
content_store_hash.dig("details", "speaker_without_profile")
end
end
Loading
Loading