Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Logic/HTMLDocumentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ function processPartialContent(

$componentList = new LogicAssemblyComponentList();

try {
$partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [
getcwd(),
$this->partialDirectory,
]));

$partialExpander = new PartialExpander(
$model,
$partial,
);
$partialExpander->expand();
}
catch(PartialContentDirectoryNotFoundException) {}

try {
// TODO: Handle other model types in sub-functions.
$partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [
Expand Down Expand Up @@ -82,20 +96,6 @@ function processPartialContent(
}
catch(PartialContentDirectoryNotFoundException) {}

try {
$partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [
getcwd(),
$this->partialDirectory,
]));

$partialExpander = new PartialExpander(
$model,
$partial,
);
$partialExpander->expand();
}
catch(PartialContentDirectoryNotFoundException) {}

return $componentList;
}

Expand Down
30 changes: 30 additions & 0 deletions test/phpunit/Logic/HTMLDocumentProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ public function testProcessPartialContent_expandsComponentsAndPartialsAndRegiste
self::assertSame("no-logic", TestLogHandler::$records[0]["context"]["component"]);
}

public function testProcessPartialContent_expandsAndRegistersComponentsFromPartial():void {
file_put_contents(
$this->componentDir . "/site-card.html",
"<article><form method='post'><button>Save</button></form></article>",
);
file_put_contents($this->componentDir . "/site-card.php", "<?php\n");
file_put_contents(
$this->partialDir . "/layout.html",
"<!doctype html><html><body><site-card></site-card><main data-partial></main></body></html>",
);

$document = new HTMLDocument(
"<!doctype html><!-- extends = layout --><h1>Page</h1>"
);
$processor = new HTMLDocumentProcessor(
ltrim(substr($this->componentDir, strlen(getcwd())), "/"),
ltrim(substr($this->partialDir, strlen(getcwd())), "/"),
);

$componentList = $processor->processPartialContent($document);

self::assertCount(1, $componentList);
self::assertSame("site-card", strtolower($componentList[0]->component->tagName));
self::assertSame(
"site-card",
$document->querySelector("site-card input[name='__component']")?->getAttribute("value"),
);
self::assertStringContainsString("<h1>Page</h1>", (string)$document);
}

public function testProcessPartialContent_ignoresMissingDirectories():void {
$document = new HTMLDocument("<!doctype html><body><site-card></site-card></body>");
$processor = new HTMLDocumentProcessor(
Expand Down
Loading