Skip to content

Commit 5bbacc0

Browse files
committed
Do not emit an empty ol tag when there are no breadcrumbs
1 parent 2fcfe48 commit 5bbacc0

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

app/components/arclight/breadcrumb_component.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ def initialize(document:, count: nil, offset: 0)
1212
end
1313

1414
def call
15-
breadcrumb_links = components.drop(@offset)
15+
return unless breadcrumb_links.any?
1616

17-
if @count && breadcrumb_links.length > @count
18-
breadcrumb_links = breadcrumb_links.first(@count)
19-
breadcrumb_links << tag.li('&hellip;'.html_safe, class: 'breadcrumb-item')
20-
end
2117
tag.ol class: 'breadcrumb' do
2218
safe_join(breadcrumb_links)
2319
end
@@ -36,5 +32,19 @@ def components
3632
def build_repository_link
3733
render Arclight::RepositoryBreadcrumbComponent.new(document: @document)
3834
end
35+
36+
private
37+
38+
def breadcrumb_links
39+
@breadcrumb_links ||= limit_breadcrumb_links(components.drop(@offset))
40+
end
41+
42+
def limit_breadcrumb_links(links)
43+
return links unless @count && links.length > @count
44+
45+
limited_links = links.first(@count)
46+
limited_links << tag.li('&hellip;'.html_safe, class: 'breadcrumb-item')
47+
limited_links
48+
end
3949
end
4050
end

spec/components/arclight/breadcrumb_component_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
end
5252
end
5353

54+
context 'with an offset that removes all links' do
55+
let(:attr) { { offset: 4 } }
56+
57+
it 'does not render an empty ordered list' do
58+
expect(rendered).to have_no_selector 'ol'
59+
end
60+
end
61+
5462
it 'renders breadcrumb links' do
5563
expect(rendered).to have_css 'li', text: 'my repository'
5664
expect(rendered).to have_link 'DEF', href: '/catalog/abc123_def'

0 commit comments

Comments
 (0)