bootstrap-navbar 0.0.13 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -16
- data/bootstrap-navbar.gemspec +3 -0
- data/lib/bootstrap-navbar.rb +11 -7
- data/lib/bootstrap-navbar/helpers.rb +5 -176
- data/lib/bootstrap-navbar/helpers/bootstrap2.rb +181 -0
- data/lib/bootstrap-navbar/helpers/bootstrap3.rb +116 -0
- data/lib/bootstrap-navbar/version.rb +1 -1
- data/spec/bootstrap-navbar/helpers/bootstrap2_spec.rb +424 -0
- data/spec/bootstrap-navbar/helpers/bootstrap3_spec.rb +263 -0
- data/spec/bootstrap-navbar/helpers_spec.rb +0 -0
- data/spec/helpers.rb +38 -0
- data/spec/spec_helper.rb +2 -1
- metadata +29 -7
- data/spec/bootstrap_navbar/helpers_spec.rb +0 -353
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db92ce40b7a8185abc9893f93030a213ab8d8601
|
4
|
+
data.tar.gz: 1d0d60b6f459a56b2bd0c8c1631db31095bf3523
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2930350b4b5b9976adcefda73fc0bafb4f0d197dfc3b7e3bad8608b27e0582a98bc41dabad861f9b6d1c549e0ea2526c34a21fde57e9494c9e6c93f441c2b1b9
|
7
|
+
data.tar.gz: 5b8fcf722a72a1581a1be65ee1c991f5bf277f5d176656f0aa70f5b88a63c201e440f02f2db591c6d36b6968878eecdb35ecfd09acb8b112ebd0391e3a022e11
|
data/README.md
CHANGED
@@ -16,15 +16,31 @@ This gem only provides a helper module with methods to generate HTML. It can be
|
|
16
16
|
|
17
17
|
In short: __Unless you know what you're doing, do not use this gem directly in your app!__
|
18
18
|
|
19
|
+
## Requirements
|
20
|
+
|
21
|
+
Only Bootstrap >= 2.1.0 is supported. It might work with earlier versions as well though.
|
22
|
+
|
19
23
|
## Setup
|
20
24
|
|
25
|
+
### Set bootstrap_version (required)
|
26
|
+
|
27
|
+
BootstrapNavbar needs to know what version of Bootstrap it's dealing with since each version has small changes compared to the previous one.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
BootstrapNavbar.configure do |config|
|
31
|
+
config.bootstrap_version = '3.0.0'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
21
35
|
### Set current_url_method (required)
|
22
36
|
|
23
37
|
BootstrapNavbar has to be able to query for the current URL when rendering the navbar, e.g. to determine if a menu item is active or not. Since the way the current URL is determined varies depending on whether you use Rails, Sinatra, etc., this has to be set beforehand in some kind of initializer:
|
24
38
|
|
25
39
|
```ruby
|
26
40
|
# For Rails >= 3.2
|
27
|
-
BootstrapNavbar.
|
41
|
+
BootstrapNavbar.configure do |config|
|
42
|
+
config.current_url_method = 'request.original_url'
|
43
|
+
end
|
28
44
|
```
|
29
45
|
|
30
46
|
`current_url_method` should be set to a string which can be `eval`ed later.
|
@@ -58,8 +74,7 @@ Let's assume you have mixed in the helper in your rendering engine and use Haml.
|
|
58
74
|
### Full example
|
59
75
|
|
60
76
|
```ruby
|
61
|
-
=
|
62
|
-
= brand_link 'My great app'
|
77
|
+
= navbar brand: 'My great app', brand_link: '/home', fixed: :top, responsive: true do
|
63
78
|
= menu_group class: 'foo', id: 'menu' do
|
64
79
|
= menu_text 'Pick an option:'
|
65
80
|
= menu_item "Home", root_path
|
@@ -87,12 +102,12 @@ Let's assume you have mixed in the helper in your rendering engine and use Haml.
|
|
87
102
|
|
88
103
|
### Methods
|
89
104
|
|
90
|
-
####
|
105
|
+
#### navbar
|
91
106
|
|
92
107
|
This method sets up the basic structure of a navbar.
|
93
108
|
|
94
109
|
```haml
|
95
|
-
=
|
110
|
+
= navbar
|
96
111
|
```
|
97
112
|
|
98
113
|
generates:
|
@@ -109,7 +124,7 @@ generates:
|
|
109
124
|
The content of the navbar is supplied by the block and the available options:
|
110
125
|
|
111
126
|
```haml
|
112
|
-
=
|
127
|
+
= navbar do
|
113
128
|
Yay!
|
114
129
|
```
|
115
130
|
|
@@ -128,7 +143,7 @@ generates:
|
|
128
143
|
Options `brand` and `brand_link` autogenerate the brand link:
|
129
144
|
|
130
145
|
```haml
|
131
|
-
=
|
146
|
+
= navbar brand: 'My great app', brand_link: '/start'
|
132
147
|
```
|
133
148
|
|
134
149
|
generates:
|
@@ -148,7 +163,7 @@ If only `brand` is defined, `brand_link` defaults to `/`.
|
|
148
163
|
Option `responsive` generates a responsive navbar:
|
149
164
|
|
150
165
|
```haml
|
151
|
-
=
|
166
|
+
= navbar responsive: true
|
152
167
|
```
|
153
168
|
|
154
169
|
generates:
|
@@ -158,18 +173,38 @@ generates:
|
|
158
173
|
<div class="navbar-inner">
|
159
174
|
<div class="container">
|
160
175
|
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
161
|
-
|
162
|
-
|
163
|
-
|
176
|
+
<span class='icon-bar'></span>
|
177
|
+
<span class='icon-bar'></span>
|
178
|
+
<span class='icon-bar'></span>
|
179
|
+
</a>
|
180
|
+
<div class="nav-collapse collapse">
|
181
|
+
</div>
|
164
182
|
</div>
|
165
183
|
</div>
|
166
184
|
</div>
|
167
185
|
```
|
168
186
|
|
187
|
+
**Attention: when using the `responsive` option, the brand link should not be added through the `brand_link` method but directly supplied to the `navbar` call.**
|
188
|
+
|
189
|
+
Don't do this:
|
190
|
+
|
191
|
+
```haml
|
192
|
+
= navbar responsive: true do
|
193
|
+
= brand_link 'My great app', '/home'
|
194
|
+
```
|
195
|
+
|
196
|
+
Do this:
|
197
|
+
|
198
|
+
```haml
|
199
|
+
= navbar responsive: true, brand: 'My great app', brand_link: '/home'
|
200
|
+
```
|
201
|
+
|
202
|
+
Otherwise the brand link will be nested incorrectly and will disappear when resizing the window to a smaller size.
|
203
|
+
|
169
204
|
Option `fluid` changes the grid system to be [fluid](http://twitter.github.io/bootstrap/scaffolding.html#fluidGridSystem):
|
170
205
|
|
171
206
|
```haml
|
172
|
-
=
|
207
|
+
= navbar fluid: true
|
173
208
|
```
|
174
209
|
|
175
210
|
generates:
|
@@ -185,7 +220,7 @@ generates:
|
|
185
220
|
|
186
221
|
#### brand_link
|
187
222
|
|
188
|
-
This method generates a menu divider, to be used in a `
|
223
|
+
This method generates a menu divider, to be used in a `navbar`.
|
189
224
|
|
190
225
|
```haml
|
191
226
|
= brand_link 'My App', '/home'
|
@@ -201,7 +236,7 @@ If the path (`/home` in this case) is not specified, it defaults to `/`.
|
|
201
236
|
|
202
237
|
#### menu_text
|
203
238
|
|
204
|
-
This method generates some menu text, to be used in a `
|
239
|
+
This method generates some menu text, to be used in a `navbar`.
|
205
240
|
|
206
241
|
```haml
|
207
242
|
= menu_text 'Select a option:'
|
@@ -248,7 +283,7 @@ generates:
|
|
248
283
|
|
249
284
|
#### menu_group
|
250
285
|
|
251
|
-
This method generates a menu group, to be used in a `
|
286
|
+
This method generates a menu group, to be used in a `navbar`.
|
252
287
|
|
253
288
|
```haml
|
254
289
|
= menu_group
|
@@ -344,7 +379,7 @@ generates:
|
|
344
379
|
</li>
|
345
380
|
```
|
346
381
|
|
347
|
-
If the specified path/URL is the [current url](#set-current_url_method-required), it will be marked as `active`. Note that it doesn't matter if you link to a full URL or just the path, or if `BootstrapNavbar.current_url_method` returns a full URL or just the path, it will work regardless.
|
382
|
+
If the specified path/URL is the [current url](#set-current_url_method-required), it will be marked as `active`. Note that it doesn't matter if you link to a full URL or just the path, or if `BootstrapNavbar.configuration.current_url_method` returns a full URL or just the path, it will work regardless.
|
348
383
|
|
349
384
|
```haml
|
350
385
|
= menu_item 'Home', '/home'
|
data/bootstrap-navbar.gemspec
CHANGED
@@ -26,4 +26,7 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'rspec-html-matchers', '~> 0.4.3'
|
27
27
|
gem.add_development_dependency 'guard-rspec', '~> 3.0'
|
28
28
|
gem.add_development_dependency 'padrino-helpers', '~> 0.11.2'
|
29
|
+
# Listen >= 2.0.0 only works with Ruby >= 1.9.3
|
30
|
+
gem.add_development_dependency 'listen', '< 2.0.0' if RUBY_VERSION < '1.9.3'
|
31
|
+
gem.add_runtime_dependency 'gem_config', '~> 0.2.4'
|
29
32
|
end
|
data/lib/bootstrap-navbar.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'gem_config'
|
2
2
|
|
3
3
|
module BootstrapNavbar
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
include GemConfig::Base
|
5
|
+
|
6
|
+
BOOTSTRAP_VERSIONS = %w(3.0.1 3.0.0 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0)
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
with_configuration do
|
9
|
+
has :bootstrap_version, classes: String, values: BOOTSTRAP_VERSIONS
|
10
|
+
has :current_url_method, classes: String
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
require_relative 'bootstrap-navbar/version'
|
15
|
+
require_relative 'bootstrap-navbar/helpers'
|
16
|
+
require_relative 'bootstrap-navbar/helpers/bootstrap2'
|
17
|
+
require_relative 'bootstrap-navbar/helpers/bootstrap3'
|
@@ -1,178 +1,7 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
1
|
module BootstrapNavbar::Helpers
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
container_div options[:brand], options[:brand_link], options[:responsive], options[:fluid], &block
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def menu_group(options = {}, &block)
|
13
|
-
css_classes = %w(nav).tap do |css_classes|
|
14
|
-
css_classes << "pull-#{options.delete(:pull)}" if options.has_key?(:pull)
|
15
|
-
css_classes << options.delete(:class) if options.has_key?(:class)
|
16
|
-
end
|
17
|
-
attributes = attribute_hash_to_string({ class: css_classes.join(' ') }.merge(options))
|
18
|
-
prepare_html <<-HTML.chomp!
|
19
|
-
<ul#{with_preceding_space attributes}>
|
20
|
-
#{capture(&block) if block_given?}
|
21
|
-
</ul>
|
22
|
-
HTML
|
23
|
-
end
|
24
|
-
|
25
|
-
def menu_item(name = nil, path = nil, list_item_options = nil, link_options = nil, &block)
|
26
|
-
name, path, list_item_options, link_options = capture(&block), name, path, list_item_options if block_given?
|
27
|
-
path ||= '#'
|
28
|
-
list_item_options ||= {}
|
29
|
-
link_options ||= {}
|
30
|
-
|
31
|
-
list_item_css_classes = [].tap do |css_classes|
|
32
|
-
css_classes << 'active' if current_url?(path)
|
33
|
-
css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
|
34
|
-
end
|
35
|
-
list_item_attributes = attribute_hash_to_string(
|
36
|
-
{ class: list_item_css_classes.join(' ') }
|
37
|
-
.delete_if { |k, v| v.empty? }
|
38
|
-
.merge(list_item_options)
|
39
|
-
)
|
40
|
-
link_attributes = attribute_hash_to_string(link_options)
|
41
|
-
prepare_html <<-HTML.chomp!
|
42
|
-
<li#{with_preceding_space list_item_attributes}>
|
43
|
-
<a href="#{path}"#{with_preceding_space link_attributes}>
|
44
|
-
#{name}
|
45
|
-
</a>
|
46
|
-
</li>
|
47
|
-
HTML
|
48
|
-
end
|
49
|
-
|
50
|
-
def drop_down(name, &block)
|
51
|
-
prepare_html <<-HTML.chomp!
|
52
|
-
<li class="dropdown">
|
53
|
-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
54
|
-
#{name} <b class="caret"></b>
|
55
|
-
</a>
|
56
|
-
#{drop_down_menu(&block)}
|
57
|
-
</li>
|
58
|
-
HTML
|
59
|
-
end
|
60
|
-
|
61
|
-
def sub_drop_down(name, list_item_options = {}, link_options = {}, &block)
|
62
|
-
list_item_css_classes = %w(dropdown-submenu).tap do |css_classes|
|
63
|
-
css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
|
64
|
-
end
|
65
|
-
list_item_attributes = attribute_hash_to_string({ class: list_item_css_classes.join(' ') }.merge(list_item_options))
|
66
|
-
link_attributes = attribute_hash_to_string(link_options)
|
67
|
-
prepare_html <<-HTML.chomp!
|
68
|
-
<li#{with_preceding_space list_item_attributes}>
|
69
|
-
<a href="#"#{with_preceding_space link_attributes}>
|
70
|
-
#{name}
|
71
|
-
</a>
|
72
|
-
#{drop_down_menu(&block)}
|
73
|
-
</li>
|
74
|
-
HTML
|
75
|
-
end
|
76
|
-
|
77
|
-
def drop_down_divider
|
78
|
-
prepare_html %(<li class="divider"></li>)
|
79
|
-
end
|
80
|
-
|
81
|
-
def drop_down_header(text)
|
82
|
-
prepare_html %(<li class="nav-header">#{text}</li>)
|
83
|
-
end
|
84
|
-
|
85
|
-
def menu_divider
|
86
|
-
prepare_html %(<li class="divider-vertical"></li>)
|
87
|
-
end
|
88
|
-
|
89
|
-
def menu_text(text = nil, pull = nil, &block)
|
90
|
-
css_classes = %w(navbar-text).tap do |css_classes|
|
91
|
-
css_classes << "pull-#{pull}" if pull
|
92
|
-
end
|
93
|
-
prepare_html <<-HTML.chomp!
|
94
|
-
<p class="#{css_classes.join(' ')}">
|
95
|
-
#{block_given? ? capture(&block) : text}
|
96
|
-
</p>
|
97
|
-
HTML
|
98
|
-
end
|
99
|
-
|
100
|
-
def brand_link(name, url = nil)
|
101
|
-
prepare_html %(<a href="#{url || '/'}" class="brand">#{name}</a>)
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def nav_bar_div(options, &block)
|
107
|
-
position = case
|
108
|
-
when options.has_key?(:static)
|
109
|
-
"static-#{options[:static]}"
|
110
|
-
when options.has_key?(:fixed)
|
111
|
-
"fixed-#{options[:fixed]}"
|
112
|
-
end
|
113
|
-
|
114
|
-
css_classes = %w(navbar).tap do |css_classes|
|
115
|
-
css_classes << "navbar-#{position}" if position
|
116
|
-
css_classes << 'navbar-inverse' if options[:inverse]
|
117
|
-
end
|
118
|
-
|
119
|
-
prepare_html <<-HTML.chomp!
|
120
|
-
<div class="#{css_classes.join(' ')}">
|
121
|
-
#{capture(&block) if block_given?}
|
122
|
-
</div>
|
123
|
-
HTML
|
124
|
-
end
|
125
|
-
|
126
|
-
def navbar_inner_div(&block)
|
127
|
-
prepare_html <<-HTML.chomp!
|
128
|
-
<div class="navbar-inner">
|
129
|
-
#{capture(&block) if block_given?}
|
130
|
-
</div>
|
131
|
-
HTML
|
132
|
-
end
|
133
|
-
|
134
|
-
def container_div(brand, brand_link, responsive, fluid, &block)
|
135
|
-
css_class = fluid ? 'container-fluid' : 'container'
|
136
|
-
content = [].tap do |content|
|
137
|
-
content << responsive_button if responsive
|
138
|
-
content << brand_link(brand, brand_link) if brand || brand_link
|
139
|
-
content << if responsive
|
140
|
-
responsive_wrapper(&block)
|
141
|
-
else
|
142
|
-
capture(&block) if block_given?
|
143
|
-
end
|
144
|
-
end
|
145
|
-
prepare_html <<-HTML.chomp!
|
146
|
-
<div class="#{css_class}">
|
147
|
-
#{content.join("\n")}
|
148
|
-
</div>
|
149
|
-
HTML
|
150
|
-
end
|
151
|
-
|
152
|
-
def responsive_wrapper(&block)
|
153
|
-
prepare_html <<-HTML.chomp!
|
154
|
-
<div class="nav-collapse collapse">
|
155
|
-
#{capture(&block) if block_given?}
|
156
|
-
</div>
|
157
|
-
HTML
|
158
|
-
end
|
159
|
-
|
160
|
-
def responsive_button
|
161
|
-
prepare_html <<-HTML.chomp!
|
162
|
-
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
163
|
-
<span class='icon-bar'></span>
|
164
|
-
<span class='icon-bar'></span>
|
165
|
-
<span class='icon-bar'></span>
|
166
|
-
</a>
|
167
|
-
HTML
|
168
|
-
end
|
169
|
-
|
170
|
-
def drop_down_menu(&block)
|
171
|
-
prepare_html <<-HTML.chomp!
|
172
|
-
<ul class="dropdown-menu">
|
173
|
-
#{capture(&block) if block_given?}
|
174
|
-
</ul>
|
175
|
-
HTML
|
2
|
+
def self.included(base)
|
3
|
+
helper_version = BootstrapNavbar.configuration.bootstrap_version.split('.').first
|
4
|
+
base.send :include, const_get("BootstrapNavbar::Helpers::Bootstrap#{helper_version}")
|
176
5
|
end
|
177
6
|
|
178
7
|
def with_preceding_space(attributes)
|
@@ -191,8 +20,8 @@ HTML
|
|
191
20
|
end
|
192
21
|
|
193
22
|
def current_url
|
194
|
-
raise StandardError, 'current_url_method is not defined.' if BootstrapNavbar.current_url_method.nil?
|
195
|
-
eval BootstrapNavbar.current_url_method
|
23
|
+
raise StandardError, 'current_url_method is not defined.' if BootstrapNavbar.configuration.current_url_method.nil?
|
24
|
+
eval BootstrapNavbar.configuration.current_url_method
|
196
25
|
end
|
197
26
|
|
198
27
|
def prepare_html(html)
|
@@ -0,0 +1,181 @@
|
|
1
|
+
module BootstrapNavbar::Helpers::Bootstrap2
|
2
|
+
def navbar(options = {}, &block)
|
3
|
+
navbar_wrapper options do
|
4
|
+
navbar_inner_div do
|
5
|
+
container_div options[:brand], options[:brand_link], options[:responsive], options[:fluid], &block
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def menu_group(options = {}, &block)
|
11
|
+
css_classes = %w(nav).tap do |css_classes|
|
12
|
+
css_classes << "pull-#{options.delete(:pull)}" if options.has_key?(:pull)
|
13
|
+
css_classes << options.delete(:class) if options.has_key?(:class)
|
14
|
+
end
|
15
|
+
attributes = attribute_hash_to_string({ class: css_classes.join(' ') }.merge(options))
|
16
|
+
prepare_html <<-HTML.chomp!
|
17
|
+
<ul#{with_preceding_space attributes}>
|
18
|
+
#{capture(&block) if block_given?}
|
19
|
+
</ul>
|
20
|
+
HTML
|
21
|
+
end
|
22
|
+
|
23
|
+
def menu_item(name = nil, path = nil, list_item_options = nil, link_options = nil, &block)
|
24
|
+
name, path, list_item_options, link_options = capture(&block), name, path, list_item_options if block_given?
|
25
|
+
path ||= '#'
|
26
|
+
list_item_options ||= {}
|
27
|
+
link_options ||= {}
|
28
|
+
|
29
|
+
list_item_css_classes = [].tap do |css_classes|
|
30
|
+
css_classes << 'active' if current_url?(path)
|
31
|
+
css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
|
32
|
+
end
|
33
|
+
list_item_attributes = attribute_hash_to_string(
|
34
|
+
{ class: list_item_css_classes.join(' ') }
|
35
|
+
.delete_if { |k, v| v.empty? }
|
36
|
+
.merge(list_item_options)
|
37
|
+
)
|
38
|
+
link_attributes = attribute_hash_to_string(link_options)
|
39
|
+
prepare_html <<-HTML.chomp!
|
40
|
+
<li#{with_preceding_space list_item_attributes}>
|
41
|
+
<a href="#{path}"#{with_preceding_space link_attributes}>
|
42
|
+
#{name}
|
43
|
+
</a>
|
44
|
+
</li>
|
45
|
+
HTML
|
46
|
+
end
|
47
|
+
|
48
|
+
def drop_down(name, &block)
|
49
|
+
prepare_html <<-HTML.chomp!
|
50
|
+
<li class="dropdown">
|
51
|
+
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
52
|
+
#{name} <b class="caret"></b>
|
53
|
+
</a>
|
54
|
+
#{drop_down_menu(&block)}
|
55
|
+
</li>
|
56
|
+
HTML
|
57
|
+
end
|
58
|
+
|
59
|
+
def sub_drop_down(name, list_item_options = {}, link_options = {}, &block)
|
60
|
+
list_item_css_classes = %w(dropdown-submenu).tap do |css_classes|
|
61
|
+
css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
|
62
|
+
end
|
63
|
+
list_item_attributes = attribute_hash_to_string({ class: list_item_css_classes.join(' ') }.merge(list_item_options))
|
64
|
+
link_attributes = attribute_hash_to_string(link_options)
|
65
|
+
prepare_html <<-HTML.chomp!
|
66
|
+
<li#{with_preceding_space list_item_attributes}>
|
67
|
+
<a href="#"#{with_preceding_space link_attributes}>
|
68
|
+
#{name}
|
69
|
+
</a>
|
70
|
+
#{drop_down_menu(&block)}
|
71
|
+
</li>
|
72
|
+
HTML
|
73
|
+
end
|
74
|
+
|
75
|
+
def drop_down_divider
|
76
|
+
prepare_html %(<li class="divider"></li>)
|
77
|
+
end
|
78
|
+
|
79
|
+
def drop_down_header(text)
|
80
|
+
prepare_html %(<li class="nav-header">#{text}</li>)
|
81
|
+
end
|
82
|
+
|
83
|
+
def menu_divider
|
84
|
+
prepare_html %(<li class="divider-vertical"></li>)
|
85
|
+
end
|
86
|
+
|
87
|
+
def menu_text(text = nil, pull = nil, &block)
|
88
|
+
css_classes = %w(navbar-text).tap do |css_classes|
|
89
|
+
css_classes << "pull-#{pull}" if pull
|
90
|
+
end
|
91
|
+
prepare_html <<-HTML.chomp!
|
92
|
+
<p class="#{css_classes.join(' ')}">
|
93
|
+
#{block_given? ? capture(&block) : text}
|
94
|
+
</p>
|
95
|
+
HTML
|
96
|
+
end
|
97
|
+
|
98
|
+
def brand_link(name, url = nil)
|
99
|
+
prepare_html %(<a href="#{url || '/'}" class="brand">#{name}</a>)
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def navbar_wrapper(options, &block)
|
105
|
+
position = case
|
106
|
+
when options.has_key?(:static)
|
107
|
+
"static-#{options[:static]}"
|
108
|
+
when options.has_key?(:fixed)
|
109
|
+
"fixed-#{options[:fixed]}"
|
110
|
+
end
|
111
|
+
|
112
|
+
css_classes = %w(navbar).tap do |css_classes|
|
113
|
+
css_classes << "navbar-#{position}" if position
|
114
|
+
css_classes << 'navbar-inverse' if options[:inverse]
|
115
|
+
end
|
116
|
+
attribute_hash = { class: css_classes.join(' ') }
|
117
|
+
attributes = attribute_hash_to_string(attribute_hash)
|
118
|
+
|
119
|
+
prepare_html <<-HTML.chomp!
|
120
|
+
<div#{with_preceding_space attributes}>
|
121
|
+
#{capture(&block) if block_given?}
|
122
|
+
</div>
|
123
|
+
HTML
|
124
|
+
end
|
125
|
+
|
126
|
+
def navbar_inner_div(&block)
|
127
|
+
prepare_html <<-HTML.chomp!
|
128
|
+
<div class="navbar-inner">
|
129
|
+
#{capture(&block) if block_given?}
|
130
|
+
</div>
|
131
|
+
HTML
|
132
|
+
end
|
133
|
+
|
134
|
+
def container_div(brand, brand_link, responsive, fluid, &block)
|
135
|
+
css_class = fluid ? 'container-fluid' : 'container'
|
136
|
+
content = [].tap do |content|
|
137
|
+
content << responsive_button if responsive
|
138
|
+
content << brand_link(brand, brand_link) if brand || brand_link
|
139
|
+
content << if responsive
|
140
|
+
responsive_wrapper(&block)
|
141
|
+
else
|
142
|
+
capture(&block) if block_given?
|
143
|
+
end
|
144
|
+
end
|
145
|
+
prepare_html <<-HTML.chomp!
|
146
|
+
<div class="#{css_class}">
|
147
|
+
#{content.join("\n")}
|
148
|
+
</div>
|
149
|
+
HTML
|
150
|
+
end
|
151
|
+
|
152
|
+
def responsive_wrapper(&block)
|
153
|
+
css_classes = %w(nav-collapse).tap do |css_classes|
|
154
|
+
css_classes << 'collapse' if BootstrapNavbar.configuration.bootstrap_version >= '2.2.0'
|
155
|
+
end
|
156
|
+
attributes = attribute_hash_to_string({ class: css_classes.join(' ') })
|
157
|
+
prepare_html <<-HTML.chomp!
|
158
|
+
<div#{with_preceding_space attributes}>
|
159
|
+
#{capture(&block) if block_given?}
|
160
|
+
</div>
|
161
|
+
HTML
|
162
|
+
end
|
163
|
+
|
164
|
+
def responsive_button
|
165
|
+
prepare_html <<-HTML.chomp!
|
166
|
+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
167
|
+
<span class='icon-bar'></span>
|
168
|
+
<span class='icon-bar'></span>
|
169
|
+
<span class='icon-bar'></span>
|
170
|
+
</a>
|
171
|
+
HTML
|
172
|
+
end
|
173
|
+
|
174
|
+
def drop_down_menu(&block)
|
175
|
+
prepare_html <<-HTML.chomp!
|
176
|
+
<ul class="dropdown-menu">
|
177
|
+
#{capture(&block) if block_given?}
|
178
|
+
</ul>
|
179
|
+
HTML
|
180
|
+
end
|
181
|
+
end
|