Sha256: 771195c5276c9e857040cdb650a0d460b30a613f96dfbb48ed71e50243f06fbd

Contents?: true

Size: 1.64 KB

Versions: 11

Compression:

Stored size: 1.64 KB

Contents

module Vedeu

  module Menus

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

      include Vedeu::DSL

      # 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
      alias_method :item=, :item

      # 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
      alias_method :items=, :items

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

    end # DSL

  end # Menus

end # Vedeu

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.6.31 lib/vedeu/menus/dsl.rb
vedeu-0.6.30 lib/vedeu/menus/dsl.rb
vedeu-0.6.29 lib/vedeu/menus/dsl.rb
vedeu-0.6.28 lib/vedeu/menus/dsl.rb
vedeu-0.6.27 lib/vedeu/menus/dsl.rb
vedeu-0.6.26 lib/vedeu/menus/dsl.rb
vedeu-0.6.25 lib/vedeu/menus/dsl.rb
vedeu-0.6.24 lib/vedeu/menus/dsl.rb
vedeu-0.6.23 lib/vedeu/menus/dsl.rb
vedeu-0.6.22 lib/vedeu/menus/dsl.rb
vedeu-0.6.21 lib/vedeu/menus/dsl.rb