Sha256: b327061157af75ecb986f15d7b6298d26d1bed99887e24171afaecd9de50ca7d

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# File: unary-element.rb
# Purpose: Implementation of the Section and ConditionalSection classes.

require_relative 'unary-element' # Load the superclass


module Macros4Cuke # Module used as a namespace

  # Base class used internally by the template engine.  
  # The generalization of any element from a template that has one variable
  # whose actual value influences the rendition.
  class UnaryElement
    # The name of the placeholder/variable.
    attr_reader(:name)
    
    # @param aVarName [String] The name of the placeholder from a template.
    def initialize(aVarName)
      @name = aVarName
    end

    protected

    # This method has the same signature as the {Engine#render} method.
    # @return [Object] The actual value from the locals or context
    # that is assigned to the variable.
    def retrieve_value_from(aContextObject, theLocals)
      actual_value = theLocals[name]
      if actual_value.nil? && aContextObject.respond_to?(name.to_sym)
        actual_value = aContextObject.send(name.to_sym)
      end
      
      return actual_value
    end  
    
  end # class

end # module

# End of file

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
macros4cuke-0.4.03 lib/macros4cuke/templating/unary-element.rb