Skip to content

Commit

Permalink
Include library basename in compiled templates.
Browse files Browse the repository at this point in the history
Fixes overwriting of templates when two different libraries have templates for same controller/action pair.

Refs #611.
Obsoletes #992.

Updating test for template name change.
  • Loading branch information
mariuswilms committed Dec 20, 2013
1 parent 60bbe47 commit 34346cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion template/view/Compiler.php
Expand Up @@ -58,7 +58,10 @@ public static function template($file, array $options = array()) {

$stats = stat($file);
$dir = dirname($file);
$oname = basename(dirname($dir)) . '_' . basename($dir) . '_' . basename($file, '.php');

$oname = basename(dirname(dirname($dir))) . '_' . basename(dirname($dir));
$oname .= '_' . basename($dir) . '_' . basename($file, '.php');

$template = "template_{$oname}_{$stats['ino']}_{$stats['mtime']}_{$stats['size']}.php";
$template = "{$options['path']}/{$template}";

Expand Down
7 changes: 5 additions & 2 deletions tests/cases/template/view/adapter/FileTest.php
Expand Up @@ -66,7 +66,9 @@ public function testContextOffsetManipulation() {
* directory.
*/
public function testTemplateLocating() {
$path = Libraries::get(true, 'path') . '/views/pages/home.html.php';
$base = Libraries::get(true, 'path');

$path = $base . '/views/pages/home.html.php';
$this->skipIf(!file_exists($path), 'No default app template.');

$file = new File(array('paths' => array(
Expand All @@ -76,7 +78,8 @@ public function testTemplateLocating() {
$template = $file->template('template', array(
'controller' => 'pages', 'template' => 'home', 'type' => 'html'
));
$this->assertPattern('/template_views_pages_home\.html_[0-9]+/', $template);
$pattern = '/template_' . basename($base) . '_views_pages_home\.html_[0-9]+/';
$this->assertPattern($pattern, $template);

$file = new File(array('compile' => false, 'paths' => array(
'template' => '{:library}/views/{:controller}/{:template}.{:type}.php'
Expand Down

0 comments on commit 34346cb

Please sign in to comment.