feat: add context tag handling to core's crafting functions

This commit is contained in:
David Bailey 2023-04-20 09:48:22 +02:00
parent eca98cda25
commit 1878186c4f

View file

@ -49,6 +49,10 @@ module Comfpile
end
end
def find_artefact(stage, file = :none, context = :default)
context = sanitize_context(context)
@artefacts.dig(context, stage, file)
end
# Create or find a new artefact.
@ -66,17 +70,20 @@ module Comfpile
#
# @return [Comfpile::Artefact, nil] Found or created artefact, or nil if nothing could be done
#
def craft_artefact(stage, file = :none)
artefact = find_artefact(stage, file)
def craft_artefact(stage, file = :none, context = :default)
context = sanitize_context(context)
artefact = find_artefact(stage, file, context)
return artefact unless artefact.nil?
@artefact_engines.each do |engine|
artefact = engine.craft stage, file
artefact = engine.craft stage, file, context
if artefact
@artefacts[stage] ||= {}
@artefacts[stage][file] = artefact
@artefacts[context] ||= {}
@artefacts[context][stage] ||= {}
@artefacts[context][stage][file] = artefact
@processing_stack.push artefact
@ -87,13 +94,16 @@ module Comfpile
nil
end
def add_artefact(stage, file = :none, engine: nil, artefact_class: Comfpile::Artefact)
return unless find_artefact(stage, file).nil?
def add_artefact(stage, file = :none, context = :default, engine: nil, artefact_class: Comfpile::Artefact)
context = sanitize_context context
a = Artefact.new(self, engine, stage, file);
return unless find_artefact(stage, file, context).nil?
a = Artefact.new(self, engine, stage, file, context);
@artefacts[stage] ||= {}
@artefacts[stage][file] = a
@artefacts[context] ||= {}
@artefacts[context][stage] ||= {}
@artefacts[context][stage][file] = a
yield(a) if block_given?