62d53ee3cd2991809e86eed0ded3562bab77b89b

Author: Mark Story

Date: 2009-01-04 13:04:37 -0500

Adding some functions and moving things around. Lots of flux still

diff --git a/README b/README index b99e2d5..e94b9c1 100644 --- a/README +++ b/README @@ -4,4 +4,18 @@ The Api Generator gives you an easy to use file browser, that generators API doc Requirements: -PHP5 - Requires PHP5.2. If you are on PHP4 too bad, time to upgrade anyways. \ No newline at end of file +PHP5 - Requires PHP5.2. If you are on PHP4 too bad, time to upgrade anyways. + + + +Goals of project: + +* Provide a file and class browser for explorer for exploring a project and viewing the classes it contains. +* Provide easy to read and well designed api docs. +* Allow configuration of api generation + * what path is used. + * what directories / files are not included. + * ability to disable either file or class browser. + * ability to omit certain classes from the docs + * allow / remove protected / private members from being displayed. + diff --git a/api_generator_app_controller.php b/api_generator_app_controller.php index ea92856..93180af 100644 --- a/api_generator_app_controller.php +++ b/api_generator_app_controller.php @@ -35,6 +35,7 @@ class ApiGeneratorAppController extends AppController { $path = Configure::read('ApiGenerator.filePath'); if (empty($path)) { $path = APP; + Configure::write('ApiGenerator.filePath', $path); } $this->path = $path; } diff --git a/api_generator_app_model.php b/api_generator_app_model.php new file mode 100644 index 0000000..300063f --- /dev/null +++ b/api_generator_app_model.php @@ -0,0 +1,45 @@ +<?php +/* SVN FILE: $Id$ */ +/** + * ApiGenerator App Model class + * + * Base model class for models in ApiGenerator + * + * PHP versions 4 and 5 + * + * CakePHP : Rapid Development Framework <http://www.cakephp.org/> + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs. + * @since CakePHP v 1.2.0.4487 + * @version + * @modifiedby + * @lastmodified + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +class ApiGeneratorAppModel extends AppModel { +/** + * Inflect a slashed path to url safe path. Trims ApiGenerator.filePath off as well. + * + * @param string $slashPath The slashed path to slug. + * @return string + **/ + public function slugPath($slashPath, $stripBase = true) { + if ($stripBase) { + $basePath = Configure::read('ApiGenerator.filePath'); + $slashPath = trim($slashPath, $basePath); + } + $slugPath = strtolower(Inflector::slug($slashPath, '-')); + return $slugPath; + } +} +?> \ No newline at end of file diff --git a/controllers/api_pages_controller.php b/controllers/api_pages_controller.php index f532761..21c23d0 100644 --- a/controllers/api_pages_controller.php +++ b/controllers/api_pages_controller.php @@ -51,8 +51,23 @@ class ApiPagesController extends ApiGeneratorAppController { * @return void **/ public function browse_files() { - $files = $this->Documentor->getFileList($this->path); + $this->ApiFile = ClassRegistry::init('ApiGenerator.ApiFile'); + $path = implode(DS, $this->params['pass']); + $files = $this->ApiFile->read($this->path . $path); + + //$files = $this->Documentor->getFileList($this->path); + } +/** + * all_files + * + * Gets a recursive list of all files that match documentor criteria. + * + * @access public + * @return void + */ + public function all_files() { + //$files = $this->Documentor->getFileList($this->path); } /** * Browse the classes in the application / API files. diff --git a/controllers/components/documentor.php b/controllers/components/documentor.php index 9ad0c8a..f097f63 100644 --- a/controllers/components/documentor.php +++ b/controllers/components/documentor.php @@ -110,16 +110,29 @@ class DocumentorComponent extends Object { $this->Folder = new Folder($basePath); $filePattern = $this->fileRegExp . '\.' . implode('|', $this->extensionsToScan); $found = $this->Folder->findRecursive($filePattern); - $count = count($found); + $this->_filterFiles($found); + + return $found; + } +/** + * _filterFiles + * + * Filter a file list and remove ignoreFolders + * + * @param array $files List of files to filter and ignore. (reference) + * @return void + **/ + protected function _filterFiles(&$fileList) { + $count = count($fileList); foreach ($this->ignoreFolders as $remove) { $blackListed = DS . $remove . DS; for ($i = 0; $i < $count; $i++) { - if (isset($found[$i]) && strpos($found[$i], $blackListed) !== false) { - unset($found[$i]); + if (isset($fileList[$i]) && strpos($fileList[$i], $blackListed) !== false) { + unset($fileList[$i]); } } } - return $found; + $fileList = array_values($fileList); } } diff --git a/models/api_file.php b/models/api_file.php new file mode 100644 index 0000000..c5effb4 --- /dev/null +++ b/models/api_file.php @@ -0,0 +1,54 @@ +<?php +/* SVN FILE: $Id$ */ +/** + * Api File Model + * + * For interacting with the Filesystem specified by ApiGenerator.filePath + * + * + * PHP versions 4 and 5 + * + * CakePHP : Rapid Development Framework <http://www.cakephp.org/> + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs. + * @since CakePHP v 1.2.0.4487 + * @version + * @modifiedby + * @lastmodified + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +class ApiFile extends Object { +/** + * Name + * + * @var string + */ + public $name = 'ApiFile'; +/** + * useTable + * + * @var string + **/ + public $useTable = false; + +/** + * Read a path and return files and folders not in the excluded Folder list + * + * @param string $path The path you wish to read. + * @return array + **/ + public function read($path) { + debug($path); + } +} +?> \ No newline at end of file diff --git a/tests/cases/components/documentor.test.php b/tests/cases/components/documentor.test.php index 7887bc1..a8d5c02 100644 --- a/tests/cases/components/documentor.test.php +++ b/tests/cases/components/documentor.test.php @@ -96,6 +96,15 @@ class DocumentorTestCase extends CakeTestCase { $this->assertFalse(in_array($core, $result)); $this->assertFalse(in_array($vendorJs, $result)); } + + function testListObjects() { + $this->Documentor->ignoreFolders = array('config', 'webroot'); + $result = $this->Documentor->listObjects('file', array('path' => APP)); + $core = CONFIGS . 'core.php'; + $vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php'; + $this->assertFalse(in_array($core, $result)); + $this->assertFalse(in_array($vendorJs, $result)); + } /** * end a test case * diff --git a/tests/cases/models/api_generator_app_model.test.php b/tests/cases/models/api_generator_app_model.test.php new file mode 100644 index 0000000..bdb70a3 --- /dev/null +++ b/tests/cases/models/api_generator_app_model.test.php @@ -0,0 +1,81 @@ +<?php +/* SVN FILE: $Id$ */ +/** + * + * + * + * + * PHP versions 4 and 5 + * + * CakePHP : Rapid Development Framework <http://www.cakephp.org/> + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs. + * @since CakePHP v 1.2.0.4487 + * @version + * @modifiedby + * @lastmodified + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +App::import('Model', 'ApiGenerator.AppModel'); + +class ApiGeneratorAppTestModel extends ApiGeneratorAppModel { + public $name = 'ApiGeneratorAppTestModel'; + public $useTable = false; + +} + +class ApiGeneratorAppModelTestCase extends CakeTestCase { +/** + * startTest + * + * @return void + **/ + function startTest() { + $this->Model = ClassRegistry::init('ApiGeneratorAppTestModel'); + } +/** + * test slugPath + * + * @return void + **/ + function testSlugPath() { + Configure::write('ApiGenerator.filePath', '/this/is/'); + $result = $this->Model->slugPath('/this/is/a/path/to_my/file.php'); + $expected = 'a-path-to_my-file-php'; + $this->assertEqual($result, $expected); + + Configure::write('ApiGenerator.filePath', '/this/is/'); + $result = $this->Model->slugPath('/this/is/a/path/to_my/f i le.php'); + $expected = 'a-path-to_my-f-i-le-php'; + $this->assertEqual($result, $expected); + + Configure::write('ApiGenerator.filePath', 'C:\www'); + $result = $this->Model->slugPath('C:\www\my Path\is Very Windows\file.php'); + $expected = 'my-path-is-very-windows-file-php'; + $this->assertEqual($result, $expected); + + Configure::write('ApiGenerator.filePath', 'C:\www'); + $result = $this->Model->slugPath('C:\www\my Path\is Very Windows\file.php', false); + $expected = 'c-www-my-path-is-very-windows-file-php'; + $this->assertEqual($result, $expected); + } +/** + * endTest + * + * @return void + **/ + function endTest() { + unset($this->Model); + } +} +?> \ No newline at end of file