From 8e69364ee5c1a99998a7fcd62a49735dfaa2f271 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Fri, 14 Jan 2011 15:18:48 +0100 Subject: [PATCH] Allow modifications to the target location within the template. --- components/lib/Components/Helper/Template/Php.php | 4 +- .../Unit/Components/Helper/TemplatesTest.php | 44 ++++++++-------------- .../test/Components/fixture/templates/rewrite/one | 5 +++ 3 files changed, 23 insertions(+), 30 deletions(-) create mode 100644 components/test/Components/fixture/templates/rewrite/one diff --git a/components/lib/Components/Helper/Template/Php.php b/components/lib/Components/Helper/Template/Php.php index abc8fdca6..611239fda 100644 --- a/components/lib/Components/Helper/Template/Php.php +++ b/components/lib/Components/Helper/Template/Php.php @@ -40,8 +40,10 @@ extends Components_Helper_Template foreach ($parameters as $key => $value) { ${$key} = $value; } + $tdir = dirname($this->_target); + $target = basename($this->_target); ob_start(); include $this->_source; - file_put_contents($this->_target, ob_get_clean()); + file_put_contents($tdir . DIRECTORY_SEPARATOR . $target, ob_get_clean()); } } \ No newline at end of file diff --git a/components/test/Components/Unit/Components/Helper/TemplatesTest.php b/components/test/Components/Unit/Components/Helper/TemplatesTest.php index d6282a714..769ef8b80 100644 --- a/components/test/Components/Unit/Components/Helper/TemplatesTest.php +++ b/components/test/Components/Unit/Components/Helper/TemplatesTest.php @@ -104,35 +104,6 @@ extends Components_TestCase $templates->write(array('1' => new stdClass, '2' => 'Two')); } - public function testPrefix() - { - $tdir = $this->getTemporaryDirectory(); - $templates = new Components_Helper_Templates_Prefix( - dirname(__FILE__) . '/../../../fixture/templates', - $tdir, - 'var', - 'target' - ); - $templates->write(array('1' => 'One', '2' => 'Two')); - $this->assertEquals( - "One : Two\n", - file_get_contents($tdir . DIRECTORY_SEPARATOR . 'target') - ); - } - - /** - * @expectedException Components_Exception - */ - public function testMissingPrefixTemplate() - { - $templates = new Components_Helper_Templates_Prefix( - dirname(__FILE__) . '/../../../fixture/templates', - $this->getTemporaryDirectory(), - 'NOSUCHPREFIX', - 'target' - ); - } - public function testPhp() { $tdir = $this->getTemporaryDirectory(); @@ -212,4 +183,19 @@ extends Components_TestCase file_get_contents($tdir . DIRECTORY_SEPARATOR . 'two') ); } + + public function testTargetRewrite() + { + $tdir = $this->getTemporaryDirectory(); + $templates = new Components_Helper_Templates_Directory( + dirname(__FILE__) . '/../../../fixture/templates/rewrite', + $tdir + ); + $templates->write(array('one' => 'One')); + $this->assertEquals( + "One", + file_get_contents($tdir . DIRECTORY_SEPARATOR . 'rewritten') + ); + } + } \ No newline at end of file diff --git a/components/test/Components/fixture/templates/rewrite/one b/components/test/Components/fixture/templates/rewrite/one new file mode 100644 index 000000000..2215c832e --- /dev/null +++ b/components/test/Components/fixture/templates/rewrite/one @@ -0,0 +1,5 @@ +