Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Created January 20, 2011 00:35
Show Gist options
  • Save ch1ago/787186 to your computer and use it in GitHub Desktop.
Save ch1ago/787186 to your computer and use it in GitHub Desktop.
the problem is that yield(instance) is yielding the currenct action (index) and it should add methods to the helper method scope
index.html
<%= tabs 1000 do |t| %>
<% t.tab "Tab1" do %>
aaa
<% end %>
<% t.tab "Tab2" do %>
bbbb
<% end %>
<% end %>
module TabsHelper
def tabs(offset, &block)
instance = JqueryUiTab.new(offset)
yield(instance)
html = "<div class='ui-tabs'>"
html += "<ul>"
instance.array.each do |h|
html += "<li><a href='#tabs-#{h[:tab_id]}'>#{h[:name]}</a></li>"
end
html += "</ul>"
instance.array.map do |h|
html += "<div id='tabs-#{h[:tab_id]}'>#{h[:proc].call}</div>"
end
"#{html}</div>"
end
end
class JqueryUiTab
def initialize(i=0)
@i = i
@array = []
end
attr_reader :array
def tab(name, &block)
@i += 1
@array << {:name=>name, :proc => block, :tab_id=>@i}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment