Class: Waiter::Menu::Drawer
- Inherits:
-
Object
- Object
- Waiter::Menu::Drawer
- Defined in:
- lib/waiter/menu/drawer.rb
Overview
Outputs a Menu into HTML
Instance Method Summary collapse
- #draw ⇒ Object
- #draw_submenu(submenu) ⇒ Object
-
#initialize(menu, context) ⇒ Drawer
constructor
A new instance of Drawer.
Constructor Details
#initialize(menu, context) ⇒ Drawer
Returns a new instance of Drawer.
8 9 10 11 |
# File 'lib/waiter/menu/drawer.rb', line 8 def initialize(, context) @context = context @menu = end |
Instance Method Details
#draw ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/waiter/menu/drawer.rb', line 13 def draw content_tag :div, :id => "menu" do out = ActiveSupport::SafeBuffer.new @menu.items.each do |(name, )| [:controller] = name unless [:controller] # Allow an :if option which will only display the menu if true if ![:if] or [:if].call # If there is a :selected option, use that instead of trying to determine the selected menu item selected = (name, [:controller], [:action] || [:actions], .delete(:controllers)) out << content_tag(:span, :class => selected ? "selected" : nil) do out2 = ActiveSupport::SafeBuffer.new out2 << link_to(I18n.t(@menu.[:string_prefix].to_s + name.to_s), { :controller => .delete(:controller).to_s.absolutify, :action => (.delete(:action) || .delete(:actions).andand.first) }.merge()) out2 << (@menu.[name]) if @menu.[name] out2 end end end out << '<br class="clear" />'.html_safe out end end |
#draw_submenu(submenu) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/waiter/menu/drawer.rb', line 39 def () content_tag :table, :class => "dropdown", :cellspacing => 0 do out = ActiveSupport::SafeBuffer.new .items.each do |(name, )| out << content_tag(:tr) do content_tag :td do controller = .delete(:controller) || .[:controller] action = .delete(:action) || begin controller_class = "#{controller}_controller".classify.constantize controller_class.action_methods.include?(name.to_s) ? name : nil end rescue nil || :index link_to I18n.t(.[:string_prefix].to_s + name.to_s), { :controller => controller.to_s.absolutify, :action => action }.merge() end end end out end end |