diff --git a/app/components/concerns/sdg/tag_list.rb b/app/components/concerns/sdg/tag_list.rb index a27225370..355005408 100644 --- a/app/components/concerns/sdg/tag_list.rb +++ b/app/components/concerns/sdg/tag_list.rb @@ -16,11 +16,10 @@ module SDG::TagList count = count_out_of_limit(collection) if count > 0 - [ - "#{count}+", - polymorphic_path(record), - class: "more-#{i18n_namespace}", title: t("sdg.#{i18n_namespace}.filter.more", count: count) - ] + link_to "#{count}+", + polymorphic_path(record), + class: "more-#{i18n_namespace}", + title: t("sdg.#{i18n_namespace}.filter.more", count: count) end end diff --git a/app/components/sdg/goals/plain_tag_list_component.rb b/app/components/sdg/goals/plain_tag_list_component.rb index 8b60b692b..bb1bb6d0a 100644 --- a/app/components/sdg/goals/plain_tag_list_component.rb +++ b/app/components/sdg/goals/plain_tag_list_component.rb @@ -8,13 +8,7 @@ class SDG::Goals::PlainTagListComponent < ApplicationComponent end def tags - [*goal_tags, see_more_link].compact - end - - def see_more_link - options = super(goals) - - link_to(*options) if options.present? + [*goal_tags, see_more_link(goals)].compact end def goal_tags diff --git a/app/components/sdg/targets/plain_tag_list_component.rb b/app/components/sdg/targets/plain_tag_list_component.rb index b24792cb2..73d73ed2a 100644 --- a/app/components/sdg/targets/plain_tag_list_component.rb +++ b/app/components/sdg/targets/plain_tag_list_component.rb @@ -8,13 +8,7 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent end def tags - [*target_tags, see_more_link].compact - end - - def see_more_link - options = super(targets) - - link_to(*options) if options.present? + [*target_tags, see_more_link(targets)].compact end def target_tags diff --git a/app/helpers/link_list_helper.rb b/app/helpers/link_list_helper.rb index f3e00d1bb..5af374fae 100644 --- a/app/helpers/link_list_helper.rb +++ b/app/helpers/link_list_helper.rb @@ -1,11 +1,15 @@ module LinkListHelper def link_list(*links, **options) - return "" if links.compact.empty? + return "" if links.select(&:present?).empty? tag.ul(options) do - safe_join(links.compact.map do |text, url, current = false, **link_options| + safe_join(links.select(&:present?).map do |text, url, current = false, **link_options| tag.li(({ "aria-current": true } if current)) do - link_to text, url, link_options + if url + link_to text, url, link_options + else + text + end end end, "\n") end diff --git a/spec/helpers/link_list_helper_spec.rb b/spec/helpers/link_list_helper_spec.rb index 31ff73768..7626d0198 100644 --- a/spec/helpers/link_list_helper_spec.rb +++ b/spec/helpers/link_list_helper_spec.rb @@ -19,6 +19,15 @@ describe LinkListHelper do expect(list).to be_html_safe end + it "accepts anchor tags" do + list = helper.link_list(link_to("Home", "/"), ["Info", "/info"], class: "menu") + + expect(list).to eq '' + expect(list).to be_html_safe + end + it "accepts options for links" do render helper.link_list(["Home", "/", class: "root"], ["Info", "/info", id: "info"]) @@ -30,7 +39,15 @@ describe LinkListHelper do it "ignores nil entries" do render helper.link_list(["Home", "/", class: "root"], nil, ["Info", "/info", id: "info"]) - expect(page).to have_css "a", count: 2 + expect(page).to have_css "li", count: 2 + expect(page).to have_css "a.root", count: 1, exact_text: "Home" + expect(page).to have_css "a#info", count: 1, exact_text: "Info" + end + + it "ignores empty entries" do + render helper.link_list(["Home", "/", class: "root"], "", ["Info", "/info", id: "info"]) + + expect(page).to have_css "li", count: 2 expect(page).to have_css "a.root", count: 1, exact_text: "Home" expect(page).to have_css "a#info", count: 1, exact_text: "Info" end