Class: Tzispa::Rig::TypeToken::Loop
- Inherits:
-
Tzispa::Rig::Token
- Object
- Tzispa::Rig::Token
- Tzispa::Rig::TypeToken::Loop
- Extended by:
- Forwardable
- Defined in:
- lib/tzispa/rig/type_token/statement.rb
Constant Summary
Constants inherited from Tzispa::Rig::Token
Instance Attribute Summary collapse
-
#body_parser ⇒ Object
readonly
Returns the value of attribute body_parser.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from Tzispa::Rig::Token
Instance Method Summary collapse
-
#initialize(parser, match) ⇒ Loop
constructor
A new instance of Loop.
- #parse! ⇒ Object
- #render(binder) ⇒ Object
Methods inherited from Tzispa::Rig::Token
Constructor Details
#initialize(parser, match) ⇒ Loop
Returns a new instance of Loop.
15 16 17 18 19 |
# File 'lib/tzispa/rig/type_token/statement.rb', line 15 def initialize(parser, match) super(parser, :loop) @id = match[3].to_sym @body = match[4] end |
Instance Attribute Details
#body_parser ⇒ Object (readonly)
Returns the value of attribute body_parser.
12 13 14 |
# File 'lib/tzispa/rig/type_token/statement.rb', line 12 def body_parser @body_parser end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/tzispa/rig/type_token/statement.rb', line 12 def id @id end |
Instance Method Details
#parse! ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/tzispa/rig/type_token/statement.rb', line 21 def parse! @body_parser = Rig::ParserNext.new template: template, text: @body, parent: parser, bindable: true @body_parser.parse! self end |
#render(binder) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/tzispa/rig/type_token/statement.rb', line 30 def render(binder) String.new.tap do |text| looper = binder.data.send(@id) if binder.data.respond_to?(@id) looper&.data&.each do |loop_item| text << body_parser.render(loop_item) if loop_item end end end |