Skip to content

Commit

Permalink
Revert "Simplify document list component markup when having only one …
Browse files Browse the repository at this point in the history
…item"
  • Loading branch information
alex-ju committed Dec 23, 2019
1 parent ceb8be7 commit 30a1d5c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@

.gem-c-document-list__item-metadata {
padding: 0;
margin: 0;
@include govuk-font(19);
}

.gem-c-document-list__attribute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,73 @@

within_multitype_list ||= false
within_multitype_list_class = " gem-c-document-list__multi-list" if within_multitype_list
title_with_context_class = " gem-c-document-list__item-title--context"

brand ||= false
brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)
%>
<% def document(item, brand_helper) %>
<% title_with_context_class = " gem-c-document-list__item-title--context" %>
<% if item[:highlight] && item[:highlight_text] %>
<p class='gem-c-document-list__highlight-text'><%= item[:highlight_text] %></p>
<% end %>
<%=
item_classes = "gem-c-document-list__item-title #{brand_helper.color_class} #{title_with_context_class if item[:link][:context]}"

if item[:link][:path]
link_to(
item[:link][:text],
item[:link][:path],
data: item[:link][:data_attributes],
class: "#{item_classes} gem-c-document-list__item-link",
)
else
content_tag(
"span",
item[:link][:text],
data: item[:link][:data_attributes],
class: item_classes,
)
end
%>
<% if item[:link][:context] %>
<span class="gem-c-document-list__item-context"><%= item[:link][:context] %></span>
<% end %>
<% if item[:link][:description] %>
<p class="gem-c-document-list__item-description" ><%= item[:link][:description] %></p>
<% end %>
<% if item[:metadata] %>
<ul class="gem-c-document-list__item-metadata">
<% item[:metadata].compact.each do |item_metadata_key, item_metadata_value| %>
<li class="gem-c-document-list__attribute">
<% if item_metadata_key.to_s.eql?("public_updated_at") %>
<time datetime="<%= item_metadata_value.iso8601 %>">
<%= l(item_metadata_value, format: '%e %B %Y') %>
</time>
<% else %>
<%= item_metadata_value %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
<% if item[:subtext] %>
<p class="gem-c-document-list__subtext"><%= item[:subtext] %></p>
<% end %>
<% end %>
<% if items.any? %>
<% unless within_multitype_list || items.one? %>
<% unless within_multitype_list %>
<ol class="<%= classes %>">
<% end %>
<% items.each do |item| %>
<% highlight_class = " gem-c-document-list__item--highlight" if item[:highlight] %>

<% if items.one? %>
<% document(item, brand_helper) %>
<% else %>
<li class="gem-c-document-list__item<%= within_multitype_list_class %> <%= brand_helper.brand_class %> <%= highlight_class %>">
<% document(item, brand_helper) %>
</li>
<% end %>
<li class="gem-c-document-list__item<%= within_multitype_list_class %> <%= brand_helper.brand_class %> <%= highlight_class %>">
<% if item[:highlight] && item[:highlight_text] %>
<p class='gem-c-document-list__highlight-text'><%= item[:highlight_text] %></p>
<% end %>

<%=
item_classes = "gem-c-document-list__item-title #{brand_helper.color_class} #{title_with_context_class if item[:link][:context]}"

if item[:link][:path]
link_to(
item[:link][:text],
item[:link][:path],
data: item[:link][:data_attributes],
class: "#{item_classes} gem-c-document-list__item-link",
)
else
content_tag(
"span",
item[:link][:text],
data: item[:link][:data_attributes],
class: item_classes,
)
end
%>

<% if item[:link][:context] %>
<span class="gem-c-document-list__item-context"><%= item[:link][:context] %></span>
<% end %>

<% if item[:link][:description] %>
<p class="gem-c-document-list__item-description" ><%= item[:link][:description] %></p>
<% end %>

<% if item[:metadata] %>
<ul class="gem-c-document-list__item-metadata">
<% item[:metadata].compact.each do |item_metadata_key, item_metadata_value| %>
<li class="gem-c-document-list__attribute">
<% if item_metadata_key.to_s.eql?("public_updated_at") %>
<time datetime="<%= item_metadata_value.iso8601 %>">
<%= l(item_metadata_value, format: '%e %B %Y') %>
</time>
<% else %>
<%= item_metadata_value %>
<% end %>
</li>
<% end %>
</ul>
<% end %>

<% if item[:subtext] %>
<p class="gem-c-document-list__subtext"><%= item[:subtext] %></p>
<% end %>
</li>
<% end %>
<% unless within_multitype_list || items.one? %>
<% unless within_multitype_list %>
</ol>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,3 @@ examples:
document_type: 'Organisation'
context:
right_to_left: true
with_a_single_item:
data:
items:
- link:
text: 'Alternative provision'
path: '/government/publications/alternative-provision'
metadata:
public_updated_at: 2016-06-27 10:29:44
document_type: 'Statutory guidance'
32 changes: 0 additions & 32 deletions spec/components/document_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ def component_name
public_updated_at: Time.zone.parse("2017-01-05 14:50:33 +0000"),
document_type: "Statutory guidance"
}
},
{
link: {
text: "Become an apprentice",
path: "/become-an-apprentice",
},
metadata: {
public_updated_at: Time.zone.parse("2017-07-19 15:01:48 +0000"),
document_type: "Statutory guidance"
}
}
]
)
Expand Down Expand Up @@ -199,16 +189,6 @@ def component_name
public_updated_at: Time.zone.parse("2017-01-05 14:50:33 +0000"),
document_type: "Statutory guidance"
}
},
{
link: {
text: "Become an apprentice",
path: "/become-an-apprentice",
},
metadata: {
public_updated_at: Time.zone.parse("2017-07-19 15:01:48 +0000"),
document_type: "Statutory guidance"
}
}
]
)
Expand All @@ -220,12 +200,6 @@ def component_name
it "does not wrap link in heading element if no description or metadata provided" do
render_component(
items: [
{
link: {
text: "Link Title",
path: "/link/path",
}
},
{
link: {
text: "Link Title",
Expand Down Expand Up @@ -276,12 +250,6 @@ def component_name
render_component(
remove_underline: true,
items: [
{
link: {
text: "Link Title",
path: "/link/path",
}
},
{
link: {
text: "Link Title",
Expand Down

0 comments on commit 30a1d5c

Please sign in to comment.