Class: MenuCreator::MenuBar
- Inherits:
-
Object
- Object
- MenuCreator::MenuBar
- Defined in:
- lib/bootstrap2-rails/menu_creator.rb
Instance Attribute Summary collapse
-
#dropdowns ⇒ Object
Returns the value of attribute dropdowns.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #add_dropdown(dropdown) ⇒ Object
-
#initialize ⇒ MenuBar
constructor
A new instance of MenuBar.
-
#valid_dropdown?(dropdown) ⇒ Boolean
Check if is a valid dropdown A valid dropdown is a class with position an caption attributes and an array of subitems.
-
#valid_subitems?(subitems) ⇒ Boolean
Check if all subitems are valid Subitem must be a hash with keys :caption, :controller and :action or a string “—” in case of a separator.
Constructor Details
#initialize ⇒ MenuBar
Returns a new instance of MenuBar.
6 7 8 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 6 def initialize @dropdowns = [] end |
Instance Attribute Details
#dropdowns ⇒ Object
Returns the value of attribute dropdowns.
4 5 6 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 4 def dropdowns @dropdowns end |
#project ⇒ Object
Returns the value of attribute project.
4 5 6 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 4 def project @project end |
Instance Method Details
#add_dropdown(dropdown) ⇒ Object
10 11 12 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 10 def add_dropdown(dropdown) @dropdowns << dropdown if valid_dropdown?(dropdown) end |
#valid_dropdown?(dropdown) ⇒ Boolean
Check if is a valid dropdown A valid dropdown is a class with position an caption attributes and an array of subitems
17 18 19 20 21 22 23 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 17 def valid_dropdown?(dropdown) return false unless dropdown.position return false unless %W(left right).include? dropdown.position.to_s return false unless dropdown. return false unless valid_subitems?(dropdown.subitems) true end |
#valid_subitems?(subitems) ⇒ Boolean
Check if all subitems are valid Subitem must be a hash with keys :caption, :controller and :action or a string “—” in case of a separator
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bootstrap2-rails/menu_creator.rb', line 28 def valid_subitems?(subitems) return false if subitems.length == 0 subitems.each do |subitem| if subitem.class.to_s == "Hash" return false unless subitem.has_key?(:caption) && subitem.has_key?(:controller) && subitem.has_key?(:action) else return false unless subitem.to_s == '---' end end true end |