Browse Source

Rework Engine::process, handle variables in meta block

master
Adam Pippin 3 years ago
parent
commit
4056674c1d
  1. 57
      app/Engine/Engine.php

57
app/Engine/Engine.php

@ -52,39 +52,62 @@ class Engine
{
$file_helper = new File([dirname(realpath($input_file))]);
$documents = [];
// First, figure out which files to process and load all files.
$files = [basename($input_file)];
$processed = [];
for ($i = 0; $i < sizeof($files); $i++)
{
// Read the current document
$document = $this->unserialize->unserialize(file_get_contents($file_helper->resolve($files[$i])));
// If we haven't already examined this document's list of included templates,
// then read those and add them to the stack.
if (!in_array($files[$i], $processed))
if (!isset($documents[$files[$i]]))
{
$additional_files = [];
$documents[$files[$i]] = $document = $this->unserialize->unserialize(file_get_contents($file_helper->resolve($files[$i])));
try
{
$additional_files = $document->getMeta('stack');
$includes = $document->getMeta('stack');
}
catch (\Exception $ex)
{
}
// If the document specified any includes, then push those into our list of templates to process _before_
// the existing templates, then walk our loop index back one to reprocess the current index (now one of
// the inserted files)
if (sizeof($additional_files))
if (sizeof($includes))
{
$processed[] = $files[$i];
array_splice($files, $i, 0, $additional_files);
array_splice($files, $i, 0, $includes);
--$i;
continue;
}
}
}
$this->compileDocument($document);
// Go through and load all the variables
$variables = [];
for ($i = 0; $i < sizeof($files); $i++)
{
$file_variables = [];
try
{
$file_variables = $documents[$files[$i]]->getMeta('variables');
}
catch (\Exception $ex)
{
}
foreach ($file_variables as $k => $v)
{
$variables[$k] = $v;
}
}
foreach ($variables as $k => $v)
{
if (!$options->hasVariable($k))
{
$options->setVariable($k, $v);
}
}
// Now actually process all the documents
for ($i = 0; $i < sizeof($files); $i++)
{
$this->compileDocument($documents[$files[$i]]);
}
// Set metadata in output

Loading…
Cancel
Save