Module: NavbarHelper
- Defined in:
- app/helpers/navbar_helper.rb
Overview
Credit for this goes to github.com/julescopeland/Rails-Bootstrap-Navbar
Instance Method Summary collapse
- #drop_down(name) ⇒ Object
- #drop_down_divider ⇒ Object
- #drop_down_header(text) ⇒ Object
- #drop_down_sublist(&block) ⇒ Object
- #drop_down_submenu(name, &block) ⇒ Object
- #drop_down_with_submenu(name, &block) ⇒ Object
- #menu_divider ⇒ Object
- #menu_group(options = {}, &block) ⇒ Object
- #menu_item(name = nil, path = "#", *args, &block) ⇒ Object
- #menu_text(text = nil, options = {}, &block) ⇒ Object
- #nav_bar(options = {}, &block) ⇒ Object
-
#uri_state(uri, options = {}) ⇒ Object
Returns current url or path state (useful for buttons).
Instance Method Details
#drop_down(name) ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/navbar_helper.rb', line 25 def drop_down(name) content_tag :li, :class => "dropdown" do drop_down_link(name) + drop_down_list { yield } end end |
#drop_down_divider ⇒ Object
47 48 49 |
# File 'app/helpers/navbar_helper.rb', line 47 def drop_down_divider content_tag :li, "", :class => "divider" end |
#drop_down_header(text) ⇒ Object
51 52 53 |
# File 'app/helpers/navbar_helper.rb', line 51 def drop_down_header(text) content_tag :li, text, :class => "nav-header" end |
#drop_down_sublist(&block) ⇒ Object
37 38 39 |
# File 'app/helpers/navbar_helper.rb', line 37 def drop_down_sublist(&block) content_tag :ul, :class => "dropdown-menu", &block end |
#drop_down_submenu(name, &block) ⇒ Object
41 42 43 44 45 |
# File 'app/helpers/navbar_helper.rb', line 41 def (name, &block) content_tag :li, :class => "dropdown-submenu" do link_to(name, "") + drop_down_list(&block) end end |
#drop_down_with_submenu(name, &block) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/navbar_helper.rb', line 31 def (name, &block) content_tag :li, :class => "dropdown" do drop_down_link(name) + drop_down_sublist(&block) end end |
#menu_divider ⇒ Object
55 56 57 |
# File 'app/helpers/navbar_helper.rb', line 55 def content_tag :li, "", :class => "divider-vertical" end |
#menu_group(options = {}, &block) ⇒ Object
11 12 13 14 |
# File 'app/helpers/navbar_helper.rb', line 11 def (={}, &block) pull_class = "navbar-#{[:pull].to_s}" if [:pull].present? content_tag(:ul, :class => "nav navbar-nav #{pull_class}", &block) end |
#menu_item(name = nil, path = "#", *args, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/helpers/navbar_helper.rb', line 16 def (name=nil, path="#", *args, &block) path = name || path if block_given? = args. content_tag :li, :class => is_active?(path, ) do name, path = path, if block_given? link_to name, path, , &block end end |
#menu_text(text = nil, options = {}, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/navbar_helper.rb', line 59 def (text=nil, ={}, &block) pull = .delete(:pull) pull_class = pull.present? ? "pull-#{pull.to_s}" : nil .append_merge!(:class, pull_class) .append_merge!(:class, "navbar-text") content_tag :p, do text || yield end end |
#nav_bar(options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/navbar_helper.rb', line 3 def (={}, &block) () do container_div([:brand], [:brand_link], [:responsive], [:fluid], [:no_turbolink]) do yield if block_given? end end end |
#uri_state(uri, options = {}) ⇒ Object
Returns current url or path state (useful for buttons). Example:
# Assume we'r currently at blog/categories/test
uri_state('/blog/categories/test', {}) # :active
uri_state('/blog/categories', {}) # :chosen
uri_state('/blog/categories/test', {method: delete}) # :inactive
uri_state('/blog/categories/test/3', {}) # :inactive
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/navbar_helper.rb', line 76 def uri_state(uri, ={}) return [:status] if .key?(:status) root_url = request.host_with_port + '/' root = uri == '/' || uri == root_url request_uri = if uri.start_with?(root_url) request.url else request.path end if ![:method].nil? || !["data-method"].nil? :inactive elsif uri == request_uri || ([:root] && (request_uri == '/') || (request_uri == root_url)) :active else if request_uri.start_with?(uri) and not(root) :chosen else :inactive end end end |