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.
This commit is contained in:
13
app/helpers/link_list_helper.rb
Normal file
13
app/helpers/link_list_helper.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
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
|
||||
Reference in New Issue
Block a user