Platinum Partner

Simpler Tabs

Just one of many ways to help you add tabs to your layout.


class TabHelper
  attr_reader :html, :tabs

  def initialize(template, states)
    @template = template
    @states = states
    @html = []
    @tabs = {}
  end

  def add(action, text)
    url = { :action => action }
    html = 
      if @template.request.path.sub(/\?.*/, '') == @template.url_for(url)
        @states[:active].call(text, url)
      else
        @states[:inactive].call(text, url)
      end
    @tabs[action] = html
    @html << html
  end
  alias_method :[]=, :add
  
  def [](*args)
    @tabs.values_at(*args)
  end
end


Example:


module ProductsHelper
  def subnav_links
    t = TabHelper.new(self,
      :active   => Proc.new {|text, url| %|
#{text}
| }, :inactive => Proc.new {|text, url| %|
#{link_to text, url}
| } ) t[:index] = 'Manage Products' t[:front_page] = 'Manage Front Page' '
' + '
' + t[:index, :front_page].join + '
' + '
' + '
' end end
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}