diff --git a/src/HTMLDocument.php b/src/HTMLDocument.php index 25fb932..0104534 100644 --- a/src/HTMLDocument.php +++ b/src/HTMLDocument.php @@ -112,24 +112,6 @@ public function getUnnamedTemplate( return $clone; } - public function pushTemplateParentStack( - string $name, - Element $element - ):void { - if(!isset($this->templateParentStack[$name])) { - $this->templateParentStack[$name] = []; - } - - $this->templateParentStack[$name] []= $element; - } - - public function insertTemplateParentStack():void { - ksort($this->templateParentStack); - foreach($this->templateParentStack as $name => $elementList) { - - } - } - public function getParentOfUnnamedTemplate( Element $element, bool $requireMatchingPath = false diff --git a/src/TemplateParent.php b/src/TemplateParent.php index 8dfd1e2..8d32c64 100644 --- a/src/TemplateParent.php +++ b/src/TemplateParent.php @@ -196,7 +196,6 @@ protected function loadComponent(string $name, string $path):DocumentFragment { } $fragment->appendHTML($html); - $fragment->extractTemplates(); return $fragment; } diff --git a/test/unit/Helper/Helper.php b/test/unit/Helper/Helper.php index d9e676d..31fb60a 100644 --- a/test/unit/Helper/Helper.php +++ b/test/unit/Helper/Helper.php @@ -194,6 +194,22 @@ class Helper {
  • This is an item in the list
  • HTML; + const COMPONENT_WITH_TEMPLATE = << +
  • Test
  • + +HTML; + + const HTML_SIMPLE_LIST_COMPONENT = << + +Simple componentised list test +
    + +
    +HTML; + + const HTML_BIND_UNKNOWN_PROPERTY = << diff --git a/test/unit/TemplateParentTest.php b/test/unit/TemplateParentTest.php index d555d16..9da4616 100644 --- a/test/unit/TemplateParentTest.php +++ b/test/unit/TemplateParentTest.php @@ -182,8 +182,8 @@ public function testComponentWithinTemplate() { Helper::HTML_TEMPLATE_WITH_NESTED_COMPONENT, $templateDir ); - $document->extractTemplates(); $document->expandComponents(); + $document->extractTemplates(); self::assertCount( 0, @@ -243,8 +243,7 @@ public function testNestedComponentsExpandWhenTemplateInserted() { $templateDir ); $document->expandComponents(); - - $document->getTemplate("title-definition-item")->insertTemplate(); + $document->extractTemplates(); $section = $document->querySelector("section"); $ol = $section->lastElementChild; @@ -420,4 +419,31 @@ public function testExistingClassesAreAddedToComponents() { $component->classList->contains("source-class") ); } + + /** @link https://github.com/PhpGt/DomTemplate/issues/105 */ + public function testTemplateWithinComponentIsAddedCorrectly() { + $componentDir = self::TEST_DIR . "/" . self::COMPONENT_PATH; + file_put_contents( + "$componentDir/simple-list.html", + Helper::COMPONENT_WITH_TEMPLATE + ); + + $document = new HTMLDocument( + Helper::HTML_SIMPLE_LIST_COMPONENT, + $componentDir + ); + $document->expandComponents(); + $document->extractTemplates(); + + $componentElement = $document->querySelector(".c-simple-list"); + self::assertCount(0, $componentElement->children); + + $componentElement->bindList([ + "one", + "two", + "three", + ]); + + self::assertCount(3, $componentElement->children); + } } \ No newline at end of file