Class: Macros4Cuke::Templating::Placeholder

Inherits:
UnaryElement 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

Attributes inherited from UnaryElement

#name

Instance Method Summary collapse

Methods inherited from UnaryElement

#initialize

Constructor Details

This class inherits a constructor from Macros4Cuke::Templating::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.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/macros4cuke/templating/engine.rb', line 97

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