rails_bootstrap_navbar 0.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +296 -0
- data/Rakefile +6 -0
- data/lib/rails_bootstrap_navbar.rb +3 -0
- data/lib/rails_bootstrap_navbar/railtie.rb +8 -0
- data/lib/rails_bootstrap_navbar/version.rb +3 -0
- data/lib/rails_bootstrap_navbar/view_helpers.rb +115 -0
- data/rails_bootstrap_navbar.gemspec +20 -0
- data/spec/lib/rails_bootstrap_navbar/view_helpers_spec.rb +267 -0
- data/spec/spec_helper.rb +1 -0
- metadata +84 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 jules@julescopeland.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,296 @@
|
|
1
|
+
# RailsBootstrapNavbar
|
2
|
+
|
3
|
+
The idea behind this gem is to make a really easy to use DSL for writing navbars for your rails apps, assuming you're already using Twitter Bootstrap >= 2.0 and Erb (It shouldn't make any difference how you ultimately get bootstrap into your app - i.e. through the sass-bootstrap gem, manually downloading the complied source, magic, whatever...). Just remember to include the javascript if you want things like dropdowns or responsive layouts.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rails_bootstrap_navbar'
|
10
|
+
|
11
|
+
...
|
12
|
+
# You need some form of Twitter bootstrap integration as well (I use Thomas McDonald's excellent [bootstrap-sass](https://github.com/thomas-mcdonald))
|
13
|
+
...
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rails_bootstrap_navbar
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
This gem aims to automate all of the features currently mentioned on the [twitter bootstrap docs re. the navbar](http://twitter.github.com/bootstrap/components.html#navbar).
|
26
|
+
|
27
|
+
It should let you write things like:
|
28
|
+
|
29
|
+
````ruby
|
30
|
+
<%= nav_bar :fixed => :top, :brand => "Fashionable Clicheizr 2.0", :responsive => true do %>
|
31
|
+
<%= menu_group do %>
|
32
|
+
<%= menu_item "Home", root_path %>
|
33
|
+
<%= menu_divider %>
|
34
|
+
<%= drop_down "Products" do %>
|
35
|
+
<%= menu_item "Things you can't afford", expensive_products_path %>
|
36
|
+
<%= menu_item "Things that won't suit you anyway", harem_pants_path %>
|
37
|
+
<%= menu_item "Things you're not even cool enough to buy anyway", hipster_products_path %>
|
38
|
+
<% if current_user.lives_in_hackney? %>
|
39
|
+
<%= menu_item "Bikes", fixed_wheel_bikes_path %>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
42
|
+
<%= menu_item "About Us", about_us_path %>
|
43
|
+
<%= menu_item "Contact", contact_path %>
|
44
|
+
<% end %>
|
45
|
+
<%= menu_group :pull => :right do %>
|
46
|
+
<% if current_user %>
|
47
|
+
<%= menu_item "Log Out", log_out_path %>
|
48
|
+
<% else %>
|
49
|
+
<%= form_for @user, :url => session_path(:user), html => {:class=> "navbar-form pull-right"} do |f| -%>
|
50
|
+
<p><%= f.text_field :email %></p>
|
51
|
+
<p><%= f.password_field :password %></p>
|
52
|
+
<p><%= f.submit "Sign in" %></p>
|
53
|
+
<% end -%>
|
54
|
+
<% end %>
|
55
|
+
<% end %>
|
56
|
+
<% end %>
|
57
|
+
````
|
58
|
+
|
59
|
+
### Navbar scaffolding
|
60
|
+
|
61
|
+
In your view file (most likely application.html.erb) to get a basic navbar set up you need to do this:
|
62
|
+
|
63
|
+
````ruby
|
64
|
+
<%= nav_bar %>
|
65
|
+
````
|
66
|
+
|
67
|
+
Which will render:
|
68
|
+
````html
|
69
|
+
<div class="navbar">
|
70
|
+
<div class="navbar-inner">
|
71
|
+
<div class="container">
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
````
|
76
|
+
|
77
|
+
### Fixed navbar
|
78
|
+
|
79
|
+
If you want the navbar to stick to the top or the bottom of the screen, pass in the option like this:
|
80
|
+
|
81
|
+
````ruby
|
82
|
+
<%= nav_bar :fixed => :top %>
|
83
|
+
````
|
84
|
+
|
85
|
+
Or
|
86
|
+
|
87
|
+
````ruby
|
88
|
+
<%= nav_bar :fixed => :top %>
|
89
|
+
````
|
90
|
+
|
91
|
+
To render:
|
92
|
+
````html
|
93
|
+
<div class="navbar navbar-fixed-top">
|
94
|
+
<div class="navbar-inner">
|
95
|
+
<div class="container">
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
````
|
100
|
+
|
101
|
+
Or
|
102
|
+
|
103
|
+
````html
|
104
|
+
<div class="navbar navbar-fixed-bottom">
|
105
|
+
<div class="navbar-inner">
|
106
|
+
<div class="container">
|
107
|
+
</div>
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
````
|
111
|
+
|
112
|
+
|
113
|
+
### Brand name
|
114
|
+
|
115
|
+
Add the name of your site on the left hand edge of the navbar. At the moment, it will only link to root_url
|
116
|
+
|
117
|
+
````ruby
|
118
|
+
<%= nav_bar :brand => "We're sooo web 2.0alizr" %>
|
119
|
+
````
|
120
|
+
|
121
|
+
Which will render:
|
122
|
+
````html
|
123
|
+
<div class="navbar">
|
124
|
+
<div class="navbar-inner">
|
125
|
+
<div class="container">
|
126
|
+
<a class="brand" href="/">
|
127
|
+
We're sooo web 2.0alizr
|
128
|
+
</a>
|
129
|
+
</div>
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
````
|
133
|
+
|
134
|
+
### Optional responsive variation
|
135
|
+
|
136
|
+
If you want the responsive version of the navbar to work (One that shrinks down on mobile devices etc.), you need to pass this option:
|
137
|
+
|
138
|
+
````ruby
|
139
|
+
<%= nav_bar :responsive => true %>
|
140
|
+
````
|
141
|
+
Which renders the html quite differently:
|
142
|
+
|
143
|
+
````html
|
144
|
+
<div class="navbar">
|
145
|
+
<div class="navbar-inner">
|
146
|
+
<div class="container">
|
147
|
+
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
|
148
|
+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
149
|
+
<span class="icon-bar"></span>
|
150
|
+
<span class="icon-bar"></span>
|
151
|
+
<span class="icon-bar"></span>
|
152
|
+
</a>
|
153
|
+
<!-- Everything in here gets hidden at 940px or less -->
|
154
|
+
<div class="nav-collapse">
|
155
|
+
<!-- menu items gets rendered here instead -->
|
156
|
+
</div>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
````
|
161
|
+
|
162
|
+
### Nav links
|
163
|
+
|
164
|
+
This is the 'meat' of the code where you define your menu items.
|
165
|
+
|
166
|
+
You can group menu items in theoretical boxes which you can apply logic to - e.g. show different collections for logged in users/logged out users, or simply right align a group.
|
167
|
+
|
168
|
+
The active menu item will be inferred from the link for now.
|
169
|
+
|
170
|
+
````ruby
|
171
|
+
<%= nav_bar :fixed => :top, :brand => "Ninety Ten" do %>
|
172
|
+
<% menu_group do %>
|
173
|
+
<%= menu_item "Home", root_path %>
|
174
|
+
<%= menu_item "About Us", about_us_path %>
|
175
|
+
<%= menu_item "Contact", contact_path %>
|
176
|
+
<% end %>
|
177
|
+
<% if current_user %>
|
178
|
+
<%= menu_item "Log Out", log_out_path %>
|
179
|
+
<% else %>
|
180
|
+
<% menu_group :pull => :right do %>
|
181
|
+
<%= menu_item "Sign Up", registration_path %>
|
182
|
+
<% form_for @user, :url => session_path(:user) do |f| -%>
|
183
|
+
<p><%= f.text_field :email %></p>
|
184
|
+
<p><%= f.password_field :password %></p>
|
185
|
+
<p><%= f.submit "Sign in" %></p>
|
186
|
+
<% end -%>
|
187
|
+
<% end %>
|
188
|
+
<% end %>
|
189
|
+
<% end %>
|
190
|
+
````
|
191
|
+
|
192
|
+
### Dropdown menus
|
193
|
+
|
194
|
+
For multi-level list options, where it makes logical sense to group menu items, or simply to save space if you have a lot of pages, you can group menu items into drop down lists like this:
|
195
|
+
|
196
|
+
````ruby
|
197
|
+
<%= nav_bar do %>
|
198
|
+
<%= menu_item "Home", root_path %>
|
199
|
+
|
200
|
+
<%= drop_down "Products" do %>
|
201
|
+
<%= menu_item "Latest", latest_products_path %>
|
202
|
+
<%= menu_item "Top Sellers", popular_products_path %>
|
203
|
+
<%= menu_item "Discount Items", discounted_products_path %>
|
204
|
+
<% end %>
|
205
|
+
|
206
|
+
<%= menu_item "About Us", about_us_path %>
|
207
|
+
<%= menu_item "Contact", contact_path %>
|
208
|
+
<% end %>
|
209
|
+
````
|
210
|
+
|
211
|
+
### Dividers
|
212
|
+
|
213
|
+
Dividers are just vertical bars that visually separate logically disparate groups of menu items
|
214
|
+
|
215
|
+
````ruby
|
216
|
+
<%= nav_bar :fixed => :bottom do %>
|
217
|
+
<%= menu_item "Home", root_path %>
|
218
|
+
<%= menu_item "About Us", about_us_path %>
|
219
|
+
<%= menu_item "Contact", contact_path %>
|
220
|
+
|
221
|
+
<%= menu_divider %>
|
222
|
+
|
223
|
+
<%= menu_item "Edit Profile", edit_user_path(current_user) %>
|
224
|
+
<%= menu_item "Account Settings", edit_user_account_path(current_user, @account) %>
|
225
|
+
<%= menu_item "Log Out", log_out_path %>
|
226
|
+
<% end %>
|
227
|
+
````
|
228
|
+
|
229
|
+
### Forms in navbar
|
230
|
+
|
231
|
+
At the moment - this is just a how to...
|
232
|
+
|
233
|
+
You need to add this class to the form itself (Different form builders do this in different ways - please check out the relevant docs)
|
234
|
+
|
235
|
+
````css
|
236
|
+
.navbar-form
|
237
|
+
````
|
238
|
+
To pull the form left or right, add either of these classes:
|
239
|
+
````css
|
240
|
+
.pull-left
|
241
|
+
.pull-right
|
242
|
+
````
|
243
|
+
|
244
|
+
If you want the Bootstrap search box (I think it just rounds the corners), use:
|
245
|
+
````css
|
246
|
+
.navbar-search
|
247
|
+
````
|
248
|
+
Instead of:
|
249
|
+
````css
|
250
|
+
.navbar-form
|
251
|
+
````
|
252
|
+
|
253
|
+
To change the size of the form fields, use .span2 (or however many span widths you want) to the input itself.
|
254
|
+
|
255
|
+
### Component alignment
|
256
|
+
|
257
|
+
You can shift things to the left or the right across the nav bar. It's easiest to do this on grouped menu items:
|
258
|
+
|
259
|
+
````ruby
|
260
|
+
<%= nav_bar :fixed => :bottom do %>
|
261
|
+
<% menu_group do %>
|
262
|
+
<%= menu_item "Home", root_path %>
|
263
|
+
<%= menu_item "About Us", about_us_path %>
|
264
|
+
<%= menu_item "Contact", contact_path %>
|
265
|
+
<% end %>
|
266
|
+
<% menu_group :pull => :right do %>
|
267
|
+
<%= menu_item "Edit Profile", edit_user_path(current_user) %>
|
268
|
+
<%= menu_item "Account Settings", edit_user_account_path(current_user, @account) %>
|
269
|
+
<%= menu_item "Log Out", log_out_path %>
|
270
|
+
<% end %>
|
271
|
+
<% end %>
|
272
|
+
````
|
273
|
+
|
274
|
+
### Text in the navbar
|
275
|
+
|
276
|
+
If you want to put regualr plain text in the navbar anywhere, you do it like this:
|
277
|
+
|
278
|
+
````ruby
|
279
|
+
<%= nav_bar :brand => "Apple" do %>
|
280
|
+
<%= menu_text "We make shiny things" %>
|
281
|
+
<%= menu_item "Home", root_path %>
|
282
|
+
<%= menu_item "About Us", about_us_path %>
|
283
|
+
<% end %>
|
284
|
+
````
|
285
|
+
|
286
|
+
## Contributing
|
287
|
+
|
288
|
+
This is my first ever published gem - so please feel free to pull it apart and fix bits that are dumb. One of my biggest problems was getting Rspec to test it properly (only just bitten the bullet and gone full TDD). Cleaning up the specs would be a good place to start.
|
289
|
+
|
290
|
+
I'm guessing also that there's a much nicer way of doing the whole thing using Rails' form_builder approach, but this was where TDD got me...
|
291
|
+
|
292
|
+
1. Fork it
|
293
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
294
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
295
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
296
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require "rails_bootstrap_navbar/version"
|
2
|
+
|
3
|
+
module RailsBootstrapNavbar
|
4
|
+
module ViewHelpers
|
5
|
+
|
6
|
+
def nav_bar(options={}, &block)
|
7
|
+
nav_bar_div(options[:fixed]) do
|
8
|
+
navbar_inner_div do
|
9
|
+
container_div(options[:brand], options[:responsive], options[:fluid]) do
|
10
|
+
yield if block_given?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def menu_group(options={}, &block)
|
17
|
+
pull_class = " pull-#{options[:pull].to_s}" if options[:pull].present?
|
18
|
+
content_tag(:ul, :class => "nav#{pull_class}", &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def menu_item(name, path)
|
22
|
+
content_tag :li, :class => is_active?(path) do
|
23
|
+
link_to name, path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def drop_down(name)
|
28
|
+
content_tag :li, :class => "dropdown" do
|
29
|
+
drop_down_link(name) + drop_down_list {yield}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def menu_divider
|
34
|
+
content_tag :li, "", :class => "divider-vertical"
|
35
|
+
end
|
36
|
+
|
37
|
+
def menu_text(text=nil, &block)
|
38
|
+
content_tag :p do
|
39
|
+
text || yield
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def nav_bar_div(fixed, &block)
|
46
|
+
content_tag :div, :class => nav_bar_css_class(fixed) do
|
47
|
+
yield
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def navbar_inner_div(&block)
|
52
|
+
content_tag :div, :class => "navbar-inner" do
|
53
|
+
yield
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def container_div(brand, responsive, fluid, &block)
|
58
|
+
content_tag :div, :class => "container#{"-fluid" if fluid}" do
|
59
|
+
container_div_with_block(brand, responsive, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def container_div_with_block(brand, responsive, &block)
|
64
|
+
output = []
|
65
|
+
if responsive == true
|
66
|
+
output << responsive_button
|
67
|
+
output << brand_link(brand)
|
68
|
+
output << responsive_div {capture(&block)}
|
69
|
+
else
|
70
|
+
output << brand_link(brand)
|
71
|
+
output << capture(&block)
|
72
|
+
end
|
73
|
+
output.join("\n").html_safe
|
74
|
+
end
|
75
|
+
|
76
|
+
def nav_bar_css_class(fixed_pos)
|
77
|
+
css_class = ["navbar"]
|
78
|
+
css_class << "navbar-fixed-#{fixed_pos.to_s}" if fixed_pos.present?
|
79
|
+
css_class.join(" ")
|
80
|
+
end
|
81
|
+
|
82
|
+
def brand_link(name)
|
83
|
+
return "" if name.blank?
|
84
|
+
link_to(name, "/", :class => "brand")
|
85
|
+
end
|
86
|
+
|
87
|
+
def responsive_button
|
88
|
+
%{<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
89
|
+
<span class="icon-bar"></span>
|
90
|
+
<span class="icon-bar"></span>
|
91
|
+
<span class="icon-bar"></span>
|
92
|
+
</a>}
|
93
|
+
end
|
94
|
+
|
95
|
+
def responsive_div(&block)
|
96
|
+
content_tag(:div, :class => "nav-collapse", &block)
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_active?(path)
|
100
|
+
"active" if current_page?(path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def name_and_caret(name)
|
104
|
+
"#{name} #{content_tag(:b, :class => "caret"){}}".html_safe
|
105
|
+
end
|
106
|
+
|
107
|
+
def drop_down_link(name)
|
108
|
+
link_to(name_and_caret(name), "#", :class => "dropdown-toggle", "data-toggle" => "dropdown")
|
109
|
+
end
|
110
|
+
|
111
|
+
def drop_down_list(&block)
|
112
|
+
content_tag :ul, :class => "dropdown-menu", &block
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rails_bootstrap_navbar/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jules Copeland"]
|
6
|
+
gem.email = ["jules@julescopeland.com"]
|
7
|
+
gem.description = %q{A helper method for easy generation of Twitter Bootstrap Navigation menus in Rails}
|
8
|
+
gem.summary = %q{Generate Bootstrap Navbars in Rails views}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rails_bootstrap_navbar"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RailsBootstrapNavbar::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'action_view'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
include RailsBootstrapNavbar::ViewHelpers
|
7
|
+
include ActionView::Helpers
|
8
|
+
include ActionView::Context
|
9
|
+
|
10
|
+
describe RailsBootstrapNavbar::ViewHelpers, :type => :helper do
|
11
|
+
before { self.stub!("current_page?").and_return(false) }
|
12
|
+
describe "nav_bar" do
|
13
|
+
it "should return a basic bootstrap navbar" do
|
14
|
+
nav_bar.gsub(/\s/,'').downcase.should eql(BASIC_NAVBAR.gsub(/\s/,'').downcase)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set the fixed position to top" do
|
18
|
+
nav_bar(:fixed => :top).gsub(/\s/,'').downcase.should eql(FIXED_TOP_NAVBAR.gsub(/\s/,'').downcase)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set the fixed position to bottom" do
|
22
|
+
nav_bar(:fixed => :bottom).gsub(/\s/,'').downcase.should eql(FIXED_BOTTOM_NAVBAR.gsub(/\s/,'').downcase)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should add the brand name and link it to the home page" do
|
26
|
+
nav_bar(:brand => "Ninety Ten").gsub(/\s/,'').downcase.should eql(NAVBAR_WITH_BRAND.gsub(/\s/,'').downcase)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the container to fluid" do
|
30
|
+
nav_bar(:fluid => :true).gsub(/\s/,'').downcase.should eql(BASIC_NAVBAR_FLUID.gsub(/\s/,'').downcase)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should add the buttons etc for a responsive layout with no block passed" do
|
34
|
+
nav_bar(:responsive => true).gsub(/\s/,'').downcase.should eql(RESPONSIVE_NAVBAR.gsub(/\s/,'').downcase)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add the buttons etc for a responsive layout with block passed" do
|
38
|
+
nav_bar(:responsive => true) do
|
39
|
+
"<p>Passing a block</p>".html_safe
|
40
|
+
end.gsub(/\s/,'').downcase.should eql(RESPONSIVE_NAVBAR_WITH_BLOCK.gsub(/\s/,'').downcase)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should render contained items" do
|
44
|
+
nav_bar do
|
45
|
+
menu_group do
|
46
|
+
menu_item("Home", "/") + menu_item("Products", "/products")
|
47
|
+
end
|
48
|
+
end.gsub(/\s/,'').downcase.should eql(PLAIN_NAVBAR_WITH_ITEM.gsub(/\s/,'').downcase)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should still render the brand name even with other options turned on" do
|
52
|
+
nav_bar(:brand => "Something") do
|
53
|
+
menu_group do
|
54
|
+
menu_item "Home", "/"
|
55
|
+
end
|
56
|
+
end.gsub(/\s/,'').downcase.should eql(BRANDED_NAVBAR_WITH_ITEM.gsub(/\s/,'').downcase)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "menu_group" do
|
61
|
+
it "should return a ul with the class 'nav'" do
|
62
|
+
menu_group do
|
63
|
+
menu_item("Home", "/") + menu_item("Products", "/products")
|
64
|
+
end.should eql '<ul class="nav"><li><a href="/">Home</a></li><li><a href="/products">Products</a></li></ul>'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return a ul with class .pull-left when passed the {:pull => :left} option" do
|
68
|
+
menu_group(:pull => :left) do
|
69
|
+
menu_item("Home", "/")
|
70
|
+
end.should eql('<ul class="nav pull-left"><li><a href="/">Home</a></li></ul>')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "menu_item" do
|
75
|
+
it "should return a link within an li tag" do
|
76
|
+
self.stub!("current_page?").and_return(false)
|
77
|
+
menu_item("Home", "/").should eql('<li><a href="/">Home</a></li>')
|
78
|
+
end
|
79
|
+
it "should return the link with class 'active' if on current page" do
|
80
|
+
self.stub!("current_page?").and_return(true)
|
81
|
+
menu_item("Home", "/").should eql('<li class="active"><a href="/">Home</a></li>')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "drop_down" do
|
86
|
+
it "should do render the proper drop down code" do
|
87
|
+
drop_down "Products" do
|
88
|
+
menu_item "Latest", "/"
|
89
|
+
end.gsub(/\s/,'').downcase.should eql(DROPDOWN_MENU.gsub(/\s/,'').downcase)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "menu_divider" do
|
94
|
+
it "should render <li class='divider-vertical'></li>" do
|
95
|
+
menu_divider.should eql '<li class="divider-vertical"></li>'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "menu_text" do
|
100
|
+
it "should render text within p tags" do
|
101
|
+
menu_text("Strapline!").should eql("<p>Strapline!</p>")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should be able to cope with a block too" do
|
105
|
+
menu_text do
|
106
|
+
"I've been rendered programmatically!"
|
107
|
+
end.should eql("<p>I've been rendered programmatically!</p>")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "rendering forms ok" do
|
112
|
+
it "should not escape anything unexpectedly" do
|
113
|
+
nav_bar do
|
114
|
+
form_tag "/", :method => 'get' do |f|
|
115
|
+
f.text_field :search, "stub"
|
116
|
+
end
|
117
|
+
end.gsub(/\s/,'').downcase.should eql(PLAIN_NAVBAR_WITH_FORM.gsub(/\s/,'').downcase)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
# HTML output
|
124
|
+
|
125
|
+
BASIC_NAVBAR = <<-HTML
|
126
|
+
<div class="navbar">
|
127
|
+
<div class="navbar-inner">
|
128
|
+
<div class="container">
|
129
|
+
</div>
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
HTML
|
133
|
+
|
134
|
+
FIXED_TOP_NAVBAR = <<-HTML
|
135
|
+
<div class="navbar navbar-fixed-top">
|
136
|
+
<div class="navbar-inner">
|
137
|
+
<div class="container">
|
138
|
+
</div>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
HTML
|
142
|
+
|
143
|
+
FIXED_BOTTOM_NAVBAR = <<-HTML
|
144
|
+
<div class="navbar navbar-fixed-bottom">
|
145
|
+
<div class="navbar-inner">
|
146
|
+
<div class="container">
|
147
|
+
</div>
|
148
|
+
</div>
|
149
|
+
</div>
|
150
|
+
HTML
|
151
|
+
|
152
|
+
BASIC_NAVBAR_FLUID= <<-HTML
|
153
|
+
<div class="navbar">
|
154
|
+
<div class="navbar-inner">
|
155
|
+
<div class="container-fluid">
|
156
|
+
</div>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
HTML
|
160
|
+
|
161
|
+
NAVBAR_WITH_BRAND = <<-HTML
|
162
|
+
<div class="navbar">
|
163
|
+
<div class="navbar-inner">
|
164
|
+
<div class="container">
|
165
|
+
<a href="/" class="brand">
|
166
|
+
Ninety Ten
|
167
|
+
</a>
|
168
|
+
</div>
|
169
|
+
</div>
|
170
|
+
</div>
|
171
|
+
HTML
|
172
|
+
|
173
|
+
RESPONSIVE_NAVBAR = <<-HTML
|
174
|
+
<div class="navbar">
|
175
|
+
<div class="navbar-inner">
|
176
|
+
<div class="container">
|
177
|
+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
178
|
+
<span class="icon-bar"></span>
|
179
|
+
<span class="icon-bar"></span>
|
180
|
+
<span class="icon-bar"></span>
|
181
|
+
</a>
|
182
|
+
<div class="nav-collapse">
|
183
|
+
</div>
|
184
|
+
</div>
|
185
|
+
</div>
|
186
|
+
</div>
|
187
|
+
HTML
|
188
|
+
|
189
|
+
RESPONSIVE_NAVBAR_WITH_BLOCK = <<-HTML
|
190
|
+
<div class="navbar">
|
191
|
+
<div class="navbar-inner">
|
192
|
+
<div class="container">
|
193
|
+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
194
|
+
<span class="icon-bar"></span>
|
195
|
+
<span class="icon-bar"></span>
|
196
|
+
<span class="icon-bar"></span>
|
197
|
+
</a>
|
198
|
+
<div class="nav-collapse">
|
199
|
+
<p>Passing a block</p>
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
</div>
|
203
|
+
</div>
|
204
|
+
HTML
|
205
|
+
|
206
|
+
PLAIN_NAVBAR_WITH_ITEM = <<-HTML
|
207
|
+
<div class="navbar">
|
208
|
+
<div class="navbar-inner">
|
209
|
+
<div class="container">
|
210
|
+
<ul class="nav">
|
211
|
+
<li>
|
212
|
+
<a href="/">Home</a>
|
213
|
+
</li>
|
214
|
+
<li>
|
215
|
+
<a href="/products">Products</a>
|
216
|
+
</li>
|
217
|
+
</ul>
|
218
|
+
</div>
|
219
|
+
</div>
|
220
|
+
</div>
|
221
|
+
HTML
|
222
|
+
|
223
|
+
BRANDED_NAVBAR_WITH_ITEM = <<-HTML
|
224
|
+
<div class="navbar">
|
225
|
+
<div class="navbar-inner">
|
226
|
+
<div class="container">
|
227
|
+
<a href="/" class="brand">
|
228
|
+
Something
|
229
|
+
</a>
|
230
|
+
<ul class="nav">
|
231
|
+
<li>
|
232
|
+
<a href="/">Home</a>
|
233
|
+
</li>
|
234
|
+
</ul>
|
235
|
+
</div>
|
236
|
+
</div>
|
237
|
+
</div>
|
238
|
+
HTML
|
239
|
+
|
240
|
+
DROPDOWN_MENU = <<-HTML
|
241
|
+
<li class="dropdown">
|
242
|
+
<a href="#"
|
243
|
+
class="dropdown-toggle"
|
244
|
+
data-toggle="dropdown">
|
245
|
+
Products
|
246
|
+
<b class="caret"></b>
|
247
|
+
</a>
|
248
|
+
<ul class="dropdown-menu">
|
249
|
+
<li><a href="/">Latest</a></li>
|
250
|
+
</ul>
|
251
|
+
</li>
|
252
|
+
HTML
|
253
|
+
|
254
|
+
PLAIN_NAVBAR_WITH_FORM = <<-HTML
|
255
|
+
<div class="navbar">
|
256
|
+
<div class="navbar-inner">
|
257
|
+
<div class="container">
|
258
|
+
<form accept-charset="utf-8" action="/" method="get">
|
259
|
+
<div style="margin:0;padding:0;display:inline">
|
260
|
+
<input name="utf8" type="hidden" value="✓"/>
|
261
|
+
</div>
|
262
|
+
<input id="search_stub" name="search[stub]" size="30" type="text"/>
|
263
|
+
</form>
|
264
|
+
</div>
|
265
|
+
</div>
|
266
|
+
</div>
|
267
|
+
HTML
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_bootstrap_navbar'
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_bootstrap_navbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.beta
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jules Copeland
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70186376954320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70186376954320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70186376953820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70186376953820
|
36
|
+
description: A helper method for easy generation of Twitter Bootstrap Navigation menus
|
37
|
+
in Rails
|
38
|
+
email:
|
39
|
+
- jules@julescopeland.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- CHANGELOG.md
|
47
|
+
- Gemfile
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/rails_bootstrap_navbar.rb
|
52
|
+
- lib/rails_bootstrap_navbar/railtie.rb
|
53
|
+
- lib/rails_bootstrap_navbar/version.rb
|
54
|
+
- lib/rails_bootstrap_navbar/view_helpers.rb
|
55
|
+
- rails_bootstrap_navbar.gemspec
|
56
|
+
- spec/lib/rails_bootstrap_navbar/view_helpers_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>'
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.1
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.10
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Generate Bootstrap Navbars in Rails views
|
82
|
+
test_files:
|
83
|
+
- spec/lib/rails_bootstrap_navbar/view_helpers_spec.rb
|
84
|
+
- spec/spec_helper.rb
|