Class: Uniword::Template::Helpers::ConditionalHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/template/helpers/conditional_helper.rb

Overview

Helper for processing conditional markers in templates.

Handles condition} … {@end} blocks by:

  1. Evaluating condition

  2. Removing content if false

  3. Keeping content if true

Responsibility: Conditional processing only Single Responsibility Principle: Does NOT parse or validate

Examples:

Process conditional

helper = ConditionalHelper.new(context)
helper.process(start_marker, end_marker, document)

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ConditionalHelper

Initialize helper with context

Parameters:



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

Parameters:

  • start_marker (TemplateMarker)

    Conditional start marker

  • end_marker (TemplateMarker)

    Conditional end marker

  • document (Document)

    Document to modify



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