Module: Bootstrap::NavHelper
- 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
Returns <div> for a group of nav bar links, <ul>s.
-
#nav_bar_text(text, options = {}) ⇒ String
Wraps text so it has proper leading and color for text in a nav bar.
-
#nav_list(options = {}) { ... } ⇒ String
Returns nav list.
-
#nav_list_header(text) ⇒ String
Returns header for nav_list.
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 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 53 def brand(text, = {}) = () = ensure_class(, 'brand') with_environment = .delete(:with_environment) if with_environment && Rails.env != 'production' text = "#{text} - #{Rails.env}" = ensure_class(, "rails-#{Rails.env}") end url = .delete(:url) if url.present? link_to(text, url, ) else content_tag(:span, text, ) 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(:header, class: 'navbar') do content_tag(:nav, class: 'navbar-inner') do yield end end end |
#nav_bar_divider ⇒ String
Returns divider (vertical bar) for separating items in a nav_bar
116 117 118 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 116 def content_tag(:li, nil, class: "divider-vertical") end |
#nav_bar_link(text, url, options = {}) ⇒ String
Returns a nav_bar_link
Usually called within yield block of #nav_bar
102 103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 102 def (text, url, ={}) = () active = .delete(:active) = {class: ('active' if active)} content_tag(:li, ) do link_to(text, url, ) end end |
#nav_bar_links(options = {}) { ... } ⇒ String
Returns <div> for a group of nav bar links, <ul>s.
Usually called in yield block of #nav_bar
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 80 def (={}) = () = ensure_class(, 'nav') if pull = .delete(:pull) = ensure_class(, "pull-#{pull}") end content_tag(:div, ) 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.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 154 def (text, ={}) = () unless .delete(:pad) == false padding = (" " * 3).html_safe text = padding + h(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_list(options = {}) { ... } ⇒ String
Returns nav list
125 126 127 128 129 130 131 132 133 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 125 def nav_list(={}) = () = ensure_class(, 'well') content_tag(:div, ) do content_tag(:ul, class: 'nav nav-list') do yield end end end |
#nav_list_header(text) ⇒ String
Returns header for nav_list
139 140 141 |
# File 'app/helpers/bootstrap/nav_helper.rb', line 139 def nav_list_header(text) content_tag(:li, text, class: 'nav-header') end |