Class: StructuredMenus::Adapters::DashboardAdapter
- Inherits:
-
Object
- Object
- StructuredMenus::Adapters::DashboardAdapter
- Includes:
- ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/structured_menus/adapters/dashboard_adapter.rb
Class Method Summary collapse
-
.show(menu, user, **options) ⇒ Object
Accepted options:.
Class Method Details
.show(menu, user, **options) ⇒ Object
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 <div> (default dashboard-menu-card)
You still need to provide your own styles for .dashboard-menu-card.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/structured_menus/adapters/dashboard_adapter.rb', line 13 def self.show(, user, **) inst = new width = [:width] || 4 cards = .map do |i| next unless !i['if'] || instance_eval(i['if']).call(user) cls = [:class] || 'dashboard-menu-card' inst.raw("<div class=\"#{cls}\">#{inst.link_to inst.raw("<i class=\"fas fa-#{i['icon']}\"></i> #{i['name']}"), i['link']}</div>") end.compact inst.raw(cards.in_groups_of(width).map(&:compact).map do |g| '<div class="row">' + g.map { |c| "<div class=\"col-md-#{12 / width}\">#{c}</div>" }.join("\n") + '</div>' end.join("\n")) end |