class Macros4Cuke::Templating::Section
Base class used internally by the template engine. Represents a section in a template, that is, a set of template elements for which its rendition depends on the value of a variable.
Attributes
children[R]
The child elements of the section
Public Class Methods
new(aVarName)
click to toggle source
@param aVarName [String] The name of the placeholder from a template.
Calls superclass method
# File lib/macros4cuke/templating/section.rb, line 22 def initialize(aVarName) super(aVarName) @children = [] end
Public Instance Methods
add_child(aChild)
click to toggle source
Add a child element as member of the section
# File lib/macros4cuke/templating/section.rb, line 28 def add_child(aChild) children << aChild end
render(_, _)
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 51 def render(_, _) msg = "Method Section.#{__method__} must be implemented in subclass." raise(NotImplementedError, msg) end
variables()
click to toggle source
Retrieve all placeholder names that appear in the template. @return [Array] The list of placeholder names.
# File lib/macros4cuke/templating/section.rb, line 34 def variables() all_vars = children.each_with_object([]) do |a_child, subResult| case a_child when Placeholder subResult << a_child.name when Section subResult.concat(a_child.variables) end end return all_vars.flatten.uniq end