Class: Textus::Protocol::Manifest::Entry::Publish::ToPaths
- Defined in:
- lib/textus/protocol/manifest/entry/publish.rb
Overview
publish.to: render or copy the entry's stored data to each fixed repo path.
Instance Attribute Summary
Attributes inherited from Mode
Instance Method Summary collapse
-
#initialize(entry, publisher: Textus::Infra::Port::Publisher.new) ⇒ ToPaths
constructor
A new instance of ToPaths.
- #publish(pctx, prefix: nil) ⇒ Object
Methods inherited from Mode
Constructor Details
Instance Method Details
#publish(pctx, prefix: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/textus/protocol/manifest/entry/publish.rb', line 68 def publish(pctx, prefix: nil) 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(key: entry.key) content = nil targets.each do |t| if t.renders? content ||= Textus::Protocol::Format.for(entry.format).parse(File.read(data_path), path: data_path)["content"] publish_bytes(render_bytes(t, content, pctx), entry.key, t, pctx, data_path, envelope) elsif (entry) content ||= Textus::Protocol::Format.for(entry.format).parse(File.read(data_path), path: data_path)["content"] bytes = Textus::Protocol::Format.for(entry.format).serialize(meta: {}, body: "", content: content) publish_bytes(bytes, entry.key, t, pctx, data_path, envelope) else 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 |