|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module SimpleNavigationBootstrap |
| 4 | + class RenderedItem5 < RenderedItem |
| 5 | + private |
| 6 | + |
| 7 | + def li_link # rubocop:disable Metrics/AbcSize, Metrics/MethodLength |
| 8 | + if include_sub_navigation?(item) |
| 9 | + if level == 1 |
| 10 | + if split |
| 11 | + splitted_simple_part + splitted_dropdown_part |
| 12 | + else |
| 13 | + content = [item.name] |
| 14 | + content << caret unless skip_caret |
| 15 | + content = content.join(" ").html_safe |
| 16 | + dropdown_part(content) |
| 17 | + end |
| 18 | + else |
| 19 | + content_tag(:li, dropdown_submenu_link, options) |
| 20 | + end |
| 21 | + else |
| 22 | + options[:class] = [options[:class], "nav-item"].flatten.compact.join( |
| 23 | + " " |
| 24 | + ) if level == 1 |
| 25 | + content_tag(:li, simple_link, options) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + def dropdown_part(name) # rubocop:disable Metrics/AbcSize |
| 30 | + options[:class] = [options[:class], "nav-item", "dropdown"].flatten |
| 31 | + .compact |
| 32 | + .join(" ") |
| 33 | + link_options[:class] = [ |
| 34 | + link_options[:class], |
| 35 | + "nav-link", |
| 36 | + "dropdown-toggle" |
| 37 | + ].flatten.compact.join(" ") |
| 38 | + link_options[:"role"] = "button" |
| 39 | + link_options[:"data-bs-toggle"] = "dropdown" |
| 40 | + link_options[:"aria-expanded"] = "false" |
| 41 | + |
| 42 | + content = |
| 43 | + link_to(name, "#", link_options) + render_sub_navigation_for(item) |
| 44 | + content_tag(:li, content, options) |
| 45 | + end |
| 46 | + |
| 47 | + def simple_link |
| 48 | + link_class = level == 1 ? "nav-link" : "dropdown-item" |
| 49 | + link_options[:class] = [options[:class], link_class].flatten.compact.join(" ") |
| 50 | + link_options[:method] ||= item.method |
| 51 | + url = item.url || "#" |
| 52 | + link_to(item.name, url, link_options) |
| 53 | + end |
| 54 | + end |
| 55 | +end |
0 commit comments