| Class | TabsHelper::Tabs |
| In: |
app/helpers/tabs_helper.rb
|
| Parent: | Object |
# File app/helpers/tabs_helper.rb, line 13
13: def initialize(controller)
14: @controller = controller
15: @tabs = []
16: end
# File app/helpers/tabs_helper.rb, line 18
18: def add(name, options = {}, html_options = {}, &block)
19: _html_options = { :onmouseover => "hover(this)", :onmouseout => "hoverOut(this)" }
20: _html_options.merge!(html_options) if html_options
21: @tabs << Tab.new(name, options, _html_options)
22: end
Show tab named name as selected
# File app/helpers/tabs_helper.rb, line 25
25: def select(name)
26: @selected_name = name
27: end
Builder escapes text, which is not what we want
# File app/helpers/tabs_helper.rb, line 30
30: def to_html(select_current_page = true)
31: table_class = "tabs"
32: table_class = "tabs_solo" if @tabs.size < 2
33: html = " <table class=\"\#{table_class} centered\">\n <tr>\n"
34: @tabs.each_with_index do |tab, index|
35: if index == 0
36: if select_current_page && current_page?(tab.options)
37: html << " <td class=\"first_selected\"><div class=\"first_selected\"><span>"
38: else
39: html << " <td class=\"first\"><div class=\"first\"><span>"
40: end
41: if select_current_page
42: html << link_to_unless_current(tab.name, tab.options, tab.html_options).to_s
43: else
44: html << link_to(tab.name, tab.options, tab.html_options).to_s
45: end
46: html << "</span></div>"
47: if @tabs.size < 2
48: if select_current_page && current_page?(tab.options)
49: html << "</td>\n <td class=\"last_selected\"><div class=\"last_selected\">"
50: html << "<span> </span></div>"
51: else
52: html << "</td>\n <td class=\"last\"><div class=\"last\"><span> </span></div>"
53: end
54: end
55: elsif index == @tabs.size - 1
56: if select_current_page && current_page?(tab.options)
57: html << " <td class=\"last_selected\"><div class=\"last_selected\"><span>"
58: else
59: html << " <td class=\"last\"><div class=\"last\"><span>"
60: end
61: if select_current_page
62: html << link_to_unless_current(tab.name, tab.options, tab.html_options).to_s
63: else
64: html << link_to(tab.name, tab.options, tab.html_options).to_s
65: end
66: html << "</span></div>"
67: else
68: if select_current_page && current_page?(tab.options)
69: html << " <td class=\"selected\"><div class=\"selected\"><span>"
70: else
71: html << " <td><div><span>"
72: end
73: if select_current_page
74: html << link_to_unless_current(tab.name, tab.options, tab.html_options).to_s
75: else
76: html << link_to(tab.name, tab.options, tab.html_options).to_s
77: end
78: html << "</span></div>"
79: end
80: html << "</td>\n"
81: end
82: end_html = " </tr>\n </table>\n"
83: html << end_html
84: end