Skip to content

Commit be08a98

Browse files
committed
Append option :header_class for <li> in tabs helper.
1 parent 9d9645d commit be08a98

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

lib/bootstrap-components-helpers/tabs_helper.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ def initialize parent
2424
@pane_contents = []
2525
end
2626

27+
# options[:header_class] - class for header's <li>
2728
def pane title, options = {}, &block
2829
css_class = options[:active] ? 'active' : ''
2930
link = content_tag(:a, title, :'data-toggle' => 'tab', :href => "##{title.parameterize}_tab")
30-
@pane_handles << [link, css_class]
31+
header_class = [css_class.presence, options[:header_class]].compact.join(' ')
32+
@pane_handles << [link, header_class]
3133
@pane_contents << [css_class, title, capture(&block)]
3234
nil
3335
end
34-
36+
3537
def pane_handles_html
3638
pane_handles.first[1] = 'active' unless pane_handles.detect {|ph| ph[1] == 'active'}
3739
pane_handles.map do |link, css_class|
3840
content_tag(:li, link, :class => css_class)
3941
end.join("\n").html_safe
4042
end
41-
43+
4244
def pane_contents_html
4345
pane_contents.first[0] = 'active' unless pane_contents.detect {|pc| pc[0] == 'active'}
4446
pane_contents.map do |css_class, title, content|
@@ -47,7 +49,7 @@ def pane_contents_html
4749
end
4850

4951
end
50-
52+
5153
end
5254
end
5355

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="tabbable "><ul class="nav nav-tabs"><li class="active my_item"><a data-toggle="tab" href="#my-first-pane_tab">My first pane</a></li></ul><div class="tab-content"><div class="tab-pane active" id="my-first-pane_tab">inside the pane</div></div></div>

test/test_tabs_helper.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'test_helper'
22

33
class TabsHelperTest < ActionView::TestCase
4-
4+
55
include BootstrapComponentsHelpers::TabsHelper
6-
6+
77
test "calling tabs method" do
88
html = tabs do |tabs|
99
tabs.pane 'My first pane' do
@@ -13,4 +13,13 @@ class TabsHelperTest < ActionView::TestCase
1313
assert_helper_output 'tabs', html
1414
end
1515

16+
test "calling tabs with header css" do
17+
html = tabs do |tabs|
18+
tabs.pane 'My first pane', :header_class=>'my_item' do
19+
'inside the pane'
20+
end
21+
end
22+
assert_helper_output 'tabs', html
23+
end
24+
1625
end

0 commit comments

Comments
 (0)