-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
341 Refactor in preparation for adding topic breadcrumbs
Rename ContentBreadcrumbsBasedOnParent to ContentBreadcrumbsBasedOnAncestors to clarify when working directly with parent and when with a group of parents in context navigation. Also removed breadcrumb outer hash as redundant. Separated finder_breadcrumbs from default breadcrumbs to simplify logic
- Loading branch information
Showing
7 changed files
with
59 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
# @private | ||
class ContentBreadcrumbsBasedOnAncestors | ||
def initialize(content_item) | ||
@content_item = ContentItem.new(content_item) | ||
end | ||
|
||
def breadcrumbs | ||
ordered_ancestors = all_ancestors.map do |ancestor| | ||
{ title: ancestor.title, url: ancestor.base_path } | ||
end | ||
|
||
ordered_ancestors << { title: "Home", url: "/" } | ||
ordered_ancestors.reverse! | ||
ordered_ancestors | ||
end | ||
|
||
private | ||
|
||
attr_reader :content_item | ||
|
||
def all_ancestors | ||
ancestors = [] | ||
|
||
parent = content_item.parent | ||
while parent | ||
ancestors << parent | ||
|
||
parent = parent.parent | ||
end | ||
|
||
ancestors | ||
end | ||
end | ||
end | ||
end |
39 changes: 0 additions & 39 deletions
39
lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_parent.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters