Class: Uniword::Template::TemplateMarker

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

Overview

Represents a template marker extracted from Word comments.

A marker is an instruction embedded in a Word document comment that tells the template engine how to process content (variable substitution, loops, conditionals).

Marker Types:

  • :variable - Simple variable substitution {variable_name}

  • :loop_start - Start of repeating section collection}

  • :loop_end - End of repeating section {@end}

  • :conditional_start - Start of conditional condition}

  • :conditional_end - End of conditional {@end}

Examples:

Variable marker

marker = TemplateMarker.new(
  type: :variable,
  expression: 'title',
  element: paragraph,
  position: 0
)

Loop marker

marker = TemplateMarker.new(
  type: :loop_start,
  collection: 'clauses',
  element: paragraph,
  position: 5
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ TemplateMarker

Initialize a template marker

Parameters:

  • attributes (Hash)

    Marker attributes

Options Hash (attributes):

  • :type (Symbol)

    Marker type

  • :collection (String)

    Collection name (for loops)

  • :condition (String)

    Condition (for conditionals)

  • :expression (String)

    Variable expression

  • :element (Element)

    Document element

  • :position (Integer)

    Document position



53
54
55
56
57
58
59
60
# File 'lib/uniword/template/template_marker.rb', line 53

def initialize(attributes)
  @type = attributes[:type]
  @collection = attributes[:collection]
  @condition = attributes[:condition]
  @expression = attributes[:expression]
  @element = attributes[:element]
  @position = attributes[:position]
end

Instance Attribute Details

#collectionString (readonly)

Collection name for loops

Returns:

  • (String)

    the current value of collection



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def collection
  @collection
end

#conditionString (readonly)

Condition expression for conditionals

Returns:

  • (String)

    the current value of condition



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def condition
  @condition
end

#elementElement (readonly)

The document element this marker is attached to

Returns:

  • (Element)

    the current value of element



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def element
  @element
end

#expressionString (readonly)

Variable expression

Returns:

  • (String)

    the current value of expression



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def expression
  @expression
end

#positionInteger (readonly)

Document position for sorting

Returns:

  • (Integer)

    the current value of position



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def position
  @position
end

#typeSymbol (readonly)

Marker type

Returns:

  • (Symbol)

    the current value of type



40
41
42
# File 'lib/uniword/template/template_marker.rb', line 40

def type
  @type
end

Instance Method Details

#conditional_end?Boolean

Check if marker is a conditional end

Returns:

  • (Boolean)

    true if conditional end



86
87
88
# File 'lib/uniword/template/template_marker.rb', line 86

def conditional_end?
  @type == :conditional_end
end

#conditional_start?Boolean

Check if marker is a conditional start

Returns:

  • (Boolean)

    true if conditional start



79
80
81
# File 'lib/uniword/template/template_marker.rb', line 79

def conditional_start?
  @type == :conditional_start
end

#inspectString

Inspect marker for debugging

Returns:

  • (String)

    Readable representation



116
117
118
# File 'lib/uniword/template/template_marker.rb', line 116

def inspect
  "#<TemplateMarker type=#{@type} name=#{name.inspect} position=#{@position}>"
end

#loop_end?Boolean

Check if marker is a loop end

Returns:

  • (Boolean)

    true if loop end



72
73
74
# File 'lib/uniword/template/template_marker.rb', line 72

def loop_end?
  @type == :loop_end
end

#loop_start?Boolean

Check if marker is a loop start

Returns:

  • (Boolean)

    true if loop start



65
66
67
# File 'lib/uniword/template/template_marker.rb', line 65

def loop_start?
  @type == :loop_start
end

#nameString

Get marker name for display

Returns:

  • (String)

    Marker name



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/uniword/template/template_marker.rb', line 100

def name
  case @type
  when :variable
    @expression
  when :loop_start
    @collection
  when :conditional_start
    @condition
  else
    @type.to_s
  end
end

#variable?Boolean

Check if marker is a variable

Returns:

  • (Boolean)

    true if variable



93
94
95
# File 'lib/uniword/template/template_marker.rb', line 93

def variable?
  @type == :variable
end