1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/helpers/navs_helper.rb

86 lines
2.3 KiB
Ruby
Raw Normal View History

2019-08-15 03:19:28 -04:00
# frozen_string_literal: true
module NavsHelper
NAV_TABS_LIST_HTML_CLASS = {
tabs: 'nav nav-tabs d-none d-sm-flex',
pills: 'nav nav-pills d-flex d-sm-none flex-column',
}.freeze
2019-08-15 03:57:17 -04:00
def nav_breadcrumb(*args, active_text)
tag.nav 'aria-label': 'breadcrumb' do
tag.ol class: 'breadcrumb' do
args.each do |(text, url)|
concat nav_breadcrumb_item text, url
end
concat nav_breadcrumb_item active_text
end
end
end
def nav_breadcrumb_item(text, url = nil)
if url
tag.li class: 'breadcrumb-item' do
link_to text, url
end
else
tag.li class: 'breadcrumb-item active', 'aria-current': 'page' do
text
end
end
end
2019-08-15 03:32:34 -04:00
def nav_tabs(scope_name, active_tab_name, options)
2019-08-15 03:19:28 -04:00
capture do
2019-08-15 03:32:34 -04:00
concat nav_tabs_list scope_name, active_tab_name, :tabs, options
concat nav_tabs_list scope_name, active_tab_name, :pills, options
2019-08-15 03:19:28 -04:00
end
end
2019-08-15 03:32:34 -04:00
def nav_sidebar(scope_name, active_tab_name, options)
2019-08-15 03:19:28 -04:00
tag.div class: 'list-group' do
options.each do |(k, v)|
2019-08-15 03:32:34 -04:00
concat nav_sidebar_item scope_name, active_tab_name, k, *v
2019-08-15 03:19:28 -04:00
end
end
end
2019-08-15 03:32:34 -04:00
def nav_tabs_list(scope_name, active_tab_name, format, options)
2019-08-15 03:19:28 -04:00
tag.ul class: NAV_TABS_LIST_HTML_CLASS[format] do
options.each do |(k, v)|
2019-08-15 03:32:34 -04:00
concat nav_tabs_item scope_name, active_tab_name, k, *v
2019-08-15 03:19:28 -04:00
end
end
end
2019-08-15 03:32:34 -04:00
def nav_tabs_item(scope_name, active_tab_name, tab_name, policy, url)
2019-08-15 03:19:28 -04:00
tag.li class: 'nav-item' do
2019-08-15 03:31:31 -04:00
link_to translate(tab_name, scope: [:nav_tabs, scope_name]),
url,
2019-08-15 03:32:34 -04:00
nav_tab_link_options(policy, tab_name == active_tab_name)
2019-08-15 03:19:28 -04:00
end
end
2019-08-15 03:32:34 -04:00
def nav_sidebar_item(scope_name, active_tab_name, tab_name, policy, url)
2019-08-15 03:31:31 -04:00
link_to translate(tab_name, scope: [:nav_tabs, scope_name]),
url,
2019-08-15 03:32:34 -04:00
nav_sidebar_link_options(policy, tab_name == active_tab_name)
2019-08-15 03:31:31 -04:00
end
def nav_tab_link_options(policy, active)
2019-08-15 03:19:28 -04:00
if policy
2019-08-15 03:31:31 -04:00
{ class: "nav-link #{:active if active}" }
2019-08-15 03:19:28 -04:00
else
2019-08-15 03:31:31 -04:00
{ class: 'nav-link disabled', tabindex: -1, 'aria-disabled': true }
end
end
def nav_sidebar_link_options(policy, active)
if policy
{ class: "list-group-item list-group-item-action #{:active if active}" }
else
{ class: 'list-group-item list-group-item-action disabled',
'aria-disabled': true }
2019-08-15 03:19:28 -04:00
end
end
end