Skip to content

Commit 82eec44

Browse files
feat: bootstrap5 support
1 parent 26fdb54 commit 82eec44

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

lib/simple_navigation_bootstrap/bootstrap5.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ def navigation_class
1919
end
2020

2121

22-
# def container_class(_level)
23-
# remove_navigation_class = options.fetch(:remove_navigation_class, false)
24-
# remove_navigation_class ? '' : ['nav', navigation_class].compact
25-
# end
22+
def render_item(*)
23+
SimpleNavigationBootstrap::RenderedItem5.new(*).to_s
24+
end
2625

2726
end
2827
end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)