Class: Uniword::Template::TemplateParser
- Inherits:
-
Object
- Object
- Uniword::Template::TemplateParser
- Defined in:
- lib/uniword/template/template_parser.rb
Overview
Parses template syntax from Word document comments.
Extracts template markers (variables, loops, conditionals) from comments attached to document elements. Converts Uniword template syntax into structured marker objects.
Responsibility: Marker extraction only Single Responsibility Principle: Does NOT render or validate
Template Syntax:
-
{variable} - Variable substitution
-
{object{object.property} - Nested property access
-
collection} - Loop start
-
{@end} - Loop/conditional end
-
condition} - Conditional start
-
condition} - Negative conditional
Instance Method Summary collapse
-
#initialize(document) ⇒ TemplateParser
constructor
Initialize parser with document.
-
#parse ⇒ Array<TemplateMarker>
Parse all markers from document.
Constructor Details
#initialize(document) ⇒ TemplateParser
Initialize parser with document
32 33 34 35 |
# File 'lib/uniword/template/template_parser.rb', line 32 def initialize(document) @document = document @markers = [] end |
Instance Method Details
#parse ⇒ Array<TemplateMarker>
Parse all markers from document
Iterates through paragraphs and tables, extracting markers from comments. Returns markers sorted by document position.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/uniword/template/template_parser.rb', line 43 def parse @markers = [] # Parse paragraphs parse_paragraphs(@document.paragraphs) # Parse tables parse_tables(@document.tables) if @document.tables.any? # Sort markers by document order @markers.sort_by(&:position) end |