Skip to content

Commit

Permalink
[Templating] removed CompilableLoaderInterface and fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 20, 2010
1 parent 6ea8782 commit 46a8a17
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 77 deletions.
8 changes: 0 additions & 8 deletions src/Symfony/Components/Templating/Loader/CacheLoader.php
Expand Up @@ -61,10 +61,6 @@ public function load($template, array $options = array())
$file = substr($tmp, 2);
$path = $dir.DIRECTORY_SEPARATOR.$file;

if ($this->loader instanceof CompilableLoaderInterface) {
$options['renderer'] = 'php';
}

if (file_exists($path)) {
if (null !== $this->debugger) {
$this->debugger->log(sprintf('Fetching template "%s" from cache', $template));
Expand All @@ -79,10 +75,6 @@ public function load($template, array $options = array())

$content = $storage->getContent();

if ($this->loader instanceof CompilableLoaderInterface) {
$content = $this->loader->compile($content);
}

if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
Expand Down

This file was deleted.

17 changes: 2 additions & 15 deletions tests/Symfony/Tests/Components/Templating/EngineTest.php
Expand Up @@ -15,7 +15,6 @@

use Symfony\Components\Templating\Engine;
use Symfony\Components\Templating\Loader\Loader;
use Symfony\Components\Templating\Loader\CompilableLoaderInterface;
use Symfony\Components\Templating\Renderer\Renderer;
use Symfony\Components\Templating\Renderer\PhpRenderer;
use Symfony\Components\Templating\Storage\Storage;
Expand Down Expand Up @@ -115,10 +114,6 @@ public function testExtendRender()
self::$loader->setTemplate('foo.php', '<?php $view->extend("layout"); echo $foo ?>');
self::$loader->setTemplate('layout.php', '<?php echo $view->render("bar") ?>-<?php echo $view->slots->get("_content") ?>-');
$this->assertEquals('bar-foo-', $engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), '->render() supports render() calls in templates');

// compilable templates
$engine = new ProjectTemplateEngine(new CompilableTemplateLoader(), array('foo' => new FooTemplateRenderer()));
$this->assertEquals('foo', $engine->render('index'), '->load() takes into account the renderer embedded in the Storage instance if not null');
}

public function testEscape()
Expand Down Expand Up @@ -176,18 +171,10 @@ public function load($template, array $options = array())

return false;
}
}

class CompilableTemplateLoader extends Loader implements CompilableLoaderInterface
{
public function load($template, array $options = array())
{
return new StringStorage($template, 'foo');
}

public function compile($template)
public function isFresh($template, array $options = array(), $time)
{
return 'COMPILED';
return false;
}
}

Expand Down
Expand Up @@ -15,7 +15,6 @@

use Symfony\Components\Templating\Loader\Loader;
use Symfony\Components\Templating\Loader\CacheLoader;
use Symfony\Components\Templating\Loader\CompilableLoaderInterface;
use Symfony\Components\Templating\Storage\StringStorage;

class CacheLoaderTest extends \PHPUnit_Framework_TestCase
Expand All @@ -39,20 +38,6 @@ public function testLoad()
$this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
$loader->load('index');
$this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');

// load() template compilation
$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999);
mkdir($dir, 0777, true);

$loader = new ProjectTemplateLoader(new CompilableTemplateLoader(), $dir);
$loader->setDebugger($debugger = new \ProjectTemplateDebugger());
$template = $loader->load('special', array('renderer' => 'comp'));
$this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
$this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');

$template = $loader->load('special', array('renderer' => 'comp'));
$this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
$this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');
}
}

Expand Down Expand Up @@ -89,12 +74,9 @@ public function load($template, array $options = array())

return false;
}
}

class CompilableTemplateLoader extends ProjectTemplateLoaderVar implements CompilableLoaderInterface
{
public function compile($template)
public function isFresh($template, array $options = array(), $time)
{
return preg_replace('/{{\s*([a-zA-Z0-9_]+)\s*}}/', '<?php echo $$1 ?>', $template);
return false;
}
}
Expand Up @@ -35,4 +35,9 @@ public function getDebugger()
{
return $this->debugger;
}

public function isFresh($template, array $options = array(), $time)
{
return false;
}
}

0 comments on commit 46a8a17

Please sign in to comment.