Skip to content
Open
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
16 changes: 11 additions & 5 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,21 @@ public function formatLayoutTemplateFiles(): array
}
[$module, $presenter] = Helpers::splitName($this->getName());
$layout = $this->layout ? $this->layout : 'layout';
$dir = dirname($this->getReflection()->getFileName());
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
$rc = $this->getReflection();
$dir = dirname($rc->getFileName());
$dir = ($newWay = is_dir("$dir/templates")) ? $dir : dirname($dir);
$list = [
"$dir/templates/$presenter/@$layout.latte",
"$dir/templates/$presenter.@$layout.latte",
];
do {
$list[] = "$dir/templates/@$layout.latte";
$dir = dirname($dir);
$dir = $newWay ? false : dirname($dir);
} while ($dir && $module && ([$module] = Helpers::splitName($module)));

while (($rc = $rc->getParentClass()) && $rc->getName() !== __CLASS__) {
$list[] = dirname($rc->getFileName()) . "/templates/@$layout.latte";
}
return $list;
}

Expand All @@ -505,11 +510,12 @@ public function formatLayoutTemplateFiles(): array
public function formatTemplateFiles(): array
{
[, $presenter] = Helpers::splitName($this->getName());
$dir = dirname($this->getReflection()->getFileName());
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
$presenterDir = dirname($this->getReflection()->getFileName());
$dir = is_dir("$presenterDir/templates") ? $presenterDir : dirname($presenterDir);
return [
"$dir/templates/$presenter/$this->view.latte",
"$dir/templates/$presenter.$this->view.latte",
"$presenterDir/templates/$this->view.latte",
];
}

Expand Down
8 changes: 4 additions & 4 deletions tests/UI/Presenter.formatLayoutTemplateFiles.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ test(function () { // with subdir templates
});


test(function () { // without subdir templates
test(function () { // without subdir templates & parent presenter
$presenter = new Presenter2;
$presenter->setParent(null, 'Two');

Assert::same([
__DIR__ . '/templates/Two/@layout.latte',
__DIR__ . '/templates/[email protected]',
__DIR__ . '/templates/@layout.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
], $presenter->formatLayoutTemplateFiles());
});

Expand All @@ -47,13 +48,11 @@ test(function () { // with module & subdir templates
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/@layout.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/[email protected]',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
__DIR__ . '/templates/@layout.latte',
dirname(__DIR__) . '/templates/@layout.latte',
], $presenter->formatLayoutTemplateFiles());
});


test(function () { // with module & without subdir templates
test(function () { // with module & without subdir templates & parent presenter
$presenter = new Presenter2;
$presenter->setParent(null, 'Module:SubModule:Two');

Expand All @@ -63,6 +62,7 @@ test(function () { // with module & without subdir templates
__DIR__ . '/templates/@layout.latte',
dirname(__DIR__) . '/templates/@layout.latte',
dirname(dirname(__DIR__)) . '/templates/@layout.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
], $presenter->formatLayoutTemplateFiles());
});

Expand Down
4 changes: 4 additions & 0 deletions tests/UI/Presenter.formatTemplateFiles.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test(function () { // with subdir templates
Assert::same([
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One.view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/view.latte',
], $presenter->formatTemplateFiles());
});

Expand All @@ -34,6 +35,7 @@ test(function () { // without subdir templates
Assert::same([
__DIR__ . '/templates/Two/view.latte',
__DIR__ . '/templates/Two.view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'two/templates/view.latte',
], $presenter->formatTemplateFiles());
});

Expand All @@ -46,6 +48,7 @@ test(function () { // with module & subdir templates
Assert::same([
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One.view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/view.latte',
], $presenter->formatTemplateFiles());
});

Expand All @@ -58,5 +61,6 @@ test(function () { // with module & without subdir templates
Assert::same([
__DIR__ . '/templates/Two/view.latte',
__DIR__ . '/templates/Two.view.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'two/templates/view.latte',
], $presenter->formatTemplateFiles());
});