From aed7bc14c7d5c19fe63920e96776dd8424119998 Mon Sep 17 00:00:00 2001 From: Anthony Leon Date: Sun, 3 Jan 2016 13:34:13 -1000 Subject: [PATCH] Allow custom class in nav_bar helper --- app/helpers/navbar_helper.rb | 6 ++++-- spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/helpers/navbar_helper.rb b/app/helpers/navbar_helper.rb index a6a01c02..a958a84c 100644 --- a/app/helpers/navbar_helper.rb +++ b/app/helpers/navbar_helper.rb @@ -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 @@ -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 diff --git a/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb b/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb index 9f11cbf8..8947ab62 100644 --- a/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +++ b/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb @@ -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