Skip to content

Instantly share code, notes, and snippets.

@charly
Created August 4, 2009 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charly/161115 to your computer and use it in GitHub Desktop.
Save charly/161115 to your computer and use it in GitHub Desktop.
module TabsHelper
# takes the block
def tabs_for(current_tab, &block)
yield Tab.new(current_tab, self)
end
class Tab
def initialize(current_tab, template)
@current_tab = current_tab
@template = template
end
def link_to(*args)
"<li #{active_class(*args)}>#{@template.link_to(*args)}</li>"
end
private
def active_class(*args)
if @current_tab.all? { |k, v| args[1][k] == v }
"class = 'active'"
end
end
end #class Tab
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment