Class: Uberkit::Menu::NavigationMenu
- Defined in:
- lib/uberkit/menu.rb
Instance Method Summary collapse
- #action(name, options = {}, html_options = {}) ⇒ Object
- #action_wrapper(contents, options = {}, url_for_options = {}) ⇒ Object
- #actions ⇒ Object
- #any_current? ⇒ Boolean
- #build ⇒ Object (also: #to_html)
- #custom_action(options = {}, &block) ⇒ Object
-
#initialize(template, options = {}) ⇒ NavigationMenu
constructor
A new instance of NavigationMenu.
- #merits_current?(contents, options = {}, url_for_options = {}) ⇒ Boolean
- #remote_action(name, options = {}, html_options = {}) ⇒ Object
- #submenu(name, options = {}, html_options = {}) {|subnav| ... } ⇒ Object
Methods inherited from Displayer
Constructor Details
#initialize(template, options = {}) ⇒ NavigationMenu
Returns a new instance of NavigationMenu.
10 11 12 13 14 15 16 |
# File 'lib/uberkit/menu.rb', line 10 def initialize(template, = {}) super(template) @actions = [] @subnavs = [] @id = .delete(:id) @class_name = .delete(:class) end |
Instance Method Details
#action(name, options = {}, html_options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uberkit/menu.rb', line 38 def action(name, = {}, = {}) = { :current => .delete(:current), :disabled => .delete(:disabled), :force_current => .delete(:force_current), :url => , :html => .delete(:html) } @actions << [@template.link_to(name,,), , ] end |
#action_wrapper(contents, options = {}, url_for_options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/uberkit/menu.rb', line 18 def action_wrapper(contents, = {}, = {}) classes = Array.new classes << "first" if @actions.first == [contents, , ] classes << "last" if @actions.last == [contents, , ] classes << "current" if merits_current?(contents,,) classes << "disabled" if .delete(:disabled) classes << classes.join("_") if classes.size > 1 classes << [:html].delete(:class) if [:html] content_tag(:li, contents, [:html].merge(:class => classes.join(" "))) end |
#actions ⇒ Object
49 50 51 |
# File 'lib/uberkit/menu.rb', line 49 def actions @actions end |
#any_current? ⇒ Boolean
77 78 79 |
# File 'lib/uberkit/menu.rb', line 77 def any_current? @actions.select{|a| merits_current?(*a)}.any? end |
#build ⇒ Object Also known as: to_html
81 82 83 84 85 |
# File 'lib/uberkit/menu.rb', line 81 def build content_tag :ul, @actions.collect{|a| action_wrapper(*a)}.join("\n"), :id => @id, :class => @class_name end |
#custom_action(options = {}, &block) ⇒ Object
58 59 60 61 |
# File 'lib/uberkit/menu.rb', line 58 def custom_action( = {}, &block) [:force_current] = true @actions << [capture(&block), , {}] end |
#merits_current?(contents, options = {}, url_for_options = {}) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/uberkit/menu.rb', line 29 def merits_current?(contents,={},={}) if [:force_current] return true if .delete(:current) == true && ![:disabled] else return true if (.delete(:current) == true || (!.is_a?(Symbol) && (@template.current_page?()) && != {}) and ![:disabled]) end false end |
#remote_action(name, options = {}, html_options = {}) ⇒ Object
53 54 55 56 |
# File 'lib/uberkit/menu.rb', line 53 def remote_action(name, = {}, = {}) = { :current => .delete(:current), :disabled => .delete(:disabled), :force_current => .delete(:force_current), :url => [:url] } @actions << [@template.link_to_remote(name,,), , [:url]] end |
#submenu(name, options = {}, html_options = {}) {|subnav| ... } ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/uberkit/menu.rb', line 63 def (name, = {}, = {}, &block) = NavigationMenu.new(@template,) @subnavs << yield if .actions.any? if == :delegate @actions << [@template.link_to(name, .actions.first[1][:url]) + .to_html, {:current => .any_current?, :url => .actions.first[1][:url]}, {:class => 'submenu'}] else @actions << [@template.link_to(name,,) + .to_html, {:current => .any_current?, :url => }, {:class => 'submenu'}.merge()] if .actions.any? end end end |