Module: BootstrapNavbar::Helpers::Bootstrap3

Defined in:
lib/bootstrap-navbar/helpers/bootstrap3.rb

Instance Method Summary collapse

Instance Method Details



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 2

def navbar(options = {}, &block)
  options = options.dup
  container = options.key?(:container) ? options.delete(:container) : true
  wrapper options do
    if container
      container(container, &block)
    else
      capture(&block) if block_given?
    end
  end
end


102
103
104
105
106
107
108
109
110
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 102

def navbar_button(text, options = {})
  options = options.dup
  options[:class] = [options[:class], 'btn', 'navbar-btn'].compact.join(' ')
  options[:type] ||= 'button'
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<button#{attributes}>#{text}</button>
HTML
end


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 33

def navbar_collapse(options = {}, &block)
  options = options.dup
  options[:class] = [options[:class], 'collapse', 'navbar-collapse'].compact.join(' ')
  options[:id] ||= 'navbar-collapsable'
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<div#{attributes}>
#{capture(&block) if block_given?}
</div>
HTML
end


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 112

def navbar_dropdown(text, list_item_options = {}, link_options = {}, &block)
  list_item_options, link_options = list_item_options.dup, link_options.dup
  list_item_options[:class] = [list_item_options[:class], 'dropdown'].compact.join(' ')
  list_item_attributes = attributes_for_tag(list_item_options)
  link_options[:class] = [link_options[:class], 'dropdown-toggle'].compact.join(' ')
  link_attributes = attributes_for_tag(link_options)
  prepare_html <<-HTML.chomp!
<li#{list_item_attributes}>
<a href="#" data-toggle="dropdown"#{link_attributes}>#{text} <b class="caret"></b></a>
<ul class="dropdown-menu">
  #{capture(&block) if block_given?}
</ul>
</li>
HTML
end


136
137
138
139
140
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 136

def navbar_dropdown_divider
  prepare_html <<-HTML.chomp!
<li class="divider"></li>
HTML
end


128
129
130
131
132
133
134
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 128

def navbar_dropdown_header(text)
  prepare_html <<-HTML.chomp!
<li class="dropdown-header">
#{text}
</li>
HTML
end


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 77

def navbar_form(url, options = {}, &block)
  options = options.dup
  options[:class] = [options[:class], 'navbar-form'].compact
  options[:class] << "navbar-#{options.delete(:align)}" if options.key?(:align)
  options[:class] = options[:class].join(' ')
  options[:role] ||= 'form'
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<form action="#{url}" #{attributes}>
#{capture(&block) if block_given?}
</form>
HTML
end


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 45

def navbar_group(options = {}, &block)
  options = options.dup
  options[:class] = [options[:class], 'nav', 'navbar-nav'].compact
  options[:class] << "navbar-#{options.delete(:align)}" if options.key?(:align)
  options[:class] = options[:class].join(' ')
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<ul#{attributes}>
#{capture(&block) if block_given?}
</ul>
HTML
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 14

def navbar_header(options = {}, &block)
  options = options.dup
  brand, brand_link = options.delete(:brand), options.delete(:brand_link)
  options[:class] = [options[:class], 'navbar-header'].compact.join(' ')
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<div#{attributes}>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapsable">
  <span class="sr-only">Toggle navigation</span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
</button>
#{brand_link brand, brand_link unless brand.nil?}
#{capture(&block) if block_given?}
</div>
HTML
end


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 58

def navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block)
  text, url, list_item_options, link_options = capture(&block), text, url, list_item_options if block_given?
  url ||= '#'
  list_item_options   = list_item_options ? list_item_options.dup : {}
  link_options        = link_options      ? link_options.dup      : {}
  list_item_options[:class] = [list_item_options[:class]].compact
  list_item_options[:class] << 'active' if current_url_or_sub_url?(url)
  list_item_options[:class] = list_item_options[:class].join(' ')
  list_item_attributes = attributes_for_tag(list_item_options)
  link_attributes = attributes_for_tag(link_options)
  prepare_html <<-HTML.chomp!
<li#{list_item_attributes}>
<a href="#{url}"#{link_attributes}>
  #{text}
</a>
</li>
HTML
end

Raises:

  • (StandardError)


91
92
93
94
95
96
97
98
99
100
# File 'lib/bootstrap-navbar/helpers/bootstrap3.rb', line 91

def navbar_text(text = nil, options = {}, &block)
  raise StandardError, 'Please provide either the "text" parameter or a block.' if !!text == block_given?
  options = options.dup
  text ||= capture(&block)
  options[:class] = [options[:class], 'navbar-text'].compact.join(' ')
  attributes = attributes_for_tag(options)
  prepare_html <<-HTML.chomp!
<p#{attributes}>#{text}</p>
HTML
end