Class: Uniword::Template::Helpers::VariableHelper

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

Overview

Helper for variable substitution in template elements.

Replaces element content with resolved variable values. Handles different element types (Paragraph, Run, TableCell).

Responsibility: Variable substitution only Single Responsibility Principle: Does NOT resolve or validate

Examples:

Replace paragraph content

helper = VariableHelper.new
helper.replace(paragraph, "New Content")

Instance Method Summary collapse

Instance Method Details

#replace(element, value) ⇒ void

This method returns an undefined value.

Replace element content with value

Parameters:

  • element (Element)

    Element to modify

  • value (Object)

    Value to insert



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/uniword/template/helpers/variable_helper.rb', line 23

def replace(element, value)
  # Convert value to string
  text = value.to_s

  case element
  when Uniword::Wordprocessingml::Paragraph
    replace_paragraph(element, text)
  when Uniword::Wordprocessingml::Run
    replace_run(element, text)
  when Uniword::Wordprocessingml::TableCell
    replace_cell(element, text)
  else
    # Try to treat as paragraph-like
    replace_paragraph(element, text) if element.respond_to?(:runs)
  end
end