Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Created January 20, 2011 01:44
Show Gist options
  • Save ch1ago/787258 to your computer and use it in GitHub Desktop.
Save ch1ago/787258 to your computer and use it in GitHub Desktop.
#index.html view file
"now it works, I'm passing an string "
<%= tabs 1000 do |t| %>
<% content = capture do %>
aaa
<% end %>
<% t.tab 'xxxx', content %>
<% content = capture do %>
bbbb
<% end %>
<% t.tab 'zzzz', content %>
<% end %>
<%= tabs 1000 do |t| %>
<% t.tab "Tab1" do %>
aaa
<% end %>
<% t.tab "Tab2" do %>
bbbb
<% end %>
<% end %>
#helper folder
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
#extra folder
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