Skip to content

Commit

Permalink
Presenter: template file extension .latte is preferred over .phtml
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 12, 2010
1 parent 43f1089 commit 5bdf5b0
Show file tree
Hide file tree
Showing 34 changed files with 35 additions and 30 deletions.
7 changes: 6 additions & 1 deletion Nette/Application/Presenter.php
Expand Up @@ -462,10 +462,13 @@ public function formatLayoutTemplateFiles($presenter, $layout)
$path = '/' . str_replace(':', 'Module/', $presenter);
$pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0);
$list = array(
"$appDir$pathP/@$layout.latte",
"$appDir$pathP.@$layout.latte",
"$appDir$pathP/@$layout.phtml",
"$appDir$pathP.@$layout.phtml",
);
while (($path = substr($path, 0, strrpos($path, '/'))) !== FALSE) {
$list[] = "$appDir$path/templates/@$layout.latte";
$list[] = "$appDir$path/templates/@$layout.phtml";
}
return $list;
Expand All @@ -486,9 +489,11 @@ public function formatTemplateFiles($presenter, $view)
$pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0);
$path = substr_replace($path, '/templates', strrpos($path, '/'));
return array(
"$appDir$pathP/$view.latte",
"$appDir$pathP.$view.latte",
"$appDir$pathP/$view.phtml",
"$appDir$pathP.$view.phtml",
"$appDir$path/@global.$view.phtml",
"$appDir$path/@global.$view.phtml", // deprecated
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.001.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.phtml');
$template->setFile(__DIR__ . '/templates/common.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelper('translate', 'strrev');
$template->registerHelper('join', 'implode');
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.002.phpt
Expand Up @@ -29,7 +29,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.cache.phtml');
$template->setFile(__DIR__ . '/templates/cache.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelperLoader('Nette\Templates\TemplateHelpers::loader');

Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.003.phpt
Expand Up @@ -48,7 +48,7 @@ function types()


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.helpers.phtml');
$template->setFile(__DIR__ . '/templates/helpers.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelper('nl2br', 'nl2br');
$template->registerHelper('h1', array(new MyHelper, 'invoke'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.009.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.delimiters.phtml');
$template->setFile(__DIR__ . '/templates/delimiters.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelperLoader('Nette\Templates\TemplateHelpers::loader');
$template->people = array('John', 'Mary', 'Paul');
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.011.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.xml.phtml');
$template->setFile(__DIR__ . '/templates/xml.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelperLoader('Nette\Templates\TemplateHelpers::loader');

Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.018.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));

Nette\Web\Html::$xhtml = FALSE;
$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.phtml');
$template->setFile(__DIR__ . '/templates/common.latte');
$template->registerFilter(new LatteFilter);
$template->registerHelper('translate', 'strrev');
$template->registerHelper('join', 'implode');
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.019.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.first-sep-last.phtml');
$template->setFile(__DIR__ . '/templates/first-sep-last.latte');
$template->registerFilter(new LatteFilter);
$template->people = array('John', 'Mary', 'Paul');

Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.ext.001.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.inheritance.child1.phtml');
$template->setFile(__DIR__ . '/templates/inheritance.child1.latte');
$template->registerFilter(new LatteFilter);

$template->people = array('John', 'Mary', 'Paul');
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.ext.002.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.inheritance.child2.phtml');
$template->setFile(__DIR__ . '/templates/inheritance.child2.latte');
$template->registerFilter(new LatteFilter);

$template->people = array('John', 'Mary', 'Paul');
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.ext.003.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.inheritance.child3.phtml');
$template->setFile(__DIR__ . '/templates/inheritance.child3.latte');
$template->registerFilter(new LatteFilter);

Assert::match(<<<EOD
Expand Down
2 changes: 1 addition & 1 deletion tests/Templates/LatteFilter.macros.ext.004.phpt
Expand Up @@ -28,7 +28,7 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.inheritance.child4.phtml');
$template->setFile(__DIR__ . '/templates/inheritance.child4.latte');
$template->registerFilter(new LatteFilter);

Assert::match(<<<EOD
Expand Down
4 changes: 2 additions & 2 deletions tests/Templates/LatteFilter.macros.ext.005.phpt
Expand Up @@ -28,9 +28,9 @@ FileTemplate::setCacheStorage(new MockCacheStorage(TEMP_DIR));


$template = new FileTemplate;
$template->setFile(__DIR__ . '/templates/latte.inheritance.child5.phtml');
$template->setFile(__DIR__ . '/templates/inheritance.child5.latte');
$template->registerFilter(new LatteFilter);

$template->ext = 'latte.inheritance.parent.phtml';
$template->ext = 'inheritance.parent.latte';

Assert::match(file_get_contents(__DIR__ . '/LatteFilter.macros.ext.005.expect'), $template->__toString(TRUE));
2 changes: 1 addition & 1 deletion tests/Templates/Template.optimizePhp().phpt
Expand Up @@ -16,6 +16,6 @@ require __DIR__ . '/../bootstrap.php';



$input = file_get_contents(__DIR__ . '/templates/optimize.phtml');
$input = file_get_contents(__DIR__ . '/templates/optimize.latte');
$expected = file_get_contents(__DIR__ . '/Template.optimizePhp().expect');
Assert::match($expected, Template::optimizePhp($input));
@@ -1,5 +1,5 @@
<ul>
{foreach $menu as $item}
<li>{if is_array($item)} {include '@menu.phtml', 'menu' => $item} {else}{$item}{/if}</li>
<li>{if is_array($item)} {include '@menu.latte', 'menu' => $item} {else}{$item}{/if}</li>
{/foreach}
</ul>
Expand Up @@ -4,6 +4,6 @@ Noncached content

<h1>{$title|upper}</h1>

{include 'include.cache.phtml', 'localvar' => 11}
{include 'include.cache.latte', 'localvar' => 11}

{/cache}
Expand Up @@ -58,7 +58,7 @@ comment *}



{include 'subdir/include1.phtml', 'localvar' => 10 |indent}
{include 'subdir/include1.latte', 'localvar' => 10 |indent}



Expand Down Expand Up @@ -105,7 +105,7 @@ var prop2 = {$people};
{include '@menu.phtml'}
{include '@menu.latte'}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
{extends "latte.inheritance.parent.phtml"}
{extends "inheritance.parent.latte"}

{block title}Homepage | {include #parent}{/block}

Expand Down
@@ -1,4 +1,4 @@
{extends "latte.inheritance.parent.phtml"}
{extends "inheritance.parent.latte"}


{block content}
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/Templates/templates/subdir/include1.latte
@@ -0,0 +1,9 @@
<p>Included file #1</p>

{include "include2.latte", 'localvar' => 20}

{include ../include3.latte, }

<textarea>
pre
</textarea>
9 changes: 0 additions & 9 deletions tests/Templates/templates/subdir/include1.phtml

This file was deleted.

File renamed without changes.

0 comments on commit 5bdf5b0

Please sign in to comment.