Class: Uniword::Template::Helpers::LoopHelper
- Inherits:
-
Object
- Object
- Uniword::Template::Helpers::LoopHelper
- Defined in:
- lib/uniword/template/helpers/loop_helper.rb
Overview
Helper for processing loop markers in templates.
Handles collection} … {@end} blocks by:
-
Extracting elements between markers
-
Cloning for each collection item
-
Filling with scoped data
Responsibility: Loop processing only Single Responsibility Principle: Does NOT parse or validate
Instance Method Summary collapse
-
#initialize(context) ⇒ LoopHelper
constructor
Initialize helper with context.
-
#process(start_marker, _end_marker, _document) ⇒ void
Process loop markers.
Constructor Details
#initialize(context) ⇒ LoopHelper
Initialize helper with context
23 24 25 |
# File 'lib/uniword/template/helpers/loop_helper.rb', line 23 def initialize(context) @context = context end |
Instance Method Details
#process(start_marker, _end_marker, _document) ⇒ void
This method returns an undefined value.
Process loop markers
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uniword/template/helpers/loop_helper.rb', line 33 def process(start_marker, _end_marker, _document) # Resolve collection from current context resolver = @context.create_resolver collection = resolver.resolve(start_marker.collection) # Convert to array if needed Array(collection) # For now, we'll mark this as processed # Full implementation would clone elements between markers # and render each with scoped context # # This is a placeholder for the actual loop processing logic # which would need deep cloning and element insertion end |