Sha256: cbf3bc324c40fe6ff0b1822bd728b57e4c28e0a94d5ba63e911d492183758aa9
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
require 'waiter/dsl' require 'waiter/menu/item_list' require 'waiter/menu/item' require 'waiter/menu/section' require 'waiter/menu/drawer' require 'active_support/core_ext/hash/slice' module Waiter class Menu attr_accessor :name, :context, :options, :submenu, :parent include DSL def self.serve(name, context = nil, options = {}, &block) new(name, context, options).tap do |menu| menu.update(&block) end end def initialize(name, context, options = {}) @name = name @context = context @items = ItemList.new @options = options end def update(&block) instance_eval(&block) end def draw(context = nil) Drawer.new(self, context).draw end def add(name, path = {}, options = {}, &block) items << Item.new(self, name, path, options, &block) end def add_section(options = {}, &block) section = Section.new(self, options, &block) items << section if section.items.any? end def sections items.select(&:section?) || [] end def [](name) items[name] end def items(sorted = false) return @items unless sorted ItemList.new(@items, options.slice(:sort, :reverse)) end def top? parent.nil? end def inspect "#<#{self.class.name}:#{'0x%x' % (36971870 << 1)} name=#{name.inspect} options=#{options.inspect}>" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
waiter-2.0.4 | lib/waiter/menu.rb |
waiter-2.0.3 | lib/waiter/menu.rb |
waiter-2.0.2 | lib/waiter/menu.rb |
waiter-2.0.1 | lib/waiter/menu.rb |