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.
@@ -0,0 +1,263 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'active navbar link' do
4
+ it 'generates the correct HTML' do
5
+ with_all_3_dot_x_versions do
6
+ paths_and_urls.each do |current_path_or_url|
7
+ paths_and_urls.each do |menu_path_or_url|
8
+ BootstrapNavbar.configuration.current_url_method = "'#{current_path_or_url}'"
9
+ expect(renderer.navbar_group_item('foo', menu_path_or_url)).to have_tag(:li, with: { class: 'active' }) do
10
+ with_tag :a, with: { href: menu_path_or_url }, content: 'foo'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ describe BootstrapNavbar::Helpers::Bootstrap3 do
19
+ before do
20
+ BootstrapNavbar.configuration.current_url_method = '"/"'
21
+ end
22
+
23
+ it 'includes the correct module' do
24
+ with_all_3_dot_x_versions do
25
+ expect(renderer.class.ancestors).to include(BootstrapNavbar::Helpers::Bootstrap3)
26
+ expect(renderer.class.ancestors).to_not include(BootstrapNavbar::Helpers::Bootstrap2)
27
+ end
28
+ end
29
+
30
+ describe '#navbar' do
31
+ context 'without parameters' do
32
+ it 'generates the correct HTML' do
33
+ with_all_3_dot_x_versions do
34
+ expect(renderer.navbar { 'foo' }).to have_tag(:nav, with: { class: 'navbar navbar-default', role: 'navigation' }) do
35
+ with_tag :div, with: { class: 'navbar-header' } do
36
+ with_tag :button, with: { type: 'button', class: 'navbar-toggle', :'data-toggle' => 'collapse', :'data-target' => '#navbar-collapsable' } do
37
+ with_tag :span, class: 'sr-only', content: 'Toggle navigation'
38
+ 3.times do
39
+ with_tag :span, class: 'icon-bar'
40
+ end
41
+ end
42
+ with_tag :a, class: 'navbar-brand', href: '#'
43
+ end
44
+ with_tag :div, class: 'collapse navbar-collapse', id: 'navbar-collapsable', content: 'foo'
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'with "static" parameter' do
51
+ it 'generates the correct HTML' do
52
+ with_all_3_dot_x_versions do
53
+ expect(renderer.navbar(static: true)).to have_tag(:nav, with: { class: 'navbar navbar-default navbar-static-top' })
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'with "fixed" parameter' do
59
+ it 'generates the correct HTML' do
60
+ with_all_3_dot_x_versions do
61
+ expect(renderer.navbar(fixed: 'top')).to have_tag(:nav, with: { class: 'navbar navbar-default navbar-fixed-top' })
62
+ expect(renderer.navbar(fixed: 'bottom')).to have_tag(:nav, with: { class: 'navbar navbar-default navbar-fixed-bottom' })
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'with "inverse" parameter' do
68
+ it 'generates the correct HTML' do
69
+ with_all_3_dot_x_versions do
70
+ expect(renderer.navbar(inverse: true)).to have_tag(:nav, with: { class: 'navbar navbar-inverse' })
71
+ end
72
+ end
73
+ end
74
+
75
+ context 'with "brand" and "brank_link" parameters' do
76
+ it 'generates the correct HTML' do
77
+ with_all_3_dot_x_versions do
78
+ expect(renderer.navbar(brand: 'foo')).to have_tag(:a, with: { href: '/', class: 'navbar-brand' }, content: 'foo')
79
+ expect(renderer.navbar(brand: 'foo', brand_link: 'http://google.com')).to have_tag(:a, with: { href: 'http://google.com', class: 'navbar-brand' }, content: 'foo')
80
+ expect(renderer.navbar(brand_link: 'http://google.com')).to have_tag(:a, with: { href: 'http://google.com', class: 'navbar-brand' })
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#navbar_group' do
87
+ context 'without parameters' do
88
+ it 'generates the correct HTML' do
89
+ with_all_3_dot_x_versions do
90
+ expect(renderer.navbar_group).to have_tag(:ul, with: { class: 'nav navbar-nav' })
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'with "align" parameter' do
96
+ it 'generates the correct HTML' do
97
+ with_all_3_dot_x_versions do
98
+ expect(renderer.navbar_group(align: 'right')).to have_tag(:ul, with: { class: 'nav navbar-nav navbar-right' })
99
+ expect(renderer.navbar_group(align: 'left')).to have_tag(:ul, with: { class: 'nav navbar-nav navbar-left' })
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#navbar_dropdown' do
106
+ it 'generates the correct HTML' do
107
+ with_all_3_dot_x_versions do
108
+ expect(renderer.navbar_dropdown('foo') { 'bar' }).to have_tag(:li, with: { class: 'dropdown' }) do
109
+ with_tag :a, with: { href: '#', class: 'dropdown-toggle', :'data-toggle' => 'dropdown' } do
110
+ with_text 'foo '
111
+ with_tag :b, with: { class: 'caret' }
112
+ end
113
+ with_tag :ul, with: { class: 'dropdown-menu' }, content: 'bar'
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '#navbar_group_item' do
120
+ context 'with current URL or path' do
121
+ # With root URL or path
122
+ it_behaves_like 'active navbar link' do
123
+ let(:paths_and_urls) do
124
+ %w(
125
+ http://www.foobar.com/
126
+ http://www.foobar.com
127
+ /
128
+ http://www.foobar.com/?foo=bar
129
+ http://www.foobar.com?foo=bar
130
+ /?foo=bar
131
+ http://www.foobar.com/#foo
132
+ http://www.foobar.com#foo
133
+ /#foo
134
+ http://www.foobar.com/#foo?foo=bar
135
+ http://www.foobar.com#foo?foo=bar
136
+ /#foo?foo=bar
137
+ )
138
+ end
139
+ end
140
+
141
+ # With sub URL or path
142
+ it_behaves_like 'active navbar link' do
143
+ let(:paths_and_urls) do
144
+ %w(
145
+ http://www.foobar.com/foo
146
+ http://www.foobar.com/foo/
147
+ /foo
148
+ /foo/
149
+ http://www.foobar.com/foo?foo=bar
150
+ http://www.foobar.com/foo/?foo=bar
151
+ /foo?foo=bar
152
+ /foo/?foo=bar
153
+ http://www.foobar.com/foo#foo
154
+ http://www.foobar.com/foo/#foo
155
+ /foo#foo
156
+ /foo/#foo
157
+ http://www.foobar.com/foo#foo?foo=bar
158
+ http://www.foobar.com/foo/#foo?foo=bar
159
+ /foo#foo?foo=bar
160
+ /foo/#foo?foo=bar
161
+ )
162
+ end
163
+ end
164
+ end
165
+
166
+ context 'without current URL' do
167
+ it 'generates the correct HTML' do
168
+ with_all_3_dot_x_versions do
169
+ BootstrapNavbar.configuration.current_url_method = '"/foo"'
170
+ expect(renderer.navbar_group_item('foo', '/')).to have_tag(:li, without: { class: 'active' }) do
171
+ with_tag :a, with: { href: '/' }, content: 'foo'
172
+ end
173
+ expect(renderer.navbar_group_item('foo', '/bar')).to have_tag(:li, without: { class: 'active' }) do
174
+ with_tag :a, with: { href: '/bar' }, content: 'foo'
175
+ end
176
+
177
+ BootstrapNavbar.configuration.current_url_method = '"/"'
178
+ expect(renderer.navbar_group_item('foo', '/foo')).to have_tag(:li, without: { class: 'active' }) do
179
+ with_tag :a, with: { href: '/foo' }, content: 'foo'
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ describe '#navbar_form' do
187
+ context 'without parameters' do
188
+ it 'generates the correct HTML' do
189
+ with_all_3_dot_x_versions do
190
+ expect(renderer.navbar_form { 'foo' }).to have_tag(:form, with: { class: 'navbar-form', role: 'form' }, content: 'foo')
191
+ end
192
+ end
193
+ end
194
+
195
+ context 'with "align" parameter' do
196
+ it 'generates the correct HTML' do
197
+ with_all_3_dot_x_versions do
198
+ expect(renderer.navbar_form(align: 'left') { 'foo' }).to have_tag(:form, with: { class: 'navbar-form navbar-left', role: 'form' }, content: 'foo')
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ describe '#navbar_divider' do
205
+ it 'generates the correct HTML' do
206
+ with_all_3_dot_x_versions do
207
+ expect(renderer.navbar_divider).to have_tag(:li, with: { class: 'divider' })
208
+ end
209
+ end
210
+ end
211
+
212
+ describe '#navbar_text' do
213
+ context 'without parameters' do
214
+ it 'raises an error' do
215
+ with_all_3_dot_x_versions do
216
+ expect { renderer.navbar_text }.to raise_error(StandardError, 'Please provide either the "text" parameter or a block.')
217
+ end
218
+ end
219
+ end
220
+
221
+ context 'with "text" parameter and a block' do
222
+ it 'raises an error' do
223
+ with_all_3_dot_x_versions do
224
+ expect { renderer.navbar_text }.to raise_error(StandardError, 'Please provide either the "text" parameter or a block.')
225
+ end
226
+ end
227
+ end
228
+
229
+ context 'with "text" parameter' do
230
+ it 'generates the correct HTML' do
231
+ with_all_3_dot_x_versions do
232
+ expect(renderer.navbar_text('foo')).to have_tag(:p, with: { class: 'navbar-text' }, content: 'foo')
233
+ end
234
+ end
235
+ end
236
+
237
+ context 'with block' do
238
+ it 'generates the correct HTML' do
239
+ with_all_3_dot_x_versions do
240
+ expect(renderer.navbar_text { 'foo' }).to have_tag(:p, with: { class: 'navbar-text' }, content: 'foo')
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ describe '#navbar_button' do
247
+ context 'without parameters' do
248
+ it 'generates the correct HTML' do
249
+ with_all_3_dot_x_versions do
250
+ expect(renderer.navbar_button('foo')).to have_tag(:button, with: { class: 'btn navbar-btn', type: 'button' }, content: 'foo')
251
+ end
252
+ end
253
+ end
254
+
255
+ context 'with "class" parameter' do
256
+ it 'generates the correct HTML' do
257
+ with_all_3_dot_x_versions do
258
+ expect(renderer.navbar_button('foo', class: 'bar')).to have_tag(:button, with: { class: 'btn navbar-btn bar', type: 'button' }, content: 'foo')
259
+ end
260
+ end
261
+ end
262
+ end
263
+ end
File without changes
@@ -0,0 +1,38 @@
1
+ require 'padrino-helpers'
2
+
3
+ module Helpers
4
+ def renderer
5
+ @renderer ||= Class.new do
6
+ include Padrino::Helpers::OutputHelpers
7
+ include BootstrapNavbar::Helpers
8
+ end.new
9
+ end
10
+
11
+ def with_all_2_dot_x_versions(&block)
12
+ with_versions '2'...'3', &block
13
+ end
14
+
15
+ def with_all_3_dot_x_versions(&block)
16
+ with_versions '3'...'4', &block
17
+ end
18
+
19
+ def with_versions(versions, &block)
20
+ versions = case versions
21
+ when String
22
+ raise "#{versions} is not a valid version!" unless BootstrapNavbar::BOOTSTRAP_VERSIONS.include?(versions)
23
+ [versions]
24
+ when Range
25
+ BootstrapNavbar::BOOTSTRAP_VERSIONS.select do |version|
26
+ versions.cover?(version)
27
+ end
28
+ else
29
+ raise "Please pass a string or a range to this method, not a #{versions.class}."
30
+ end
31
+
32
+ versions.each do |version|
33
+ puts "Testing version #{version}..."
34
+ BootstrapNavbar.configuration.bootstrap_version = version
35
+ block.call
36
+ end
37
+ end
38
+ end
@@ -1,10 +1,11 @@
1
1
  require 'bootstrap-navbar'
