Class: Textus::Manifest::Entry::Publish::ToPaths
- Defined in:
- lib/textus/manifest/entry/publish/to_paths.rb
Overview
publish.to: render or copy the entry’s stored data to each fixed repo path. The behaviour of any entry that declares ‘publish: [{ to: … }, …]`. ADR 0094: iterates publish_targets (to-targets), rendering through a template when the target declares one, or copying verbatim otherwise.
Instance Attribute Summary
Attributes inherited from Mode
Instance Method Summary collapse
-
#initialize(entry, publisher: Textus::Ports::Publisher.new) ⇒ ToPaths
constructor
A new instance of ToPaths.
-
#publish(pctx, prefix: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics/AbcSize.
Methods inherited from Mode
Constructor Details
Instance Method Details
#publish(pctx, prefix: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics/AbcSize
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/textus/manifest/entry/publish/to_paths.rb', line 17 def publish(pctx, prefix: nil) # rubocop:disable Lint/UnusedMethodArgument,Metrics/AbcSize targets = entry.publish_targets.select(&:to_target?) return nil if targets.empty? data_path = pctx.manifest.resolver.resolve(entry.key).path envelope = pctx.reader.call(entry.key) renderer = Textus::Produce::Render.new(template_loader: ->(n) { pctx.read_template(n) }) content = nil # parsed lazily; the data's `content` (always _meta-free) targets.each do |t| if t.renders? content ||= Textus::Entry.for_format(entry.format).parse(File.read(data_path), path: data_path)["content"] publish_bytes(render_bytes(t, content, renderer, pctx), entry.key, t, pctx, data_path, envelope) elsif (entry) content ||= Textus::Entry.for_format(entry.format).parse(File.read(data_path), path: data_path)["content"] bytes = Textus::Entry.for_format(entry.format).serialize(meta: {}, body: "", content: content) publish_bytes(bytes, entry.key, t, pctx, data_path, envelope) else # opaque / command / non-structured — publish the stored file as-is target_abs = File.join(pctx.repo_root, t.to) @publisher.publish(source: data_path, target: target_abs, store_root: pctx.root) pctx.emit(:entry_published, key: entry.key, envelope: envelope, source: data_path, target: target_abs) end end { kind: :built, value: { "key" => entry.key, "path" => data_path, "published_to" => targets.map(&:to) } } end |