Send this to a friend
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
30
31 module ProductsHelper
32 def subnav_links
33 t = TabHelper.new(self,
34 :active => Proc.new {|text, url| %|<div class="current tab">
35 :inactive => Proc.new {|text, url| %|<div class="tab">
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
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
module ProductsHelper
def subnav_links
t = TabHelper.new(self,
:active => Proc.new {|text, url| %|<div class="current tab">
:inactive => Proc.new {|text, url| %|<div class="tab">
)
t[:index] = 'Manage Products'
t[:front_page] = 'Manage Front Page'
'<div id="tabs">' +
'<div style="float: left">' +
t[:index, :front_page].join +
'</div>' +
'<div class="clear"></div>' +
'</div>'
end
end