Class: Macros4Cuke::Templating::Placeholder

Inherits:
UnaryElement show all
Defined in:
lib/macros4cuke/templating/placeholder.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

Attributes inherited from UnaryElement

#name

Instance Method Summary collapse

Methods inherited from UnaryElement

#initialize

Constructor Details

This class inherits a constructor from Macros4Cuke::UnaryElement

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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/macros4cuke/templating/placeholder.rb', line 26

def render(aContextObject, theLocals)
  actual_value = retrieve_value_from(aContextObject, theLocals)
  
  result = case actual_value
    when NilClass
      ''
    
    when Array
      # TODO: Move away from hard-coded separator.
      actual_value.join('<br/>')
      
    when String
      actual_value
    else
      actual_value.to_s
  end
      
  return result
end