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

Detailed guides migration #134

Merged
merged 13 commits into from
Apr 20, 2016
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
@import "views/topical-event-about-page";
@import "views/unpublishing";
@import "views/working-group";
@import "views/detailed-guide";
8 changes: 8 additions & 0 deletions app/assets/stylesheets/views/_detailed-guide.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.detailed-guide {
@include description;
@include sidebar-with-body;

.offset-one-third {
margin-left: percentage(1 / 3);
}
}
57 changes: 5 additions & 52 deletions app/presenters/case_study_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CaseStudyPresenter < ContentItemPresenter
include ActionView::Helpers::UrlHelper
include CommonSections

attr_reader :body, :format_display_type

Expand All @@ -9,41 +10,6 @@ def initialize(content_item)
@format_display_type = content_item["details"]["format_display_type"]
end

def from
links("lead_organisations") + links("supporting_organisations") + links("worldwide_organisations")
end

def part_of
links("document_collections") + links("related_policies") + links("worldwide_priorities") + links("world_locations")
end

def history
return [] unless any_updates?
content_item["details"]["change_history"].map do |item|
{
display_time: display_time(item["public_timestamp"]),
note: item["note"],
timestamp: item["public_timestamp"]
}
end
end

def published
display_time(content_item["details"]["first_public_at"])
end

def updated
display_time(content_item["public_updated_at"]) if any_updates?
end

def short_history
if any_updates?
"#{I18n.t('content_item.metadata.updated')} #{updated}"
else
"#{I18n.t('content_item.metadata.published')} #{published}"
end
end

def image
content_item["details"]["image"]
end
Expand All @@ -56,6 +22,10 @@ def page_title
withdrawn? ? "[Withdrawn] #{title}" : title
end

def part_of
links("document_collections") + links("related_policies") + links("worldwide_priorities") + links("world_locations")
end

def withdrawal_notice
notice = content_item["details"]["withdrawn_notice"]
if notice
Expand All @@ -65,21 +35,4 @@ def withdrawal_notice
}
end
end

private

def any_updates?
if (first_public_at = content_item["details"]["first_public_at"]).present?
DateTime.parse(content_item["public_updated_at"]) != DateTime.parse(first_public_at)
else
false
end
end

def links(type)
return [] unless content_item["links"][type]
content_item["links"][type].map do |link|
link_to(link["title"], link["base_path"])
end
end
end
49 changes: 49 additions & 0 deletions app/presenters/common_sections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module CommonSections
def from
links("lead_organisations") + links("supporting_organisations") + links("worldwide_organisations")
end

def published
display_time(content_item["details"]["first_public_at"])
end

def updated
display_time(content_item["public_updated_at"]) if any_updates?
end

def short_history
if any_updates?
"#{I18n.t('content_item.metadata.updated')} #{updated}"
else
"#{I18n.t('content_item.metadata.published')} #{published}"
end
end

def history
return [] unless any_updates?
content_item["details"]["change_history"].map do |item|
{
display_time: display_time(item["public_timestamp"]),
note: item["note"],
timestamp: item["public_timestamp"]
}
end
end

private

def any_updates?
if (first_public_at = content_item["details"]["first_public_at"]).present?
DateTime.parse(content_item["public_updated_at"]) != DateTime.parse(first_public_at)
else
false
end
end

def links(type)
return [] unless content_item["links"][type]
content_item["links"][type].map do |link|
link_to(link["title"], link["base_path"])
end
end
end
42 changes: 42 additions & 0 deletions app/presenters/detailed_guide_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class DetailedGuidePresenter < ContentItemPresenter
include ExtractsHeadings
include ActionView::Helpers::UrlHelper
include CommonSections

def body
content_item["details"]["body"]
end

def breadcrumbs
e = parent
res = []

while e
res << { title: e["title"], url: e["base_path"] }
e = e["parent"] && e["parent"].first
end

res << { title: "Home", url: "/" }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually adding the "Home" link as this is not present in the parent hierarchy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot 👍

res.reverse
end

