From 4b877c21b881f2db6ad6119e9b3c5b4411afc70e Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 10 Jan 2011 14:16:28 +0100 Subject: [PATCH] Start the documentation module. --- components/lib/Components/Dependencies.php | 7 ++ .../lib/Components/Dependencies/Injector.php | 23 ++++++ components/lib/Components/Module/Document.php | 86 ++++++++++++++++++++++ .../Integration/Components/Module/DocumentTest.php | 47 ++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 components/lib/Components/Module/Document.php create mode 100644 components/test/Components/Integration/Components/Module/DocumentTest.php diff --git a/components/lib/Components/Dependencies.php b/components/lib/Components/Dependencies.php index bddd35a6d..725f148d3 100644 --- a/components/lib/Components/Dependencies.php +++ b/components/lib/Components/Dependencies.php @@ -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. diff --git a/components/lib/Components/Dependencies/Injector.php b/components/lib/Components/Dependencies/Injector.php index c31784ee9..ca384669e 100644 --- a/components/lib/Components/Dependencies/Injector.php +++ b/components/lib/Components/Dependencies/Injector.php @@ -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 index 000000000..a92697251 --- /dev/null +++ b/components/lib/Components/Module/Document.php @@ -0,0 +1,86 @@ + + * @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 + * @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 index 000000000..69d9c58f5 --- /dev/null +++ b/components/test/Components/Integration/Components/Module/DocumentTest.php @@ -0,0 +1,47 @@ + + * @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 + * @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 -- 2.11.0