Module: Railsstrap::NavbarHelper
- Defined in:
- app/helpers/railsstrap/navbar_helper.rb
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
28 29 30 31 32 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 28 def drop_down(name) content_tag :li, :class => "dropdown" do drop_down_link(name) + drop_down_list { yield } end end |
#drop_down_divider ⇒ Object
50 51 52 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 50 def drop_down_divider content_tag :li, "", :class => "divider" end |
#drop_down_header(text) ⇒ Object
54 55 56 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 54 def drop_down_header(text) content_tag :li, text, :class => "nav-header" end |
#drop_down_sublist(&block) ⇒ Object
40 41 42 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 40 def drop_down_sublist(&block) content_tag :ul, :class => "dropdown-menu", &block end |
#drop_down_submenu(name, &block) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 44 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
34 35 36 37 38 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 34 def (name, &block) content_tag :li, :class => "dropdown" do drop_down_link(name) + drop_down_sublist(&block) end end |
#menu_divider ⇒ Object
58 59 60 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 58 def content_tag :li, "", :class => "divider-vertical" end |
#menu_group(options = {}, &block) ⇒ Object
14 15 16 17 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 14 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
19 20 21 22 23 24 25 26 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 19 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
62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 62 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
6 7 8 9 10 11 12 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 6 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're 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 79 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 |