Sha256: 4df42f8a68091f9a2d486f3d4d0790d6897006da6316cd3d07c6c890e384abed

Contents?: true

Size: 651 Bytes

Versions: 7

Compression:

Stored size: 651 Bytes

Contents

module Refinery
  class Menu

    def initialize(objects = nil)
      objects.each do |item|
        item = item.to_refinery_menu_item if item.respond_to?(:to_refinery_menu_item)
        items << MenuItem.new(item.merge(:menu => self))
      end if objects
    end

    attr_accessor :items

    def items
      @items ||= []
    end

    def roots
      @roots ||= items.select {|item| item.parent_id.nil?}
    end

    def to_s
      items.map(&:title).join(' ')
    end

    # The delegation is specified so crazily so that it works on 1.8.x and 1.9.x
    delegate *((Array.instance_methods - Object.instance_methods) << {:to => :items})
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
refinerycms-core-2.0.10 lib/refinery/menu.rb
refinerycms-core-2.0.9 lib/refinery/menu.rb
refinerycms-core-2.0.8 lib/refinery/menu.rb
refinerycms-core-2.0.7 lib/refinery/menu.rb
refinerycms-core-2.0.6 lib/refinery/menu.rb
refinerycms-core-2.0.5 lib/refinery/menu.rb
refinerycms-core-2.0.4 lib/refinery/menu.rb