# Rails view helpers for various Bootstrap navigation components. # # See: http://twitter.github.io/bootstrap/components.html#navbar # @example navigation bar (across top of page) # <%= nav_bar do %> # # <%= brand('Span Brand')%> # <%= brand('Link Brand', url: '#')%> # # <%= nav_bar_links do %> # <%= nav_bar_link('Active', '#', active: true) %> # <%= nav_bar_link('Link 1', '/link1') %> # <%= nav_bar_divider %> # <%= nav_bar_link('Link 2', '/link2') %> # <% end > # # <%= nav_dropdown(pull: 'right') %> # <%= nav_dropdown('Dropdown 1') do %> # <%= dropdown_item('One', 'foo')%> # <% end %> # <% end %> # # <% end %> # # @example navigation list (e.g., in sidebar) # <%= nav_list(id: 'my') do %> # <%= nav_list_header('Buttons & Labels') %> # <%= dropdown_item('Buttons', 'butons')%> # <%= dropdown_item('Labels', 'butons')%> # <% end %> module Bootstrap::NavHelper include ActionView::Helpers::SanitizeHelper # Returns a Bootstrap navigation bar # @yield yield block usually consists of other {Bootstrap::NavHelper} helpers # @yieldreturn the contents of the navigation bar # @return [String] def nav_bar() content_tag(:nav, class: 'navbar navbar-default') do content_tag(:div, class: 'container-fluid') do yield end end end # Returns a Bootstrap brand element # # @param [String] text text of the brand # @param [Hash] options except for +:url+, becomes html attributes of returned tag # @option options [String] :url if present, returned tag is an (else ) # @option options [Boolean] :with_environment if present, environment is appended to _text_ and # and a class of "rails-" is added to the returned tag. # @return [String] if +:url+ option present, else def brand(text, options = {}) options = canonicalize_options(options) options = ensure_class(options, 'navbar-brand') with_environment = options.delete(:with_environment) if with_environment && Rails.env != 'production' if text.present? text = "#{text} - #{Rails.env}" else text = Rails.env end options = ensure_class(options, "rails-#{Rails.env}") end url = options.delete(:url) content_tag(:div, class: "navbar-header") do if url.present? link_to(text, url, options) else content_tag(:span, text, options) end end end # Returns
for a group of nav bar links,