Module: NavbarHelper

Defined in:
app/helpers/navbar_helper.rb

Overview

Instance Method Summary collapse

Instance Method Details



28
29
30
31
32
# File 'app/helpers/navbar_helper.rb', line 28

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


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

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


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

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


40
41
42
# File 'app/helpers/navbar_helper.rb', line 40

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


44
45
46
47
48
# File 'app/helpers/navbar_helper.rb', line 44

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


34
35
36
37
38
# File 'app/helpers/navbar_helper.rb', line 34

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


58
59
60
# File 'app/helpers/navbar_helper.rb', line 58

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
24
25
26
# 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
    if block_given?
      link_to path, options, &block
    else
      link_to name, path, options, &block
    end 
  end
end


62
63
64
65
66
67
68
69
70
# File 'app/helpers/navbar_helper.rb', line 62

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


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/navbar_helper.rb', line 79

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