Sha256: 5c8cd0be6de1f656abb828ca57c48057caf0f4a379e6f80de2eb4e1c4e07b700

Contents?: true

Size: 1.96 KB

Versions: 13

Compression:

Stored size: 1.96 KB

Contents

module Vedeu

  module DSL

    # Provides the mechanism to create menus within client applications and use
    # events to drive them.
    #
    class Menu

      include Vedeu::DSL

      # Return a new instance of DSL::Menu.
      #
      # @param model [Vedeu::Menu]
      # @param client [Object]
      # @return [Vedeu::DSL::Menu]
      def initialize(model, client = nil)
        @model  = model
        @client = client
      end

      # Add an individual item to the menu.
      #
      # @param element [Object] An object you wish to add to the collection.
      #
      #   Vedeu.menu 'my_menu' do
      #     item SomeClass.new
      #     item SomeClass.new
      #   end
      #
      # @return [Array]
      def item(element)
        model.collection << element
      end

      # Define the items for the menu. Most powerful when used with one of your
      # model classes.
      #
      # In the 'my_playlist' example below, your `Track` model may return a
      # collection of tracks to populate the menu.
      #
      #   Vedeu.menu 'my_menu' do
      #     items [:item_1, :item_2, :item_3]
      #   end
      #
      #   Vedeu.menu 'my_playlist' do
      #     items Track.all_my_favourites
      #   end
      #
      # @param collection [Array<Object>] A collection of objects which make up
      #   the menu items.
      # @return [Array]
      def items(collection = [])
        model.collection = collection
      end

      # The name of the menu. Used to reference the menu throughout your
      # application's execution lifetime.
      #
      #   Vedeu.menu do
      #     name 'my_menu'
      #     # ...
      #   end
      #
      # @param value [String]
      # @return [String]
      def name(value)
        model.name = value
      end

      protected

      # @!attribute [r] client
      # @return [Object]
      attr_reader :client

      # @!attribute [r] model
      # @return [Vedeu::Menu]
      attr_reader :model

    end # Menu

  end # DSL

end # Vedeu

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vedeu-0.5.5 lib/vedeu/dsl/menu.rb
vedeu-0.5.4 lib/vedeu/dsl/menu.rb
vedeu-0.5.3 lib/vedeu/dsl/menu.rb
vedeu-0.5.2 lib/vedeu/dsl/menu.rb
vedeu-0.5.1 lib/vedeu/dsl/menu.rb
vedeu-0.5.0 lib/vedeu/dsl/menu.rb
vedeu-0.4.65 lib/vedeu/dsl/menu.rb
vedeu-0.4.64 lib/vedeu/dsl/menu.rb
vedeu-0.4.63 lib/vedeu/dsl/menu.rb
vedeu-0.4.62 lib/vedeu/dsl/menu.rb
vedeu-0.4.61 lib/vedeu/dsl/menu.rb
vedeu-0.4.60 lib/vedeu/dsl/menu.rb
vedeu-0.4.59 lib/vedeu/dsl/menu.rb