Sha256: ab0e0773326f21c72212329d917254d962aab45b62be2ebce5fe2a2f5b3eae69

Contents?: true

Size: 1.18 KB

Versions: 30

Compression:

Stored size: 1.18 KB

Contents

module SimpleNavigation

  # Acts as a proxy to navigation items that are passed into the SimpleNavigation::Configuration#items method. It hides the logic
  # for finding items from the Configuration object.
  #
  class ItemsProvider

    attr_reader :provider

    # It accepts the following types of provider:
    # * methodname as symbol - the specified method should return the relevant items and has to be available in the view (a helper method)
    # * object that responds to :items
    # * enumerable object that represents the items
    #
    # See SimpleNavigation::ItemAdapter for the requirements that need to be fulfilled by the provided items.
    #
    def initialize(provider)
      @provider = provider
    end

    # Returns the navigation items
    def items
      if provider.instance_of?(Symbol)
        SimpleNavigation.context_for_eval.send(provider)
      elsif provider.respond_to?(:items)
        provider.items
      elsif provider.respond_to?(:each)
        provider
      else
        raise "items_provider either must be a symbol specifying the helper-method to call, an object with an items-method defined or an enumerable representing the items"
      end
    end

  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
simple-navigation-3.12.0 lib/simple_navigation/core/items_provider.rb
jordanyeo-simple-navigation-3.11.1 lib/simple_navigation/core/items_provider.rb
jordanyeo-simple-navigation-3.11.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.11.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.10.1 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.10.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.9.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.8.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.7.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.6.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.5.1 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.5.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.4.2 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.4.1 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.4.0 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.3.4 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.3.3 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.3.2 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.3.1 lib/simple_navigation/core/items_provider.rb
simple-navigation-3.3.0 lib/simple_navigation/core/items_provider.rb