Module: Recourse::Helpers::Navigation
- Included in:
- Recourse::Helpers
- Defined in:
- lib/recourse/helpers/navigation.rb
Overview
Helpers for the navbar and the sidebar.
Instance Method Summary collapse
-
#current_resource?(name) ⇒ Boolean
True when a sidebar entry names the resource the page is showing.
-
#edit_resource_link(record) ⇒ Object
Pencil linking to a record's edit page, or nothing when there is not one.
-
#new_resource_path ⇒ Object
Path to this resource's new page, or nil when there is not one to link to.
-
#resource_breadcrumbs ⇒ Object
Trail to the current page as [title, path] pairs; a nil path is this page.
-
#resource_label(title) ⇒ Object
Label for a link to a resource: its icon, then its title.
-
#sidebar_resources ⇒ Object
Sidebar entries as [name, title, path], in the order routes.rb declares them.
Instance Method Details
#current_resource?(name) ⇒ Boolean
True when a sidebar entry names the resource the page is showing.
46 47 48 |
# File 'lib/recourse/helpers/navigation.rb', line 46 def current_resource?(name) name == controller.controller_name end |
#edit_resource_link(record) ⇒ Object
Pencil linking to a record's edit page, or nothing when there is not one.
14 15 16 17 18 19 |
# File 'lib/recourse/helpers/navigation.rb', line 14 def edit_resource_link(record) path = edit_resource_path record return unless path link_to tag.i(class: 'bi bi-pencil-square'), path, aria: { label: 'Edit' } end |
#new_resource_path ⇒ Object
Path to this resource's new page, or nil when there is not one to link to.
22 23 24 25 26 27 |
# File 'lib/recourse/helpers/navigation.rb', line 22 def new_resource_path return unless controller.class.action_methods.include? 'new' return unless routed? controller.controller_path, 'new' url_for action: :new end |
#resource_breadcrumbs ⇒ Object
Trail to the current page as [title, path] pairs; a nil path is this page.
6 7 8 9 10 11 |
# File 'lib/recourse/helpers/navigation.rb', line 6 def leaf = return [[resources_name, nil]] unless leaf [[resources_name, url_for(action: :index)], [leaf, nil]] end |
#resource_label(title) ⇒ Object
Label for a link to a resource: its icon, then its title.
30 31 32 33 34 |
# File 'lib/recourse/helpers/navigation.rb', line 30 def resource_label(title) icon = NAVIGATION_ICONS.fetch title, FALLBACK_ICON safe_join [tag.i(class: "bi bi-#{icon}"), title], ' ' end |
#sidebar_resources ⇒ Object
Sidebar entries as [name, title, path], in the order routes.rb declares them.
37 38 39 40 41 42 43 |
# File 'lib/recourse/helpers/navigation.rb', line 37 def Recourse.declared.filter_map do |name| next unless routed? name, 'index' [name, name.humanize, url_for(controller: "/#{name}", action: :index)] end end |