2
2
  require 'rspec-html-matchers'
3
+ require_relative 'helpers'
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.treat_symbols_as_metadata_keys_with_true_values = true
6
7
  config.run_all_when_everything_filtered = true
7
8
  config.filter_run :focus
8
-
9
9
  config.order = 'random'
10
+ config.include Helpers
10
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-navbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.11.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: gem_config
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.4
83
97
  description: Helpers to generate a Twitter Bootstrap style navbar
84
98
  email: manuel.meurer@gmail.com
85
99
  executables: []
@@ -95,8 +109,13 @@ files:
95
109
  - bootstrap-navbar.gemspec
96
110
  - lib/bootstrap-navbar.rb
97
111
  - lib/bootstrap-navbar/helpers.rb
112
+ - lib/bootstrap-navbar/helpers/bootstrap2.rb
113
+ - lib/bootstrap-navbar/helpers/bootstrap3.rb
98
114
  - lib/bootstrap-navbar/version.rb
99
- - spec/bootstrap_navbar/helpers_spec.rb
115
+ - spec/bootstrap-navbar/helpers/bootstrap2_spec.rb
116
+ - spec/bootstrap-navbar/helpers/bootstrap3_spec.rb
117
+ - spec/bootstrap-navbar/helpers_spec.rb
118
+ - spec/helpers.rb
100
119
  - spec/spec_helper.rb
