Skip to content

Instantly share code, notes, and snippets.

@MyklClason
Last active July 29, 2022 04:59
Show Gist options
  • Save MyklClason/2e10887c8b89d089affe60526fbb7c33 to your computer and use it in GitHub Desktop.
Save MyklClason/2e10887c8b89d089affe60526fbb7c33 to your computer and use it in GitHub Desktop.
Bootstrap Nav Helper (Bootstrap 4/5)
module BootstrapNavHelper
def navbar_text(nav_text)
content_tag :span, class: "navbar_text" do
nav_text
end
end
def navbar_link_to(nav_text, nav_path, link_options = {})
is_active = current_page?(nav_path)
link_options[:class] = "#{link_options[:class]} nav-link"
content_tag :li, class: "nav-item #{"active" if is_active}" do
link_to nav_text, nav_path, **link_options
end
end
def navbar_brand_link_to(nav_text, nav_path=nil, link_options = {})
nav_path ||= root_path
link_options[:class] = "#{link_options[:class]} navbar-brand"
link_to nav_text, nav_path, **link_options
end
def navbar_dropdown_link_to(nav_text, nav_path, link_options = {})
is_active = current_page?(nav_path)
link_options[:class] = "#{link_options[:class]} dropdown-item #{"active" if is_active}"
content_tag :li, class: "#{"active" if is_active}" do
link_to nav_text, nav_path, **link_options
end
end
def navbar_dropdown_seperator()
content_tag :li do
tag.hr class: "dropdown-divider"
end
end
def nav_link_to(nav_text, nav_path, link_options = {})
is_active = current_page?(nav_path)
link_options[:class] = "#{link_options[:class]} nav-link #{"active" if is_active}"
content_tag :li, class: "nav-item" do
link_to nav_text, nav_path, **link_options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment