Class: Macros4Cuke::Templating::Placeholder
- Inherits:
-
Object
- Object
- Macros4Cuke::Templating::Placeholder
- 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
-
#name ⇒ Object
readonly
The name of the placeholder/variable.
Instance Method Summary collapse
-
#initialize(aVarName) ⇒ Placeholder
constructor
A new instance of Placeholder.
-
#render(aContextObject, theLocals) ⇒ String
Render the placeholder given the passed arguments.
Constructor Details
#initialize(aVarName) ⇒ Placeholder
Returns a new instance of Placeholder.
48 49 50 |
# File 'lib/macros4cuke/templating/engine.rb', line 48 def initialize(aVarName) @name = aVarName end |
Instance Attribute Details
#name ⇒ Object (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.
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 |