Class: Uniword::Template::Helpers::ConditionalHelper
- Inherits:
-
Object
- Object
- Uniword::Template::Helpers::ConditionalHelper
- Defined in:
- lib/uniword/template/helpers/conditional_helper.rb
Overview
Helper for processing conditional markers in templates.
Handles condition} … {@end} blocks by:
-
Evaluating condition
-
Removing content if false
-
Keeping content if true
Responsibility: Conditional processing only Single Responsibility Principle: Does NOT parse or validate
Instance Method Summary collapse
-
#initialize(context) ⇒ ConditionalHelper
constructor
Initialize helper with context.
-
#process(start_marker, end_marker, document) ⇒ void
Process conditional markers.
Constructor Details
#initialize(context) ⇒ ConditionalHelper
Initialize helper with context
23 24 25 |
# File 'lib/uniword/template/helpers/conditional_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 conditional markers
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/uniword/template/helpers/conditional_helper.rb', line 33 def process(start_marker, end_marker, document) # Evaluate condition resolver = @context.create_resolver condition_result = resolver.evaluate(start_marker.condition) # If condition is false, remove elements between markers return if condition_result remove_conditional_content(start_marker, end_marker, document) end |