Class: MenuHelper::Menu
- Inherits:
-
HtmlElement
- Object
- HtmlElement
- MenuHelper::Menu
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- lib/menu_helper/menu.rb
Overview
Represents a single menu within a menu bar
Constant Summary collapse
'ui-menubar-menu'
- @@selected_class =
'ui-state-active ui-menubar-selected'
- @@last_class =
'ui-menubar-last'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The unique name assigned to this menu.
-
#parent_menu_bar ⇒ Object
readonly
The menu bar in which this menu exists.
-
#url_options ⇒ Object
readonly
The url where this menu is linked to.
Instance Method Summary collapse
-
#html(last = false) ⇒ Object
Builds the actual html of the menu.
-
#initialize(parent_menu_bar, name, content = nil, url_options = {}, html_options = {}) {|@menu_bar| ... } ⇒ Menu
constructor
:nodoc.
-
#selected? ⇒ Boolean
Is this menu selected? A menu is considered selected if it or any of its sub-menus are selected.
Constructor Details
#initialize(parent_menu_bar, name, content = nil, url_options = {}, html_options = {}) {|@menu_bar| ... } ⇒ Menu
:nodoc
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/menu_helper/menu.rb', line 36 def initialize(, name, content = nil, = {}, = {}) #:nodoc # Allow the content parameter to be skipped content, , = nil, content, if content.is_a?(Hash) # Remove non-html options that are specific to this element and shouldn't # be rendered as an html attribute @options = .slice(:link) .except!(:link) super() @parent_menu_bar = @name = name.to_s # Set context of the menu for url generation @controller = request_controller # Generate the text-based content of the menu @content = content_tag(:span, content || @name.underscore.titleize) # Set up url url, @url_options = build_url() @content = link_to(@content, url) if @options[:link] != false # Set up default html options id_prefix = [:id] || && [:id] self[:id] ||= "#{id_prefix}-#{@name}" if auto_set_ids? && id_prefix self[:class] = "#{self[:class]} #{} #{}-#{level}".strip # Create the menu bar for sub-menus in case any are generated. Use the # same configuration as the parent menu bar. @menu_bar = MenuBar.new(request_controller, ..merge(:parent_menu => self)) yield @menu_bar if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
The unique name assigned to this menu
19 20 21 |
# File 'lib/menu_helper/menu.rb', line 19 def name @name end |
#parent_menu_bar ⇒ Object (readonly)
The menu bar in which this menu exists
26 27 28 |
# File 'lib/menu_helper/menu.rb', line 26 def @parent_menu_bar end |
#url_options ⇒ Object (readonly)
The url where this menu is linked to. This can either be a hash of url options or a string representing the actual url
23 24 25 |
# File 'lib/menu_helper/menu.rb', line 23 def @url_options end |
Instance Method Details
#html(last = false) ⇒ Object
Builds the actual html of the menu
79 80 81 82 83 84 85 |
# File 'lib/menu_helper/menu.rb', line 79 def html(last = false) = @html_options.dup [:class] = "#{[:class]} #{selected_class}".strip if selected? [:class] = "#{[:class]} #{last_class}".strip if last content_tag(tag_name, content, ) end |
#selected? ⇒ Boolean
Is this menu selected? A menu is considered selected if it or any of its sub-menus are selected
74 75 76 |
# File 'lib/menu_helper/menu.rb', line 74 def selected? current_page?() || @menu_bar.selected? end |