- WWW frontend
- The package descriptions need to be escaped when writing them into
- the Hudson config.xml file
+ the Hudson config.xml file (probably means that the templating
+ should be switched to PHP based templates)
- Allow channel dependency detection with external/local package
dependencies.
--- /dev/null
+<?php
+/**
+ * Components_Helper_Templates_Directory:: converts template files from a
+ * directory into files in a target directory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * Components_Helper_Templates_Directory:: converts template files from a
+ * directory into files in a target directory.
+ *
+ * Copyright 2011 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+class Components_Helper_Templates_Directory
+extends Components_Helper_Templates
+{
+ /**
+ * The source location.
+ *
+ * @var string
+ */
+ private $_source;
+
+ /**
+ * The target location.
+ *
+ * @var string
+ */
+ private $_target;
+
+ /**
+ * Constructor.
+ *
+ * @param string $sdir The templates source directory.
+ * @param string $tdir The templates target directory.
+ */
+ public function __construct($sdir, $tdir)
+ {
+ if (file_exists($sdir)) {
+ $this->_source = $sdir;
+ } else {
+ throw new Components_Exception("No template directory at $sdir!");
+ }
+ $this->_target = $tdir;
+ }
+
+ /**
+ * Rewrite the template(s) from the source(s) to the target location(s).
+ *
+ * @param array $parameters The template(s) parameters.
+ *
+ * @return NULL
+ */
+ public function write(array $parameters = array())
+ {
+ if (!file_exists($this->_target)) {
+ mkdir($this->_target, 0777, true);
+ }
+ foreach (
+ new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($this->_source)
+ )
+ as $file
+ ) {
+ if ($file->isFile()) {
+ $this->writeSourceToTarget(
+ $file->getPathname(),
+ $this->_target . DIRECTORY_SEPARATOR . $file->getBasename(),
+ $parameters
+ );
+ }
+ }
+ }
+}
\ No newline at end of file
<email>jan@horde.org</email>
<active>yes</active>
</lead>
- <date>2011-01-11</date>
- <time>11:29:20</time>
+ <date>2011-01-12</date>
+ <time>10:29:42</time>
<version>
<release>0.0.1</release>
<api>0.0.1</api>
<file name="Printf.php" role="php" />
</dir> <!-- /lib/Components/Helper/Template -->
<dir name="Templates">
+ <file name="Directory.php" role="php" />
<file name="Prefix.php" role="php" />
<file name="Single.php" role="php" />
</dir> <!-- /lib/Components/Helper/Templates -->
<file name="IGNORE.txt" role="test" />
</dir> <!-- /test/Components/fixture/simple -->
<dir name="templates">
+ <dir name="dir">
+ <file name="one" role="test" />
+ <file name="two" role="test" />
+ </dir> <!-- /test/Components/fixture/templates/dir -->
<file name="hudson-component-build.xml.template" role="test" />
<file name="hudson-component-config.xml.template" role="test" />
<file name="hudson-component-phpunit.xml.template" role="test" />
<install as="Components/Helper/Tree.php" name="lib/Components/Helper/Tree.php" />
<install as="Components/Helper/Template/Php.php" name="lib/Components/Helper/Template/Php.php" />
<install as="Components/Helper/Template/Printf.php" name="lib/Components/Helper/Template/Printf.php" />
+ <install as="Components/Helper/Templates/Directory.php" name="lib/Components/Helper/Templates/Directory.php" />
<install as="Components/Helper/Templates/Prefix.php" name="lib/Components/Helper/Templates/Prefix.php" />
<install as="Components/Helper/Templates/Single.php" name="lib/Components/Helper/Templates/Single.php" />
<install as="Components/Module/Base.php" name="lib/Components/Module/Base.php" />
<install as="Components/fixture/templates/php.template" name="test/Components/fixture/templates/php.template" />
<install as="Components/fixture/templates/simple.template" name="test/Components/fixture/templates/simple.template" />
<install as="Components/fixture/templates/variables.template" name="test/Components/fixture/templates/variables.template" />
+ <install as="Components/fixture/templates/dir/one" name="test/Components/fixture/templates/dir/one" />
+ <install as="Components/fixture/templates/dir/two" name="test/Components/fixture/templates/dir/two" />
<install as="Components/Integration/ComponentsTest.php" name="test/Components/Integration/ComponentsTest.php" />
<install as="Components/Integration/Components/Module/CiSetupTest.php" name="test/Components/Integration/Components/Module/CiSetupTest.php" />
<install as="Components/Integration/Components/Module/DependenciesTest.php" name="test/Components/Integration/Components/Module/DependenciesTest.php" />
<release>alpha</release>
<api>alpha</api>
</stability>
- <date>2011-01-11</date>
+ <date>2011-01-12</date>
<license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
<notes>
* Initial release
*/
public function testMissingPrefixTemplate()
{
- $tdir = $this->getTemporaryDirectory();
$templates = new Components_Helper_Templates_Prefix(
dirname(__FILE__) . '/../../../fixture/templates',
- $tdir,
+ $this->getTemporaryDirectory(),
'NOSUCHPREFIX',
'target'
);
file_get_contents($tdir . DIRECTORY_SEPARATOR . 'target')
);
}
+
+ public function testDirectory()
+ {
+ $tdir = $this->getTemporaryDirectory();
+ $templates = new Components_Helper_Templates_Directory(
+ dirname(__FILE__) . '/../../../fixture/templates/dir',
+ $tdir
+ );
+ $templates->write(array('one' => 'One', 'two' => 'Two'));
+ $this->assertEquals(
+ "One",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'one')
+ );
+ $this->assertEquals(
+ "Two",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'two')
+ );
+ }
+
+ /**
+ * @expectedException Components_Exception
+ */
+ public function testMissingDirectory()
+ {
+ new Components_Helper_Templates_Directory(
+ dirname(__FILE__) . '/../../../fixture/templates/NOSUCHDIR',
+ $this->getTemporaryDirectory()
+ );
+ }
+
+ public function testMissingTargetDirectory()
+ {
+ $tdir = $this->getTemporaryDirectory() . DIRECTORY_SEPARATOR
+ . 'a' .DIRECTORY_SEPARATOR . 'b';
+ $templates = new Components_Helper_Templates_Directory(
+ dirname(__FILE__) . '/../../../fixture/templates/dir',
+ $tdir
+ );
+ $templates->write(array('one' => 'One', 'two' => 'Two'));
+ $this->assertEquals(
+ "One",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'one')
+ );
+ $this->assertEquals(
+ "Two",
+ file_get_contents($tdir . DIRECTORY_SEPARATOR . 'two')
+ );
+ }
}
\ No newline at end of file
--- /dev/null
+<?php
+
+echo $one;
--- /dev/null
+<?php
+
+echo $two;