Skip to content

Commit

Permalink
Presenter::formatLayoutTemplateFiles() finds layouts in parent presen…
Browse files Browse the repository at this point in the history
…ters locations (BC break)
  • Loading branch information
dg committed May 25, 2015
1 parent e15c4d2 commit b5a4a62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ public function formatLayoutTemplateFiles()
$name = $this->getName();
$presenter = substr($name, strrpos(':' . $name, ':'));
$layout = $this->layout ? $this->layout : 'layout';
$dir = dirname($this->getReflection()->getFileName());
$rc = $this->getReflection();
$dir = dirname($rc->getFileName());
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
$list = [
"$dir/templates/$presenter/@$layout.latte",
Expand All @@ -512,6 +513,10 @@ public function formatLayoutTemplateFiles()
$list[] = "$dir/templates/@$layout.latte";
$dir = dirname($dir);
} while ($dir && ($name = substr($name, 0, strrpos($name, ':'))));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,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/Two.@layout.latte',
__DIR__ . '/templates/@layout.latte',
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
], $presenter->formatLayoutTemplateFiles() );
});

Expand All @@ -52,7 +53,7 @@ test(function() { // with module & subdir templates
});


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 @@ -62,5 +63,6 @@ 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() );
});

0 comments on commit b5a4a62

Please sign in to comment.