class Macros4Cuke::Templating::ConditionalSection
A specialized section in a template for which its rendition depends on the (in)existence of an actual value bound to the variable name.
Attributes
existence[R]
A boolean that indicates whether the rendition condition is the existence of a value for the variable (true) or its non-existence (false).
Public Class Methods
new(aVarName, renderWhenExisting = true)
click to toggle source
@param aVarName [String] The name of the placeholder from a template. @param renderWhenExisting [boolean] When true, render the children elements
if a value exists for the variable.
Calls superclass method
Macros4Cuke::Templating::Section::new
# File lib/macros4cuke/templating/section.rb, line 68 def initialize(aVarName, renderWhenExisting = true) super(aVarName) @existence = renderWhenExisting end
Public Instance Methods
render(aContextObject, theLocals)
click to toggle source
Render the placeholder given the passed arguments. This method has the same signature as the {Engine#render} method. @return [String] The text value assigned to the placeholder.
Returns an empty string when no value is assigned to the placeholder.
# File lib/macros4cuke/templating/section.rb, line 77 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()
click to toggle source
@return [String] The original text representation of the tag.
# File lib/macros4cuke/templating/section.rb, line 92 def to_s() return "<?#{name}>" end