Sha256: 9d3caa2286caaf1d9da2ebe90d0245988b25ddc735612af669cd237c2e9288cd

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

module Refinery

  # Create a little something to store the instances of the menu.
  class << self
    attr_accessor :menus
    def menus
      @@menus ||= HashWithIndifferentAccess.new
    end
  end

  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_id => id))
      end if objects

      ::Refinery.menus[self.id] = self
    end

    attr_accessor :items, :id

    def id
      require 'securerandom' unless defined?(::SecureRandom)
      @id ||= ::SecureRandom.hex(8)
    end

    def items
      @items ||= []
    end

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

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

    def inspect
      items.map(&:inspect)
    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})

    # Ensure that things still work from how the menu partials worked before.
    def live
      Refinery.deprecate({
        :what => "'live' on a ::Refinery::Menu instance",
        :when => '1.1 with no replacement'
      })

      self
    end

    def in_menu
      Refinery.deprecate({
        :what => "'in_menu' on a ::Refinery::Menu instance",
        :when => '1.1 with no replacement'
      })

      self
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
refinerycms-core-1.0.11 lib/refinery/menu.rb
refinerycms-core-1.0.10 lib/refinery/menu.rb
refinerycms-core-1.0.9 lib/refinery/menu.rb
refinerycms-core-1.0.8 lib/refinery/menu.rb
refinerycms-core-1.0.7 lib/refinery/menu.rb
refinerycms-core-1.0.5 lib/refinery/menu.rb
refinerycms-core-1.0.4 lib/refinery/menu.rb
refinerycms-core-1.0.3 lib/refinery/menu.rb
refinerycms-core-1.0.1 lib/refinery/menu.rb
refinerycms-core-1.0.0 lib/refinery/menu.rb