Sha256: 57642b5597083300bd2172e404fb5c8a886e8619cf1cf9d646479aca70bf1bab

Contents?: true

Size: 1.11 KB

Versions: 36

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.all_widgets_from_pool.each(&block)
    end

    private

    attr_reader :obj
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
scrivito_sdk-0.71.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-0.70.0 lib/scrivito/widget_collection.rb
scrivito_sdk-0.70.0.rc3 lib/scrivito/widget_collection.rb
scrivito_sdk-0.70.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-0.70.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-0.66.0 lib/scrivito/widget_collection.rb
scrivito_sdk-0.66.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-0.65.2 lib/scrivito/widget_collection.rb
scrivito_sdk-0.66.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-0.65.1 lib/scrivito/widget_collection.rb
scrivito_sdk-0.65.0 lib/scrivito/widget_collection.rb
scrivito_sdk-0.65.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-0.65.0.rc1 lib/scrivito/widget_collection.rb
scrivito_sdk-0.60.0 lib/scrivito/widget_collection.rb
scrivito_sdk-0.60.0.rc2 lib/scrivito/widget_collection.rb
scrivito_sdk-0.60.0.rc1 lib/scrivito/widget_collection.rb