Permalink
Browse files

Added support for nested tabs and ability to pass a block to the #tab…

…_for method (#12, #9, #11).

Added more tests.
  • Loading branch information...
1 parent 1317fc2 commit ed0759aece59f1d51142a4a47a25313710fe7ff7 @weppos committed May 20, 2011
View
@@ -3,6 +3,12 @@
== master
+* NEW: Added support for nested tabs and ability
+ to pass a block to the #tab_for method (#12, #9, #11).
+
+ However, the default TabsBuilder builder does not implement it.
+ Create a custom builder and specify how the block should be rendered.
+
* CHANGED: Removed deprecated #has_rdoc= RubyGems attribute.
@@ -113,6 +113,18 @@ def execute(method)
end
end
+
+ class BlockBuilder < TabsOnRails::Tabs::TabsBuilder
+ def tab_for(tab, name, options, item_options = {}, &block)
+ item_options[:class] = item_options[:class].to_s.split(" ").push("current").join(" ") if current_tab?(tab)
+ content = @context.link_to_unless(current_tab?(tab), name, options) do
+ @context.content_tag(:span, name)
+ end
+ content += @context.capture(&block) if block_given?
+ @context.content_tag(:li, content, item_options)
+ end
+ end
+
end
class WorkingMixinTest < ActionController::TestCase
@@ -142,6 +154,15 @@ def test_render_with_item_options
</ul>}, @response.body)
end
+ def test_render_with_item_block
+ get :action_dashboard, :template => "with_item_block"
+ assert_dom_equal(%Q{<ul>
+ <li class="custom current"><span>Dashboard</span></li>
+ <li class="custom"><a href="/w">Welcome</a>
+ <img src="#image" />
+</li></ul>}, @response.body)
+ end
+
def test_set_tab
get :action_dashboard
@@ -1,6 +1,6 @@
require 'test_helper'
-class CustomBuilderTest < ActionView::TestCase
+class BlockBuilderTest < ActionView::TestCase
tests TabsOnRails::ActionController::HelperMethods
include ActionView::Helpers::TagHelper
@@ -17,17 +17,17 @@ def current_tab(namespace)
end
end
- class CustomBuilder < TabsOnRails::Tabs::TabsBuilder
+ class BlockBuilder < TabsOnRails::Tabs::TabsBuilder
def tab_for(tab, name, options, item_options = {}, &block)
item_options[:class] = item_options[:class].to_s.split(" ").push("current").join(" ") if current_tab?(tab)
- content = @context.link_to(name, options)
+ content = @context.link_to(name, options)
content += @context.capture(&block) if block_given?
@context.content_tag(:li, content, item_options)
end
end
-
+
def setup
- @klass = CustomBuilder
+ @klass = BlockBuilder
@builder = @klass.new(self)
end
View
@@ -30,6 +30,15 @@ def close_tabs
end
end
+ BlockBuilder = Class.new(TabsOnRails::Tabs::Builder) do
+ def tab_for(tab, name, options, item_options = {}, &block)
+ item_options[:class] = item_options[:class].to_s.split(" ").push("current").join(" ") if current_tab?(tab)
+ content = @context.link_to(name, options)
+ content += @context.capture(&block) if block_given?
+ @context.content_tag(:li, content, item_options)
+ end
+ end
+
def setup
@template = Template.new
@@ -83,4 +92,10 @@ def test_open_tabs_should_ignore_options_if_arity_is_zero
end
end
+
+ def test_tab_for
+ assert_equal %Q{<li><a href="#">Welcome</a></li>},
+ @tabs.welcome('Welcome', '#')
+ end
+
end
@@ -0,0 +1,6 @@
+<%= tabs_tag(:builder => WorkingMixinTestController::BlockBuilder) do |tabs| %>
+ <%= tabs.dashboard 'Dashboard', '/d', :class => "custom" %>
+ <%= tabs.welcome 'Welcome', '/w', :class => "custom" do %>
+ <img src="#image" />
+ <% end %>
+<% end %>

0 comments on commit ed0759a

Please sign in to comment.