Start the documentation module.
authorGunnar Wrobel <p@rdus.de>
Mon, 10 Jan 2011 13:16:28 +0000 (14:16 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 10 Jan 2011 13:16:28 +0000 (14:16 +0100)
components/lib/Components/Dependencies.php
components/lib/Components/Dependencies/Injector.php
components/lib/Components/Module/Document.php [new file with mode: 0644]
components/test/Components/Integration/Components/Module/DocumentTest.php [new file with mode: 0644]

index bddd35a..725f148 100644 (file)
@@ -67,6 +67,13 @@ interface Components_Dependencies
     public function getRunnerDistribute();
 
     /**
+     * Returns the documentation handler for a package.
+     *
+     * @return Components_Runner_Document The distribution handler.
+     */
+    public function getRunnerDocument();
+
+    /**
      * Returns the installer for a package.
      *
      * @return Components_Runner_Installer The installer.
index c31784e..ca38466 100644 (file)
@@ -38,6 +38,9 @@ implements Components_Dependencies
     {
         parent::__construct(new Horde_Injector_TopLevel());
         $this->setInstance('Components_Dependencies', $this);
+        $this->bindFactory(
+            'Horde_Cli', 'Components_Dependencies', 'createCli'
+        );
     }
 
     /**
@@ -83,6 +86,16 @@ implements Components_Dependencies
     }
 
     /**
+     * Returns the documentation handler for a package.
+     *
+     * @return Components_Runner_Document The distribution handler.
+     */
+    public function getRunnerDocument()
+    {
+        return $this->getInstance('Components_Runner_Document');
+    }
+
+    /**
      * Returns the snapshot packaging handler for a package.
      *
      * @return Components_Runner_DevPackage The snapshot handler.
@@ -131,4 +144,14 @@ implements Components_Dependencies
     {
         return $this->getInstance('Components_Output');
     }
+
+    /**
+     * Create the CLI handler.
+     *
+     * @return Horde_Cli The CLI handler.
+     */
+    public function createCli()
+    {
+        return Horde_Cli::init();
+    }
 }
\ No newline at end of file
diff --git a/components/lib/Components/Module/Document.php b/components/lib/Components/Module/Document.php
new file mode 100644 (file)
index 0000000..a926972
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Components_Module_Document:: generates HTML documentation for a
+ * component.
+ *
+ * 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_Module_Document:: generates HTML documentation for a
+ * component.
+ *
+ * Copyright 2010 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_Module_Document
+extends Components_Module_Base
+{
+    /**
+     * Return the title for the option group representing this module.
+     *
+     * @return string The group title.
+     */
+    public function getOptionGroupTitle()
+    {
+        return 'Document';
+    }
+
+    /**
+     * Return the description for the option group representing this module.
+     *
+     * @return string The group description.
+     */
+    public function getOptionGroupDescription()
+    {
+        return 'This module generates HTML documentation for the component.';
+    }
+
+    /**
+     * Return the options for this module.
+     *
+     * @return array The group options.
+     */
+    public function getOptionGroupOptions()
+    {
+        return array(
+            new Horde_Argv_Option(
+                '-O',
+                '--document',
+                array(
+                    'action' => 'store',
+                    'help'   => 'Generate the documentation for the component in the specified DOCUMENT root location. The name of the component will be added to this root path.'
+                )
+            ),
+        );
+    }
+
+    /**
+     * Determine if this module should act. Run all required actions if it has
+     * been instructed to do so.
+     *
+     * @return NULL
+     */
+    public function handle(Components_Config $config)
+    {
+        $options = $config->getOptions();
+        if (!empty($options['document'])) {
+            $this->requirePackageXml($config->getPackageDirectory());
+            $this->_dependencies->getRunnerDocument()->run();
+        }
+    }
+}
diff --git a/components/test/Components/Integration/Components/Module/DocumentTest.php b/components/test/Components/Integration/Components/Module/DocumentTest.php
new file mode 100644 (file)
index 0000000..69d9c58
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Test the Document module.
+ *
+ * PHP version 5
+ *
+ * @category   Horde
+ * @package    Components
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the Document module.
+ *
+ * Copyright 2010 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
+ * @subpackage UnitTests
+ * @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_Integration_Components_Module_DocumentTest
+extends Components_StoryTestCase
+{
+    /**
+     * @scenario
+     */
+    public function theDocumentModuleAddsTheOOptionInTheHelpOutput()
+    {
+        $this->given('the default Components setup')
+            ->when('calling the package with the help option')
+            ->then('the help will contain the option', '-O\s*DOCUMENT,\s*--document=DOCUMENT');
+    }
+}
\ No newline at end of file