def contents
extract_headings_with_ids(body).map do |heading|
link_to(heading[:text], "##{heading[:id]}")
end
end

def context
parent["title"]
end

def part_of
links("document_collections") + links("related_policies") + links("worldwide_priorities") + links("world_locations") + links("topics")
end

private

def parent
content_item["links"]["parent"][0]
end
end
48 changes: 48 additions & 0 deletions app/views/content_items/detailed_guide.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= content_for :page_class, @content_item.format.dasherize %>
<%= content_for :title, @content_item.title %>

<%= render 'govuk_component/breadcrumbs', breadcrumbs: @content_item.breadcrumbs %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title',
context: t("content_item.format.#{@content_item.format}", count: 1),
title: @content_item.title %>
</div>
</div>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/metadata',
from: @content_item.from,
other: {
"First published" => @content_item.published,
"Last updated" => [@content_item.updated,"<a href=\"#history\">see all updates</a>"].join(", "),
"Part of" => @content_item.part_of #doing this to preserve the ordering but if part_of, at the same level as from and other
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the ordering needs to be preserved.

}
%>
</div>
</div>

<%= render 'shared/description', description: @content_item.description %>

<div class="grid-row sidebar-with-body">
<% if @content_item.contents.any? %>
<div class="column-third">
<%= render 'shared/sidebar_contents', contents: @content_item.contents %>
</div>
<% end %>
<div class="column-two-thirds <% unless @content_item.contents.any? %>offset-one-third<% end %>">
<%= render 'govuk_component/govspeak',
content: @content_item.body,
direction: page_text_direction %>
</div>
</div>

<%= render 'govuk_component/document_footer',
from: @content_item.from,
updated: @content_item.updated,
history: @content_item.history,
published: @content_item.published,
direction: page_text_direction
%>
2 changes: 1 addition & 1 deletion config/locales/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ar:
few:
many:
other:
detailed_guidance:
detailed_guide:
zero:
one: "توجيه مفصل"
two:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/az.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ az:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: "ətraflı məlumat"
other: "ətraflı məlumat"
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ be:
few:
many:
other:
detailed_guidance:
detailed_guide:
one: "Падрабязнае кіраўніцтва"
few:
many:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bg:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: "Подробна насока"
other: "Подробни насоки"
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/bn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bn:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one:
other:
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cs:
one:
few:
other:
detailed_guidance:
detailed_guide:
one: Podrobný návod
few:
other: Podrobný návod
Expand Down
2 changes: 1 addition & 1 deletion config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cy:
few:
many:
other:
detailed_guidance:
detailed_guide:
zero:
one: Cyfarwyddyd manwl
two:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ de:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: Detaillierte Hinweise
other: Detaillierte Hinweise
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/dr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dr:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: " رهنمود مفصل"
other: "رهنمود های مفصل"
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/el.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ el:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: "Οδηγίες"
other: "Οδηγίες"
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ en:
correspondence:
one: Correspondence
other: Correspondences
detailed_guidance:
detailed_guide:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably all the other language keys also need updating?

Copy link
Author

@mgrassotti mgrassotti Apr 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I quickly substituted them, we can go back eventually. In Whitehall I found both terms used, although "detailed_guide" seems to be used more.

one: Guidance
other: Guidance
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es-419.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ es-419:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: Orientación detallada
other: Orientación detallada
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ es:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: Orientación detallada
other: Orientación detallada
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/et.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ et:
decision:
one: Otsus
other: Otsused
detailed_guidance:
detailed_guide:
one: Juhend
other: Juhendid
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fa:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: "راهنمای تفصیلی"
other: "راهنمای تفصیلی"
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fr:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: Instructions détaillées
other: Instructions détaillées
document_collection:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ he:
two:
many:
other:
detailed_guidance:
detailed_guide:
one: "מדריך מפורט"
two:
many:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/hi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ hi:
decision:
one:
other:
detailed_guidance:
detailed_guide:
one: "विस्तृत मार्गदर्शन"
other: "विस्तृत मार्गदर्शन"
document_collection:
Expand Down
Loading