lib/menu_maker/menu.rb in menu_maker-0.1.0 vs lib/menu_maker/menu.rb in menu_maker-0.2.0

- old
+ new

@@ -15,12 +15,12 @@ def each(&block) items.each(&block) end - def add(title, path, options = {}) - @items[title] = MenuItem.new(title, path, options) + def add(title, *paths, **options) + @items[title] = MenuItem.new(title, *paths, options) @current_item = title yield current_submenu if block_given? self @@ -72,26 +72,28 @@ def next_depth current_depth + 1 end class MenuItem - attr_reader :title, :paths, :options + attr_reader :title, :options - def initialize(title, path = nil, options = nil) + def initialize(title, *paths, **options) @title = title - @paths = [] + @paths = paths.map { |p| Path.convert(p) } @options = options - - @paths << path if path end attr_accessor :submenu def has_submenu? !@submenu.nil? end + def paths + @paths + end + def submenu_paths return [] unless has_submenu? submenu.items.reduce([]) do |all, item| all + item.paths + item.submenu_paths @@ -101,11 +103,11 @@ def all_paths [*paths, *submenu_paths] end def has_path?(path) - all_paths.any? { |p| p == path } + all_paths.include? Path.convert(path) end def method_missing(method, *args) options && options[method] || '' end @@ -113,10 +115,10 @@ def respond_to_missing?(method) !!(options && options[method]) end def path - @paths.first + @paths.first.address end def render_submenu has_submenu? ? submenu.render : '' end