Module: Bootstrap::NavHelper
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/helpers/bootstrap/nav_helper.rb
Overview
Rails view helpers for various Bootstrap navigation components.
Instance Method Summary collapse
-
#brand(text, options = {}) ⇒ String
Returns a Bootstrap brand element.
-
#nav_bar { ... } ⇒ String
Returns a Bootstrap navigation bar.
-
#nav_bar_divider ⇒ String
Returns divider (vertical bar) for separating items in a nav_bar.
-
#nav_bar_link(text, url, options = {}) ⇒ String
Returns a nav_bar_link.
-
#nav_bar_links(options = {}) { ... } ⇒ String
Usually called in
yield
block of #nav_bar. -
#nav_bar_text(text, options = {}) ⇒ String
Wraps text so it has proper leading and color for text in a nav bar.
-
#nav_bar_wrapper(options = {}) ⇒ Object
Returns <div> for a group of nav bar links, <ul>s.
-
#nav_list(options = {}) { ... } ⇒ String
Returns nav list.
-
#nav_list_header(text) ⇒ String
Returns header for nav_list.
- #vertical_nav(options = {}) ⇒ Object
Instance Method Details
#brand(text, options = {}) ⇒ String
Returns a Bootstrap brand element
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 53 def brand(text, = {}) = () = ensure_class(, 'navbar-brand') with_environment = .delete(:with_environment) if with_environment && Rails.env != 'production' if text.present? text = "#{text} - #{Rails.env}" else text = Rails.env end = ensure_class(, "rails-#{Rails.env}") end url = .delete(:url) content_tag(:div, class: "navbar-header") do if url.present? link_to(text, url, ) else content_tag(:span, text, ) end end end |
#nav_bar { ... } ⇒ String
Returns a Bootstrap navigation bar
37 38 39 40 41 42 43 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 37 def () content_tag(:nav, class: 'navbar navbar-default') do content_tag(:div, class: 'container-fluid') do yield end end end |
#nav_bar_divider ⇒ String
Returns divider (vertical bar) for separating items in a nav_bar
127 128 129 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 127 def content_tag(:li, nil, class: "divider") end |
#nav_bar_link(text, url, options = {}) ⇒ String
Returns a nav_bar_link
Usually called within yield block of #nav_bar
113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 113 def (text, url, ={}) = () active = .delete(:active) = ensure_class({class: ('active' if active)}, "") content_tag(:li, ) do link_to(text, url, ) end end |
#nav_bar_links(options = {}) { ... } ⇒ String
Usually called in yield
block of #nav_bar
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 91 def ( = {}) = () = ensure_class(, 'nav navbar-nav') if pull = .delete(:pull) = ensure_class(, "navbar-#{pull}") end content_tag(:ul, ) do yield end end |
#nav_bar_text(text, options = {}) ⇒ String
Wraps text so it has proper leading and color for text in a nav bar. Usually in a nav_bar_links
block
Note that the Bootstrap CSS has no horizontal margins or padding. This method pads with three at front and back. Use pad: false to suppress padding.
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 165 def (text, = {}) = () unless .delete(:pad) == false padding = (" " * 3).html_safe text = padding + sanitize(text) + padding end pull_class = (.delete(:pull).to_s == 'right' ? 'pull-right' : 'pull-left') = ensure_class(, [pull_class, 'navbar-text']) content_tag(:p, text, ) end |
#nav_bar_wrapper(options = {}) ⇒ Object
Returns <div> for a group of nav bar links, <ul>s.
79 80 81 82 83 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 79 def ( = {}) content_tag(:div, class: "navbar-collapse collapse sidebar-navbar-collapse") do yield end end |
#nav_list(options = {}) { ... } ⇒ String
Returns nav list
136 137 138 139 140 141 142 143 144 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 136 def nav_list(={}) = () = ensure_class(, 'well') content_tag(:div, ) do content_tag(:ul, class: 'nav nav-stacked') do yield end end end |
#nav_list_header(text) ⇒ String
Returns header for nav_list
150 151 152 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 150 def nav_list_header(text) content_tag(:li, text, class: '') end |
#vertical_nav(options = {}) ⇒ Object
179 180 181 182 183 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 179 def vertical_nav( = {}) content_tag(:div, class: "sidebar-nav") do yield end end |