Class: Macros4Cuke::Templating::Section
- Inherits:
-
UnaryElement
- Object
- UnaryElement
- Macros4Cuke::Templating::Section
- Defined in:
- lib/macros4cuke/templating/section.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
The child elements of the section.
Attributes inherited from UnaryElement
Instance Method Summary collapse
-
#add_child(aChild) ⇒ Object
Add a child element as member of the section.
-
#initialize(aVarName) ⇒ Section
constructor
A new instance of Section.
-
#render(aContextObject, theLocals) ⇒ String
Render the placeholder given the passed arguments.
-
#variables ⇒ Array
Retrieve all placeholder names that appear in the template.
Constructor Details
#initialize(aVarName) ⇒ Section
Returns a new instance of Section.
23 24 25 26 |
# File 'lib/macros4cuke/templating/section.rb', line 23 def initialize(aVarName) super(aVarName) @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
The child elements of the section
20 21 22 |
# File 'lib/macros4cuke/templating/section.rb', line 20 def children @children end |
Instance Method Details
#add_child(aChild) ⇒ Object
Add a child element as member of the section
31 32 33 |
# File 'lib/macros4cuke/templating/section.rb', line 31 def add_child(aChild) children << aChild end |
#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 |
# File 'lib/macros4cuke/templating/section.rb', line 57 def render(aContextObject, theLocals) msg = "Method Section.#{__method__} must be implemented in subclass." fail(NotImplementedError, msg) end |
#variables ⇒ Array
Retrieve all placeholder names that appear in the template.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/macros4cuke/templating/section.rb', line 37 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) else # Do nothing end end return all_vars.flatten.uniq end |