/lib/widgets/tabnav.rb

http://github.com/paolodona/rails-widgets · Ruby · 26 lines · 20 code · 4 blank · 2 comment · 3 complexity · 25c43737d75517bfad93bc4fd29890c0 MD5 · raw file

  1. module Widgets
  2. class Tabnav
  3. include CssTemplate
  4. attr_accessor :tabs, :html, :name
  5. def initialize(name, opts={})
  6. @name = name || :main
  7. @tabs = []
  8. @generate_css = opts[:generate_css] || false
  9. @html = opts[:html] || {} # setup default html options
  10. @html[:id] ||= name.to_s.underscore << '_tabnav'
  11. @html[:class] ||= @html[:id]
  12. end
  13. # should the helper generate a css for this tabnav?
  14. def generate_css?
  15. @generate_css ? true : false
  16. end
  17. # sort your tabs alphabetically
  18. def sort!
  19. @tabs.sort! { |x,y| x.name <=> y.name }
  20. end
  21. end
  22. end