you are in: codestackercodes [RSS]simple tabs helper

simple tabs helper Delicious Email

show/hide lines
   1  class TabHelper
   2    attr_reader :html, :tabs
   3  
   4    def initialize(template, states)
   5      @template = template
   6      @states = states
   7      @html = []
   8      @tabs = {}
   9    end
  10  
  11    def add(action, text)
  12      url = { :action => action }
  13      html = 
  14        if @template.request.path.sub(/\?.*/, '') == @template.url_for(url)
  15          @states[:active].call(text, url)
  16        else
  17          @states[:inactive].call(text, url)
  18        end
  19      @tabs[action] = html
  20      @html << html
  21    end
  22    alias_method :[]=, :add
  23    
  24    def [](*args)
  25      @tabs.values_at(*args)
  26    end
  27  end
  28  
  29  # example
  30  
  31  module ProductsHelper
  32    def subnav_links
  33      t = TabHelper.new(self,
  34        :active   => Proc.new {|text, url| %|<div class="current tab">#{text}</div>| },
  35        :inactive => Proc.new {|text, url| %|<div class="tab">#{link_to text, url}</div>| }
  36      )
  37      t[:index] = 'Manage Products'
  38      t[:front_page] = 'Manage Front Page'
  39      
  40      '<div id="tabs">' +
  41        '<div style="float: left">' +
  42          t[:index, :front_page].join +
  43        '</div>' +
  44        '<div class="clear"></div>' +
  45      '</div>'
  46    end
  47  end
created by leozera — 01 December 2008 — get a short url — tags: helper rails tab embed

Comments



We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image