Files
grecia/app/helpers/link_list_helper.rb
Javi Martín c156621a4c Add method to generate a list of links
A list of links is a very common pattern in the web, and we use it in
many places. Here we're applying it to one of the most simple ones; the
help page.

Generally speaking, I'm not a big fan of helpers, but there are methods
which IMHO qualify as helpers when:

* They do not deal with application objects but mainly strings and
  arrays
* They return text or an HTML tag
* Their logic is simple and splitting it into several methods is not
  necessary

Many Rails helpers, like `tag`, follow these principles.
2020-12-07 15:28:56 +01:00

14 lines
285 B
Ruby

module LinkListHelper
def link_list(*links, **options)
return "" if links.compact.empty?
tag.ul(options) do
safe_join(links.compact.map do |text, url, **link_options|
tag.li do
link_to text, url, link_options
end
end)
end
end
end