Module: Textus::Builder::InjectMeta

Defined in:
lib/textus/builder/pipeline.rb

Class Method Summary collapse

Class Method Details

.call(content_hash, mentry) ⇒ Object

Returns a new hash with _meta as the first key, per SPEC §6 ordering.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/textus/builder/pipeline.rb', line 8

def self.call(content_hash, mentry)
  meta = { "generated_at" => Time.now.utc.iso8601 }
  if mentry.is_a?(Textus::Manifest::Entry::Derived)
    src = mentry.source
    if src.is_a?(Textus::Manifest::Entry::Derived::Projection)
      from = Array(src.select).compact
      meta["from"] = from unless from.empty?
      meta["reduce"] = src.transform if src.transform
    end
  end
  meta["template"] = mentry.template if mentry.template

  out = { "_meta" => meta }
  content_hash.each { |k, v| out[k] = v unless k == "_meta" }
  out
end