51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/qui-tabs-main-helper.rb', line 51
def tabs(options)
@tabs_count ||= 0
raise RuntimeError, "@tabs_count must be integer" unless @tabs_count.is_a? Fixnum
default_id = "tabs_#{@tabs_count}"
options[:id] ||= default_id
= ""
bodies = ""
options[:tabs].each_with_index do |tab, i|
if tab[:header][:text]
if tab[:header][:text].is_a? Symbol
= t(tab[:header][:text])
else
= tab[:header][:text].to_s
end
elsif tab[:header][:inline]
= ERB.new(tab[:header][:inline]).result
elsif tab[:header][:partial]
= capture { render :partial => tab[:header][:partial], :locals => tab[:header][:locals] }
else
= ""
end
<< content_tag(:a, , :id => "#{options[:id]}_tab_#{i}_header", :class => (i == 0 ? "current" : "" ), :href => "#", :onclick => "Tab.find(#{@tabs_count}).setCurrent(#{escape_javascript(i.to_s)}); return false;")
if tab[:body][:text]
if tab[:body][:text].is_a? Symbol
body = t(tab[:body][:text])
else
body = tab[:body][:text].to_s
end
elsif tab[:body][:inline]
body = ERB.new(tab[:body][:inline]).result
elsif tab[:body][:partial]
body = capture { render :partial => tab[:body][:partial], :locals => tab[:body][:locals] }
else
body = ""
end
bodies << content_tag(:div, body, :id => "#{options[:id]}_tab_#{i}_body", :class => (i == 0 ? "current" : "" ))
end
result = "<div class=\"tabs\" id=\"#{options[:id]}\">"
result << "<div class=\"header\">"
result <<
result << "</div>"
result << "<div class=\"body\">"
result << bodies
result << "</div>"
result << "</div>"
js_options = { :id => @tabs_count, :count => options[:tabs].size }
js_options.merge!({ :custom_html_id => options[:id] }) unless options[:id] == default_id
result << javascript_tag("Tab.create(#{js_options.to_json});")
@tabs_count += 1
result
end
|