Class: Textus::Produce::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/produce/render.rb

Overview

Renders an entry’s stored DATA into the bytes for one publish target (ADR 0094). Relocates the Mustache logic that used to live in the build-time Markdown renderer. Provenance is NOT added here — it lives in the data’s ‘_meta`; a template surfaces it if the output should show it. A verbatim target (no template) is the caller’s job to copy.

Instance Method Summary collapse

Constructor Details

#initialize(template_loader:) ⇒ Render

Returns a new instance of Render.



9
10
11
# File 'lib/textus/produce/render.rb', line 9

def initialize(template_loader:)
  @template_loader = template_loader
end

Instance Method Details

#bytes_for(target:, data:, boot:) ⇒ Object

target: a rendering Policy::PublishTarget. data: parsed entry data. boot: boot context hash or nil. Returns the rendered String.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/textus/produce/render.rb', line 15

def bytes_for(target:, data:, boot:)
  raise ArgumentError.new("Produce::Render called for a verbatim target #{target.to.inspect}") unless target.renders?

  ctx = target.inject_boot ? data.merge("boot" => boot) : data
  Mustache.render(@template_loader.call(target.template), ctx)
end