Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add feature: set default builder for Tabs

  with this feature, we don't need adding argument like :builder =>
CustomBuilder on tabs_tag any more, this woule be useful if we call
 tabs_tag many times.
  • Loading branch information...
commit e0f924a7130e19b4ed09fedc7eede2051b1d0382 1 parent a91a476
ilstar authored
Showing with 32 additions and 1 deletion.
  1. +4 −1 lib/tabs_on_rails/tabs.rb
  2. +28 −0 test/unit/tabs_test.rb
View
5 lib/tabs_on_rails/tabs.rb
@@ -15,9 +15,12 @@ module TabsOnRails
class Tabs
+ mattr_accessor :default_builder
+ @@default_builder = TabsBuilder
+
def initialize(context, options = {})
@context = context
- @builder = (options.delete(:builder) || TabsBuilder).new(@context, options)
+ @builder = (options.delete(:builder) || self.class.default_builder).new(@context, options)
@options = options
end
View
28 test/unit/tabs_test.rb
@@ -43,6 +43,17 @@ def test_initialize_with_option_builder
assert_instance_of builder, @tabs.instance_variable_get(:"@builder")
end
+ def test_initialize_with_default_builder
+ default_builder = TabsOnRails::Tabs.default_builder
+ TabsOnRails::Tabs.default_builder = CustomBuilder
+
+ custom_tab = TabsOnRails::Tabs.new(@template) # doesnt need argument :builder => CustomBuilder
+
+ assert_instance_of CustomBuilder, custom_tab.instance_variable_get(:"@builder")
+
+ TabsOnRails::Tabs.default_builder = default_builder
+ end
+
def test_open_tabs
assert_equal '<ul>', @tabs.open_tabs
@@ -91,4 +102,21 @@ def test_tab_for_with_block
assert_dom_equal expected, result
end
+ class CustomBuilder < TabsOnRails::Tabs::Builder
+ def open_tabs(options = {})
+ @context.tag("ul", options, open = true)
+ end
+
+ def close_tabs(options = {})
+ "</ul>".html_safe
+ end
+
+ def tab_for(tab, name, options, item_options = {})
+ item_options[:class] = (current_tab?(tab) ? 'active' : '')
+ @context.content_tag(:li, item_options) do
+ @context.link_to(name, options)
+ end
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.