module StructuredMenus::Adapters
class DashboardAdapter
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::OutputSafetyHelper
# Accepted options:
#
# :if - only include this menu item if the provided block returns true when passed the current user (if not present, item is always included)
# :width - the number of cards to include in one row of the menu (max 12, default 4)
# :class - the CSS class to apply to each card's wrapper
(default dashboard-menu-card)
#
# You still need to provide your own styles for .dashboard-menu-card.
def self.show(menu, user, **options)
inst = new
width = options[:width] || 4
cards = menu.map do |i|
next unless !i['if'] || instance_eval(i['if']).call(user)
cls = options[:class] || 'dashboard-menu-card'
inst.raw("
#{inst.link_to inst.raw(" #{i['name']}"), i['link']}
")
end.compact
inst.raw(cards.in_groups_of(12 / width).map(&:compact).map do |g|
'
' + g.map { |c| "
#{c}
" }.join("\n") + '
'
end.join("\n"))
end
end
end