Sha256: 4c8ac8f877a86a5fae9800745d35fb888e8a47387befd72682b6199ff7590065

Contents?: true

Size: 1.11 KB

Versions: 31

Compression:

Stored size: 1.11 KB

Contents

module Scrivito
  # @api public
  # The +WidgetCollection+ represents all {Scrivito::BasicWidget Widgets} referenced by an
  # {Scrivito::BasicObj Obj} or its subwidgets.
  class WidgetCollection
    include Enumerable

    def initialize(obj)
      @obj = obj
    end

    # @api public
    # Access a {Scrivito::BasicWidget Widget} by its +id+
    # @param [String] widget_id the id of the widget
    # @return [Scrivito::BasicWidget, nil] the Widget with the given +widget_id+ or nil
    def [](widget_id)
      obj.widget_from_pool(widget_id)
    end

    # @api public
    #
    # Enables you to iterate the {Scrivito::BasicWidget Widgets} of an {Scrivito::BasicObj Obj}.
    # Includes the {http://ruby-doc.org/core-2.1.0/Enumerable.html Enumerable} mixin
    # and thereby provides methods like +map+ or +select+.
    # @yield [Scrivito::BasicWidget] the {Scrivito::BasicWidget Widgets} of an {Scrivito::BasicObj Obj}
    #
    # @example Array of all widget ids
    #   obj.widgets.map { |widget| widget.id }
    def each(&block)
      obj.contained_widgets.each(&block)
    end

    private

    attr_reader :obj
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
scrivito_sdk-1.4.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.1 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.1.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.0 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.0.rc3 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-1.3.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-1.2.0 lib/scrivito/widget_collection.rb
scrivito_sdk-1.2.0.rc3 lib/scrivito/widget_collection.rb
scrivito_sdk-1.2.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-1.2.0.rc1 lib/scrivito/widget_collection.rb