101
120
  homepage: https://github.com/krautcomputing/bootstrap-navbar
102
121
  licenses:
@@ -113,16 +132,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
132
  version: '0'
114
133
  required_rubygems_version: !ruby/object:Gem::Requirement
115
134
  requirements:
116
- - - '>='
135
+ - - '>'
117
136
  - !ruby/object:Gem::Version
118
- version: '0'
137
+ version: 1.3.1
119
138
  requirements: []
120
139
  rubyforge_project:
121
- rubygems_version: 2.0.2
140
+ rubygems_version: 2.1.5
122
141
  signing_key:
123
142
  specification_version: 4
124
143
  summary: Helpers to generate a Twitter Bootstrap style navbar
125
144
  test_files:
126
- - spec/bootstrap_navbar/helpers_spec.rb
145
+ - spec/bootstrap-navbar/helpers/bootstrap2_spec.rb
146
+ - spec/bootstrap-navbar/helpers/bootstrap3_spec.rb
147
+ - spec/bootstrap-navbar/helpers_spec.rb
148
+ - spec/helpers.rb
127
149
  - spec/spec_helper.rb
128
150
  has_rdoc:
@@ -1,353 +0,0 @@
1
- require 'spec_helper'
2
- require 'padrino-helpers'
3
-
4
- shared_examples 'active menu item' do
5
- it 'generates the correct HTML' do
6
- paths_and_urls.each do |current_path_or_url|
7
- paths_and_urls.each do |menu_path_or_url|
8
- BootstrapNavbar.current_url_method = "'#{current_path_or_url}'"
9
- subject.menu_item('foo', menu_path_or_url).should have_tag(:li, with: { class: 'active' })
10
- end
11
- end
12
- end
13
- end
14
-
15
- describe BootstrapNavbar::Helpers do
16
- subject do
17
- Class.new do
18
- include Padrino::Helpers::OutputHelpers
19
- include BootstrapNavbar::Helpers
20
- end.new
21
- end
22
-
23
- before do
24
- BootstrapNavbar.current_url_method = ''
25
- end
26
-
27
- describe '#nav_bar' do
28
- context 'without parameters' do
29
- it 'generates the correct HTML' do
30
- subject.nav_bar.should have_tag(:div, with: { class: 'navbar' }) do
31
- with_tag :div, with: { class: 'navbar-inner' } do
32
- with_tag :div, with: { class: 'container' }
33
- end
34
- end
35
- end
36
- end
37
-
38
- context 'with a block' do
39
- it 'generates the correct HTML' do
40
- subject.nav_bar { 'foo' }.should have_tag(:div, with: { class: 'navbar' }, content: 'foo')
41
- end
42
- end
43
-
44
- context 'with "static" parameter' do
45
- it 'generates the correct HTML' do
46
- subject.nav_bar(static: 'top').should have_tag(:div, with: { class: 'navbar navbar-static-top' })
47
- subject.nav_bar(static: 'bottom').should have_tag(:div, with: { class: 'navbar navbar-static-bottom' })
48
- end
49
- end
50
-
51
- context 'with "fixed" parameter' do
52
- it 'generates the correct HTML' do
53
- subject.nav_bar(fixed: 'top').should have_tag(:div, with: { class: 'navbar navbar-fixed-top' })
54
- subject.nav_bar(fixed: 'bottom').should have_tag(:div, with: { class: 'navbar navbar-fixed-bottom' })
55
- end
56
- end
57
-
58
- context 'with "inverse" parameter' do
59
- it 'generates the correct HTML' do
60
- subject.nav_bar(inverse: true).should have_tag(:div, with: { class: 'navbar navbar-inverse' })
61
- end
62
- end
63
-
64
- context 'with "brand" and "brank_link" parameters' do
65
- it 'generates the correct HTML' do
66
- subject.nav_bar(brand: 'foo').should have_tag(:a, with: { href: '/', class: 'brand' }, content: 'foo')
67
- subject.nav_bar(brand: 'foo', brand_link: 'http://google.com').should have_tag(:a, with: { href: 'http://google.com', class: 'brand' }, content: 'foo')
68
- subject.nav_bar(brand_link: 'http://google.com').should have_tag(:a, with: { href: 'http://google.com', class: 'brand' })
69
- end
70
- end
71
-
72
- context 'with "responsive" parameter' do
73
- it 'generates the correct HTML' do
74
- subject.nav_bar(responsive: true).should have_tag(:a, with: { class: 'btn btn-navbar', :'data-toggle' => 'collapse', :'data-target' => '.nav-collapse' }) do
75
- 3.times do
76
- with_tag :span, with: { class: 'icon-bar' }
77
- end
78
- end
79
- end
80
- end
81
-
82
- context 'with "fluid" parameter' do
83
- it 'generates the correct HTML' do
84
- subject.nav_bar(fluid: true).should have_tag(:div, with: { class: 'container-fluid' })
85
- end
86
- end
87
- end
88
-
89
- describe '#menu_group' do
90
- context 'without parameters' do
91
- it 'generates the correct HTML' do
92
- subject.menu_group.should have_tag(:ul, with: { class: 'nav' })
93
- subject.menu_group { 'foo' }.should have_tag(:ul, with: { class: 'nav' }, content: 'foo')
94
- end
95
- end
96
-
97
- context 'with "pull" parameter' do
98
- it 'generates the correct HTML' do
99
- subject.menu_group(pull: 'right').should have_tag(:ul, with: { class: 'nav pull-right' })
100
- end
101
- end
102
-
103
- context 'with "class" parameter' do
104
- it 'generates the correct HTML' do
105
- subject.menu_group(class: 'foo').should have_tag(:ul, with: { class: 'nav foo' })
106
- end
107
- end
108
-
109
- context 'with random parameters' do
110
- it 'generates the correct HTML' do
111
- subject.menu_group(:'data-foo' => 'bar').should have_tag(:ul, with: { class: 'nav', :'data-foo' => 'bar' })
112
- end
113
- end
114
-
115
- context 'with many parameters' do
116
- it 'generates the correct HTML' do
117
- subject.menu_group(pull: 'right', class: 'foo', :'data-foo' => 'bar').should have_tag(:ul, with: { class: 'nav foo pull-right', :'data-foo' => 'bar' })
118
- end
119
- end
120
- end
121
-
122
- describe '#menu_item' do
123
- context 'with current URL or path' do
124
- # With root URL or path
125
- it_behaves_like 'active menu item' do
126
- let(:paths_and_urls) do
127
- %w(
128
- http://www.foobar.com/
129
- http://www.foobar.com
130
- /
131
- http://www.foobar.com/?foo=bar
132
- http://www.foobar.com?foo=bar
133
- /?foo=bar
134
- http://www.foobar.com/#foo
135
- http://www.foobar.com#foo
136
- /#foo
137
- http://www.foobar.com/#foo?foo=bar
138
- http://www.foobar.com#foo?foo=bar
139
- /#foo?foo=bar
140
- )
141
- end
142
- end
143
-
144
- # With sub URL or path
145
- it_behaves_like 'active menu item' do
146
- let(:paths_and_urls) do
147
- %w(
148
- http://www.foobar.com/foo
149
- http://www.foobar.com/foo/
150
- /foo
151
- /foo/
152
- http://www.foobar.com/foo?foo=bar
153
- http://www.foobar.com/foo/?foo=bar
154
- /foo?foo=bar
155
- /foo/?foo=bar
156
- http://www.foobar.com/foo#foo
157
- http://www.foobar.com/foo/#foo
158
- /foo#foo
159
- /foo/#foo
160
- http://www.foobar.com/foo#foo?foo=bar
161
- http://www.foobar.com/foo/#foo?foo=bar
162
- /foo#foo?foo=bar
163
- /foo/#foo?foo=bar
164
- )
165
- end
166
- end
167
-
168
- context 'with list item options' do
169
- it 'generates the correct HTML' do
170
- BootstrapNavbar.current_url_method = '"/"'
171
- subject.menu_item('foo', '/', class: 'bar', id: 'baz').should have_tag(:li, with: { class: 'active bar', id: 'baz' })
172
- end
173
- end
174
-
175
- context 'with link options' do
176
- it 'generates the correct HTML' do
177
- BootstrapNavbar.current_url_method = '"/"'
178
- subject.menu_item('foo', '/', {}, class: 'pelle', id: 'fant').should have_tag(:li, with: { class: 'active' }) do
179
- with_tag :a, with: { href: '/', class: 'pelle', id: 'fant' }, content: 'foo'
180
- end
181
- end
182
- end
183
-
184
- context 'with list item options and link options' do
185
- it 'generates the correct HTML' do
186
- BootstrapNavbar.current_url_method = '"/"'
187
- subject.menu_item('foo', '/', { class: 'bar', id: 'baz' }, class: 'pelle', id: 'fant').should have_tag(:li, with: { class: 'active bar', id: 'baz' }) do
188
- with_tag :a, with: { href: '/', class: 'pelle', id: 'fant' }, content: 'foo'
189
- end
190
- end
191
- end
192
- end
193
-
194
- context 'without current URL' do
195
- it 'generates the correct HTML' do
196
- BootstrapNavbar.current_url_method = '"/foo"'
197
- subject.menu_item('foo').should have_tag(:li, without: { class: 'active' }) do
198
- with_tag :a, with: { href: '#' }, content: 'foo'
199
- end
200
- subject.menu_item('foo', '/').should have_tag(:li, without: { class: 'active' }) do
201
- with_tag :a, with: { href: '/' }, content: 'foo'
202
- end
203
- subject.menu_item('foo', '/bar').should have_tag(:li, without: { class: 'active' }) do
204
- with_tag :a, with: { href: '/bar' }, content: 'foo'
205
- end
206
-
207
- BootstrapNavbar.current_url_method = '"/"'
208
- subject.menu_item('foo', '/foo').should have_tag(:li, without: { class: 'active' }) do
209
- with_tag :a, with: { href: '/foo' }, content: 'foo'
210
- end
211
- end
212
-
213
- context 'with list item options' do
214
- it 'generates the correct HTML' do
215
- BootstrapNavbar.current_url_method = '"/foo"'
216
- subject.menu_item('foo', '/', class: 'bar', id: 'baz').should have_tag(:li, without: { class: 'active' }, with: { class: 'bar', id: 'baz' })
217
- end
218
- end
219
- end
220
-
221
- context 'with a block' do
222
- it 'generates the correct HTML' do
223
- subject.menu_item { 'bar' }.should have_tag(:li) do
224
- with_tag :a, with: { href: '#' }, content: 'bar'
225
- end
226
- end
227
-
228
- context 'with list item options' do
229
- it 'generates the correct HTML' do
230
- subject.menu_item('/foo', class: 'pelle', id: 'fant') { 'bar' }.should have_tag(:li, with: { class: 'pelle', id: 'fant' }) do
231
- with_tag :a, with: { href: '/foo' }, content: 'bar'
232
- end
233
- end
234
- end
235
-
236
- context 'with link options' do
237
- it 'generates the correct HTML' do
238
- subject.menu_item('/foo', {}, class: 'pelle', id: 'fant') { 'bar' }.should have_tag(:li) do
239
- with_tag :a, with: { href: '/foo', class: 'pelle', id: 'fant' }, content: 'bar'
240
- end
241
- end
242
- end
243
-
244
- context 'with list item options and link options' do
245
- it 'generates the correct HTML' do
246
- subject.menu_item('/foo', { class: 'bar', id: 'baz' }, class: 'pelle', id: 'fant') { 'shnoo' }.should have_tag(:li, with: { class: 'bar', id: 'baz' }) do
247
- with_tag :a, with: { href: '/foo', class: 'pelle', id: 'fant' }, content: 'shnoo'
248
- end
249
- end
250
- end
251
- end
252
- end
253
-
254
- context 'drop downs' do
255
- def with_drop_down_menu(content = nil)
256
- options = { with: { class: 'dropdown-menu' } }
257
- options[:content] = content unless content.nil?
258
- with_tag :ul, options
259
- end
260
-
261
- describe '#drop_down' do
262
- it 'generates the correct HTML' do
263
- subject.drop_down('foo').should have_tag(:li, with: { class: 'dropdown' }) do
264
- with_tag :a, with: { href: '#', class: 'dropdown-toggle', :'data-toggle' => 'dropdown' } do
265
- with_text /foo/
266
- with_tag :b, with: { class: 'caret' }
267
- end
268
- with_drop_down_menu
269
- end
270
-
271
- subject.drop_down('foo') { 'bar' }.should have_tag(:li, with: { class: 'dropdown' }) do
272
- with_tag :a, with: { href: '#', class: 'dropdown-toggle', :'data-toggle' => 'dropdown' } do
273
- with_text /foo/
274
- with_tag :b, with: { class: 'caret' }
275
- end
276
- with_drop_down_menu('bar')
277
- end
278
- end
279
- end
280
-
281
- describe '#sub_drop_down' do
282
- it 'generates the correct HTML' do
283
- subject.sub_drop_down('foo').should have_tag(:li, with: { class: 'dropdown-submenu' }) do
284
- with_tag :a, with: { href: '#' }, content: 'foo'
285
- with_drop_down_menu
286
- end
287
-
288
- subject.sub_drop_down('foo') { 'bar' }.should have_tag(:li, with: { class: 'dropdown-submenu' }) do
289
- with_tag :a, with: { href: '#' }, content: 'foo'
290
- with_drop_down_menu('bar')
291
- end
292
- end
293
-
294
- context 'with list item options' do
295
- it 'generates the correct HTML' do
296
- subject.sub_drop_down('foo', class: 'bar', id: 'baz').should have_tag(:li, with: { class: 'dropdown-submenu bar', id: 'baz' }) do
297
- with_tag :a, with: { href: '#' }, content: 'foo'
298
- end
299
- end
300
- end
301
-
302
- context 'with link options' do
303
- it 'generates the correct HTML' do
304
- subject.sub_drop_down('foo', {}, class: 'pelle', id: 'fant').should have_tag(:li, with: { class: 'dropdown-submenu' }) do
305
- with_tag :a, with: { href: '#', class: 'pelle', id: 'fant' }, content: 'foo'
306
- end
307
- end
308
- end
309
-
310
- context 'with list item options and link options' do
311
- it 'generates the correct HTML' do
312
- subject.sub_drop_down('foo', { class: 'bar', id: 'baz' }, class: 'pelle', id: 'fant').should have_tag(:li, with: { class: 'dropdown-submenu bar', id: 'baz' }) do
313
- with_tag :a, with: { href: '#', class: 'pelle', id: 'fant' }, content: 'foo'
314
- end
315
- end
316
- end
317
- end
318
- end
319
-
320
- describe '#drop_down_divider' do
321
- it 'generates the correct HTML' do
322
- subject.drop_down_divider.should have_tag(:li, with: { class: 'divider' }, content: '')
323
- end
324
- end
325
-
326
- describe '#drop_down_header' do
327
- it 'generates the correct HTML' do
328
- subject.drop_down_header('foo').should have_tag(:li, with: { class: 'nav-header' }, content: 'foo')
329
- end
330
- end
331
-
332
- describe '#menu_divider' do
333
- it 'generates the correct HTML' do
334
- subject.menu_divider.should have_tag(:li, with: { class: 'divider-vertical' }, content: '')
335
- end
336
- end
337
-
338
- describe '#menu_text' do
339
- it 'generates the correct HTML' do
340
- subject.menu_text('foo').should have_tag(:p, with: { class: 'navbar-text' }, content: 'foo')
341
- subject.menu_text { 'foo' }.should have_tag(:p, with: { class: 'navbar-text' }, content: 'foo')
342
- subject.menu_text('foo', 'right').should have_tag(:p, with: { class: 'navbar-text pull-right' }, content: 'foo')
343
- subject.menu_text(nil, 'left') { 'foo' }.should have_tag(:p, with: { class: 'navbar-text pull-left' }, content: 'foo')
344
- end
345
- end
346
-
347
- describe '#brand_link' do
348
- it 'generates the correct HTML' do
349
- subject.brand_link('foo').should have_tag(:a, with: { class: 'brand', href: '/' }, content: 'foo')
350
- subject.brand_link('foo', '/foo').should have_tag(:a, with: { class: 'brand', href: '/foo' }, content: 'foo')
351
- end
352
- end
353
- end