Class: Macros4Cuke::Templating::ConditionalSection
- Inherits:
-
Section
- Object
- UnaryElement
- Section
- Macros4Cuke::Templating::ConditionalSection
- Defined in:
- lib/macros4cuke/templating/section.rb
Overview
A specialized section in a template for which its rendition depends on the (in)existence of an actual value bound to the variable name.
Instance Attribute Summary collapse
-
#existence ⇒ Object
readonly
A boolean that indicates whether the rendition condition is the existence of a value for the variable (true) or its inexistence (false).
Attributes inherited from Section
Attributes inherited from UnaryElement
Instance Method Summary collapse
-
#initialize(aVarName, renderWhenExisting = true) ⇒ ConditionalSection
constructor
A new instance of ConditionalSection.
-
#render(aContextObject, theLocals) ⇒ String
Render the placeholder given the passed arguments.
-
#to_s ⇒ String
The original text representation of the tag.
Methods inherited from Section
Constructor Details
#initialize(aVarName, renderWhenExisting = true) ⇒ ConditionalSection
Returns a new instance of ConditionalSection.
76 77 78 79 |
# File 'lib/macros4cuke/templating/section.rb', line 76 def initialize(aVarName, renderWhenExisting = true) super(aVarName) @existence = renderWhenExisting end |
Instance Attribute Details
#existence ⇒ Object (readonly)
A boolean that indicates whether the rendition condition is the existence of a value for the variable (true) or its inexistence (false).
71 72 73 |
# File 'lib/macros4cuke/templating/section.rb', line 71 def existence @existence 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/macros4cuke/templating/section.rb', line 87 def render(aContextObject, theLocals) actual_value = retrieve_value_from(aContextObject, theLocals) if (!actual_value.nil? && existence) || (actual_value.nil? && !existence) # Let render the children result = children.each_with_object('') do |a_child, sub_result| sub_result << a_child.render(aContextObject, theLocals) end else result = '' end return result end |
#to_s ⇒ String
Returns The original text representation of the tag.
103 104 105 |
# File 'lib/macros4cuke/templating/section.rb', line 103 def to_s() return "<?#{name}>" end |