Class: Uniword::Template::TemplateRenderer
- Inherits:
-
Object
- Object
- Uniword::Template::TemplateRenderer
- Defined in:
- lib/uniword/template/template_renderer.rb
Overview
Renders templates by processing markers and filling with data.
Takes a template and data, processes all markers in order, and produces a filled document. Handles variable substitution, loops, and conditionals.
Responsibility: Template rendering only Single Responsibility Principle: Does NOT parse or validate
Instance Method Summary collapse
-
#initialize(template, data, additional_context = {}) ⇒ TemplateRenderer
constructor
Initialize renderer.
-
#render ⇒ Document
Render template with data.
Constructor Details
#initialize(template, data, additional_context = {}) ⇒ TemplateRenderer
Initialize renderer
26 27 28 29 30 31 |
# File 'lib/uniword/template/template_renderer.rb', line 26 def initialize(template, data, additional_context = {}) @template = template @data = data @additional_context = additional_context @context = TemplateContext.new(data, additional_context) end |
Instance Method Details
#render ⇒ Document
Render template with data
Creates a new document by cloning the template document and processing all markers.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/uniword/template/template_renderer.rb', line 39 def render # Clone template document output = clone_document(@template.document) # Process markers process_markers(output) # Remove template comments remove_template_comments(output) output end |