Class Limelight::DSL::PropBuilder
In: lib/limelight/dsl/prop_builder.rb
Parent: Object

The basis of the DSL for building Limelight::Prop objects.

Sample usage:

  builder = Limelight::PropBuilder.new(a_prop)
  builder.instance_eval(&block)

The prop passed into the constructor will be the root of the contructed Prop tree. The block passed into instance_eval contains the DSL for building props.

Example block/DSL:

  parent :id => "the_parent" do
    child_one do
      grand_child_one :id => "gc_1", :styles => "grand_child"
      grand_child_two :id => "gc_2", :styles => "grand_child"
    end
    child_two
  end

The above example will create a Limelight::Prop named ‘parent’ and add it to the root prop passed into the builder. The ‘parent’ prop will contain two props named ‘child_one’ and ‘child_two’. ‘child_one’ will contain two props named ‘grand_child_one’ and ‘grand_child_two’. ‘child_two’ has no child props nor do ‘grand_child_one’ or ‘grand_child_two’.

An options Hash may be passed into each prop. The key, value pairs in the hash will be used to set properties on the prop when it is added to a Limelight::Scene.

See Limelight::Prop

Methods

External Aliases

instance_variables -> __instance_variables
instance_variable_get -> __instance_variable_get
instance_variable_set -> __instance_variable_set

Attributes

__loader__  [RW] 
__prop__  [R]  Returns the root prop either passed in or created by this builder.

Public Class methods

Creates a new builder. If a prop is passed it, it will be the root on which props are created. If the paramter is a Hash, the Hash will be used to construct a prop that will be used as the root.

[Source]

    # File lib/limelight/dsl/prop_builder.rb, line 73
73:       def initialize(options)
74:         if options.is_a?(Prop)
75:           @__prop__ = options
76:         else
77:           @__prop__ = Prop.new(options)
78:         end
79:       end

Public Instance methods

Add extra initialization options to the prop currently under construction.

  tree :id => "stump" do
    __ :height => "100%", :width => "30", :background_color => :brown
    branch :height => "100", :width => "20"
    branch do
      __ :height => "100", :width => "20"
    end
  end

In the above example, the ‘tree’ prop has the following initialization options: id, height, width, background_color. The two ‘branch’ child props are identical.

[Source]

    # File lib/limelight/dsl/prop_builder.rb, line 94
94:       def __(options)
95:         @__prop__.add_options(options)
96:       end

Installs props from another file using the prop DSL. The path will be relative to the root directory of the current production.

[Source]

     # File lib/limelight/dsl/prop_builder.rb, line 101
101:       def __install(file, instance_variables = {})
102:         raise "Cannot install external props because no loader was provided" if @__loader__.nil?
103:         raise "External prop file: '#{file}' doesn't exist" if !@__loader__.exists?(file)
104:         content = @__loader__.load(file)
105:         begin
106:           self.__install_instance_variables(instance_variables)
107:           self.instance_eval(content)
108:         rescue Exception => e
109:           raise BuildException.new(file, content, e)
110:         end
111:       end

Installs instance variables, specified by the passed hash, into the PropBuilder instance. The following call…

  __install_instance_variables :one => "1", "two" => "two", :three => 3

…will result in the following instance variables.

  @one   = "1"
  @two   = "2"
  @three = 3

Instance variables are propogated to nested builders so that they need only be defined on the top level builder and all children will have access to them.

[Source]

     # File lib/limelight/dsl/prop_builder.rb, line 127
127:       def __install_instance_variables(instance_variables)
128:         return if instance_variables.nil?
129:         instance_variables.each_pair do |key, value|
130:           name = "@#{key}"
131:           __instance_variable_set(name, value)
132:         end
133:       end

[Validate]