#-- # Tabs on Rails # # A simple Ruby on Rails plugin for creating and managing Tabs. # # Copyright (c) 2009-2012 Simone Carletti #++ module TabsOnRails class Tabs # # = Tabs Builder # # The TabsBuilder is and example of custom Builder. # class TabsBuilder < Builder # Returns a link_to +tab+ with +name+ and +options+ if +tab+ is not the current tab, # a simple tab name wrapped by a span tag otherwise. # # current_tab? :foo # => true # # tab_for :foo, 'Foo', foo_path # # => "
  • Foo
  • " # # tab_for :bar, 'Bar', bar_path # # => "
  • Bar
  • " # # You can pass a hash of item_options # to customize the behavior and the style of the li element. # # # Pass a custom class to the element # tab_for :bar, 'Bar', bar_path, :class => "custom" # # => "
  • Bar
  • " # # Implements Builder#tab_for. # def tab_for(tab, name, options, item_options = {}) 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 @context.content_tag(:li, content, item_options) end # Returns an unordered list open tag. # # The options hash is used to customize the HTML attributes of the tag. # # open_tag # # => "" # # Implements Builder#close_tabs. # def close_tabs(options = {}) "".html_safe end end end end