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