Module: NavbarHelper

Defined in:
app/helpers/navbar_helper.rb

Overview

Instance Method Summary collapse

Instance Method Details



25
26
27
28
29
# File 'app/helpers/navbar_helper.rb', line 25

def drop_down(name)
   :li, :class => "dropdown" do
    drop_down_link(name) + drop_down_list { yield }
  end
end


47
48
49
# File 'app/helpers/navbar_helper.rb', line 47

def drop_down_divider
   :li, "", :class => "divider"
end


51
52
53
# File 'app/helpers/navbar_helper.rb', line 51

def drop_down_header(text)
   :li, text, :class => "nav-header"
end


37
38
39
# File 'app/helpers/navbar_helper.rb', line 37

def drop_down_sublist(&block)
   :ul, :class => "dropdown-menu", &block
end


41
42
43
44
45
# File 'app/helpers/navbar_helper.rb', line 41

def drop_down_submenu(name, &block)
   :li, :class => "dropdown-submenu" do
    link_to(name, "") + drop_down_list(&block)
  end
end


31
32
33
34
35
# File 'app/helpers/navbar_helper.rb', line 31

def drop_down_with_submenu(name, &block)
   :li, :class => "dropdown" do
    drop_down_link(name) + drop_down_sublist(&block)
  end
end


55
56
57
# File 'app/helpers/navbar_helper.rb', line 55

def menu_divider
   :li, "", :class => "divider-vertical"
end


11
12
13
14
# File 'app/helpers/navbar_helper.rb', line 11

def menu_group(options={}, &block)
  pull_class = "navbar-#{options[:pull].to_s}" if options[:pull].present?
  (:ul, :class => "nav navbar-nav #{pull_class}", &block)
end


16
17
18
19
20
21
22
23
# File 'app/helpers/navbar_helper.rb', line 16

def menu_item(name=nil, path="#", *args, &block)
  path = name || path if block_given?
  options = args.extract_options!
   :li, :class => is_active?(path, options) do
    name, path = path, options if block_given?
    link_to name, path, options, &block
  end
end


59
60
61
62
63
64
65
66
67
# File 'app/helpers/navbar_helper.rb', line 59

def menu_text(text=nil, options={}, &block)
  pull       = options.delete(:pull)
  pull_class = pull.present? ? "pull-#{pull.to_s}" : nil
  options.append_merge!(:class, pull_class)
  options.append_merge!(:class, "navbar-text")
   :p, options do
    text || yield
  end
end


3
4
5
6
7
8
9
# File 'app/helpers/navbar_helper.rb', line 3

def nav_bar(options={}, &block)
  nav_bar_nav(options) do
    container_div(options[:brand], options[:brand_link], options[:responsive], options[:fluid], options[: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, options={})
  return options[:status] if options.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 !options[:method].nil? || !options["data-method"].nil?
    :inactive
  elsif uri == request_uri || (options[:root] && (request_uri == '/') || (request_uri == root_url))
    :active
  else
    if request_uri.start_with?(uri) and not(root)
      :chosen
    else
      :inactive
    end
  end
end