diff --git a/lib/sigbit_admin_rails/helpers/sidebar_helper.rb b/lib/sigbit_admin_rails/helpers/sidebar_helper.rb index 5cdac84..53ad24b 100644 --- a/lib/sigbit_admin_rails/helpers/sidebar_helper.rb +++ b/lib/sigbit_admin_rails/helpers/sidebar_helper.rb @@ -4,26 +4,45 @@ def sidebar(*args, &block) options = args.extract_options! if block_given? content_tag :div, id: 'sidebar-wrapper' do - html = link_to '', options[:brand_url], class: 'sidebar-brand hidden-sm-down' - html << content_tag(:ul, class: 'sidebar-nav') do + concat(link_to '', options[:brand_url], class: 'sidebar-brand hidden-sm-down') + concat(content_tag(:ul, class: 'sidebar-nav') do yield - end - html.html_safe + end) end end end - def sidebar_item(title, url, &block) + def sidebar_item(title, url = nil, &block) if block_given? + url = "##{generate_random_id}" unless url.present? content_tag :li do - html = link_to("#{title} ".html_safe, url, data: { toggle: 'collapse' }) - html << content_tag(:ul, class: 'submenu collapse', id: url.delete('#')) do + concat(link_to("#{ title } #{ arrow_icon }".html_safe, url, data: { toggle: 'collapse' })) + concat(content_tag(:ul, class: 'submenu collapse', id: url.delete('#')) do yield - end - html.html_safe + end) end else - "
  • #{link_to title, url}
  • ".html_safe + smart_link_to title, url, class: 'nav-link' end - end end + end + + def smart_link_to(title, url, options = {}) + content_tag :li, class: 'nav-item' do + if defined?(ActiveLinkTo) + active_link_to(title, url, options) + else + link_to title, url, options + end + end + end + + def arrow_icon + content_tag :i, class: 'fa fa-chevron-right' do + end + end + + def generate_random_id + (0...20).map { ('a'..'z').to_a.sample }.join + end + end end