Class: Macros4Cuke::Templating::Placeholder

Inherits:
Object
  • Object
show all
Defined in:
lib/macros4cuke/templating/engine.rb

Overview

Class used internally by the template engine.
Represents a named placeholder in a template, that is, a name placed between <..> in the template.
At rendition, a placeholder is replaced by the text value that is associated with it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aVarName) ⇒ Placeholder

Returns a new instance of Placeholder.

Parameters:

  • aVarName (String)

    The name of the placeholder from a template.



48
49
50
# File 'lib/macros4cuke/templating/engine.rb', line 48

def initialize(aVarName)
  @name = aVarName
end

Instance Attribute Details

#nameObject (readonly)

The name of the placeholder/variable.



45
46
47
# File 'lib/macros4cuke/templating/engine.rb', line 45

def name
  @name
end

Instance Method Details

#render(aContextObject, theLocals) ⇒ String

Render the placeholder given the passed arguments. This method has the same signature as the Engine#render method.

Returns:

  • (String)

    The text value assigned to the placeholder. Returns an empty string when no value is assigned to the placeholder.



57
58
59
60
61
62
63
64
65
# File 'lib/macros4cuke/templating/engine.rb', line 57

def render(aContextObject, theLocals)
  actual_value = theLocals[name]
  if actual_value.nil?
    actual_value = aContextObject.send(name.to_sym) if aContextObject.respond_to?(name.to_sym)
    actual_value = '' if actual_value.nil?
  end
  
  return actual_value.is_a?(String) ? actual_value : actual_value.to_s
end