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
37 38 39 40 |
# File 'lib/uberkit/menu.rb', line 37 def action(name, = {}, = {}) = { :current => .delete(:current), :disabled => .delete(:disabled), :force_current => .delete(:force_current), :url => } @actions << [@template.link_to(name,,), , ] end |
#action_wrapper(contents, options = {}, url_for_options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# 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 content_tag(:li, contents, :class => classes.join(" ")) end |
#actions ⇒ Object
42 43 44 |
# File 'lib/uberkit/menu.rb', line 42 def actions @actions end |
#any_current? ⇒ Boolean
70 71 72 |
# File 'lib/uberkit/menu.rb', line 70 def any_current? @actions.select{|a| merits_current?(*a)}.any? end |
#build ⇒ Object Also known as: to_html
74 75 76 77 78 |
# File 'lib/uberkit/menu.rb', line 74 def build content_tag :ul, @actions.collect{|a| action_wrapper(*a)}.join("\n"), :id => @id, :class => @class_name end |
#custom_action(options = {}, &block) ⇒ Object
51 52 53 54 |
# File 'lib/uberkit/menu.rb', line 51 def custom_action( = {}, &block) [:force_current] = true @actions << [capture(&block), , {}] end |
#merits_current?(contents, options = {}, url_for_options = {}) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/uberkit/menu.rb', line 28 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
46 47 48 49 |
# File 'lib/uberkit/menu.rb', line 46 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
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uberkit/menu.rb', line 56 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]}, ] else @actions << [@template.link_to(name,,) + .to_html, {:current => .any_current?, :url => }, ] if .actions.any? end end end |