Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom class in nav_bar helper #894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/helpers/navbar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def nav_bar_nav(options, &block)
position = "static-#{options[:static].to_s}" if options[:static]
position = "fixed-#{options[:fixed].to_s}" if options[:fixed]
inverse = (options[:inverse].present? && options[:inverse] == true) ? true : false
classes = options[:class]

content_tag :nav, :class => nav_bar_css_class(position, inverse), :role => "navigation" do
content_tag :nav, :class => nav_bar_css_class(position, inverse, classes), :role => "navigation" do
yield
end
end
Expand Down Expand Up @@ -144,10 +145,11 @@ def responsive_nav_header(brand, brand_link, no_turbolink)
end
end

def nav_bar_css_class(position, inverse = false)
def nav_bar_css_class(position, inverse = false, classes=nil)
css_class = ["navbar", "navbar-default"]
css_class << "navbar-#{position}" if position.present?
css_class << "navbar-inverse" if inverse
css_class << classes
css_class.join(" ")
end

Expand Down
5 changes: 5 additions & 0 deletions spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@
with_tag(:a, text: " Home", with: { href: "/"})
}
end

it "should add custom class to navbar" do
expect(nav_bar(:class => "custom-class"))
.to have_tag(:nav, with: { class: 'custom-class' } )
end
end

describe "drop_down" do
Expand Down