Class: Uniword::Template::TemplateMarker
- Inherits:
-
Object
- Object
- Uniword::Template::TemplateMarker
- 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}
Instance Attribute Summary collapse
-
#collection ⇒ String
readonly
Collection name for loops.
-
#condition ⇒ String
readonly
Condition expression for conditionals.
-
#element ⇒ Element
readonly
The document element this marker is attached to.
-
#expression ⇒ String
readonly
Variable expression.
-
#position ⇒ Integer
readonly
Document position for sorting.
-
#type ⇒ Symbol
readonly
Marker type.
Instance Method Summary collapse
-
#conditional_end? ⇒ Boolean
Check if marker is a conditional end.
-
#conditional_start? ⇒ Boolean
Check if marker is a conditional start.
-
#initialize(attributes) ⇒ TemplateMarker
constructor
Initialize a template marker.
-
#inspect ⇒ String
Inspect marker for debugging.
-
#loop_end? ⇒ Boolean
Check if marker is a loop end.
-
#loop_start? ⇒ Boolean
Check if marker is a loop start.
-
#name ⇒ String
Get marker name for display.
-
#variable? ⇒ Boolean
Check if marker is a variable.
Constructor Details
#initialize(attributes) ⇒ TemplateMarker
Initialize a template marker
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
#collection ⇒ String (readonly)
Collection name for loops
40 41 42 |
# File 'lib/uniword/template/template_marker.rb', line 40 def collection @collection end |
#condition ⇒ String (readonly)
Condition expression for conditionals
40 41 42 |
# File 'lib/uniword/template/template_marker.rb', line 40 def condition @condition end |
#element ⇒ Element (readonly)
The document element this marker is attached to
40 41 42 |
# File 'lib/uniword/template/template_marker.rb', line 40 def element @element end |
#expression ⇒ String (readonly)
Variable expression
40 41 42 |
# File 'lib/uniword/template/template_marker.rb', line 40 def expression @expression end |
#position ⇒ Integer (readonly)
Document position for sorting
40 41 42 |
# File 'lib/uniword/template/template_marker.rb', line 40 def position @position end |
#type ⇒ Symbol (readonly)
Marker 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
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
79 80 81 |
# File 'lib/uniword/template/template_marker.rb', line 79 def conditional_start? @type == :conditional_start end |
#inspect ⇒ String
Inspect marker for debugging
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
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
65 66 67 |
# File 'lib/uniword/template/template_marker.rb', line 65 def loop_start? @type == :loop_start end |
#name ⇒ String
Get marker name for display
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
93 94 95 |
# File 'lib/uniword/template/template_marker.rb', line 93 def variable? @type == :variable end |