Commit: 5754e00c018de0f6998382ef10052e201f1f5926

Author: David Persson | Date: 2010-08-10 13:51:32 +0200
Renaming BrowserController to ApiBrowserController.
diff --git a/config/routes.php b/config/routes.php index 83443fc..b58f167 100644 --- a/config/routes.php +++ b/config/routes.php @@ -10,9 +10,9 @@ if (isset($config['showApi']) && $config['showApi'] === false) { return; } -Router::connect('/docs', array('library' => 'li3_docs', 'controller' => 'browser')); +Router::connect('/docs', array('library' => 'li3_docs', 'controller' => 'api_browser')); Router::connect('/docs/{:lib}/{:args}', array( - 'library' => 'li3_docs', 'controller' => 'browser', 'action' => 'view' + 'library' => 'li3_docs', 'controller' => 'api_browser', 'action' => 'view' )); // Router::connect(new Locale(array( // 'template' => '/docs', diff --git a/controllers/ApiBrowserController.php b/controllers/ApiBrowserController.php new file mode 100644 index 0000000..7898583 --- /dev/null +++ b/controllers/ApiBrowserController.php @@ -0,0 +1,144 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace li3_docs\controllers; + +use Exception; +use DirectoryIterator; +use lithium\core\Libraries; +use lithium\analysis\Inspector; + +/** + * This is the Lithium API browser controller. This class introspects your application's libraries, + * plugins and classes to generate on-the-fly API documentation. + */ +class ApiBrowserController extends \lithium\action\Controller { + + /** + * The `Extractor` class dependency, which can be replaced with a proxy file to read from + * a cache or database. + * + * @var array + */ + protected $_classes = array( + 'media' => 'lithium\net\http\Media', + 'response' => 'lithium\action\Response', + 'extractor' => 'li3_docs\extensions\docs\Extractor' + ); + + /** + * The name of the file used to document (describe) namespaces. By default, the document is read + * from the directory being examined, and the contents of it represent the "docblock" for the + * corresponding namespace. + * + * @var string + */ + public $docFile = 'readme.wiki'; + + /** + * This action introspects all libraries and plugins that exist in your app (even if they are + * not loaded), including the app itself and the Lithium core. + * + * @return array + */ + public function index() { + $libraries = Libraries::get(); + $config = Libraries::get('li3_docs'); + + if (isset($config['index'])) { + $libraries = array_combine( + $config['index'], + array_map(function($lib) { return Libraries::get($lib); }, $config['index']) + ); + } + return compact('libraries'); + } + + /** + * This action renders the detail page for all API elements, including namespaces, classes, + * properties and methods. The action determines what type of entity is being displayed, and + * gathers all available data on it. Any wiki text embedded in the data is then post-processed + * and prepped for display. + * + * @return array Returns an array with the following keys: + * - `'name'`: A string containing the full name of the entity being displayed + * - `'library'`: An array with the details of the current class library being + * browsed, in which the current entity is contained. + * - `'object'`: A multi-level array containing all data extracted about the + * current entity. + */ + public function view() { + $extractor = $this->_classes['extractor']; + $config = Libraries::get('li3_docs'); + + if (!$library = $extractor::library($this->request->lib)) { + return $this->render('../errors/not_found'); + } + if (isset($config['index']) && !in_array($this->request->lib, $config['index'])) { + return $this->render('../errors/not_found'); + } + $name = $library['prefix'] . join('\\', func_get_args()); + $options = array('namespaceDoc' => $this->docFile); + + $object = $extractor::get($this->request->lib, $name, $options); + $crumbs = $this->_crumbs($object); + return compact('name', 'library', 'object', 'crumbs'); + } + + protected function _crumbs($object) { + $path = array_filter(array_merge( + array($object['name']), explode('\\', $object['identifier']) + )); + $crumbs[] = array( + 'title' => $object['type'], + 'url' => null, + 'class' => 'type ' . $object['type'] + ); + $url = ''; + + foreach (array_slice($path, 0, -1) as $part) { + $url .= '/' . $part; + $crumbs[] = array('title' => $part, 'url' => 'docs' . $url, 'class' => null); + } + $ident = end($path); + + if (strpos($ident, '::') !== false) { + list($class, $ident) = explode('::', $ident, 2); + $crumbs[] = array('title' => $class, 'url' => "docs{$url}/{$class}", 'class' => null); + $isMethod = true; + } else { + $isMethod = false; + } + $crumbs[] = array('title' => $ident, 'url' => null, 'class' => $isMethod ? 'ident' : null); + return $crumbs; + } + + protected function _oldProcess($object) { + if (isset($object['info']['tags']['var'])) { + $object['type'] = $object['info']['tags']['var']; + } + $object['info'] += array('description' => ''); + + if ($object['info']['description']) { + $object['info']['description'] = $this->_embed($object['info']['description']); + } + + if (isset($object['info']['text'])) { + $object['info']['text'] = $this->_embed($object['info']['text']); + } + + if (isset($object['info']['tags']['return'])) { + list($type, $text) = explode(' ', $object['info']['tags']['return'], 2) + array('', ''); + $object['info']['return'] = compact('type', 'text'); + $object['info']['return']['text'] = $this->_embed($object['info']['return']['text']); + } + return $object; + } +} + +?> \ No newline at end of file diff --git a/controllers/BrowserController.php b/controllers/BrowserController.php deleted file mode 100644 index b7560bf..0000000 --- a/controllers/BrowserController.php +++ /dev/null @@ -1,144 +0,0 @@ -<?php -/** - * Lithium: the most rad php framework - * - * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) - * @license http://opensource.org/licenses/bsd-license.php The BSD License - */ - -namespace li3_docs\controllers; - -use Exception; -use DirectoryIterator; -use lithium\core\Libraries; -use lithium\analysis\Inspector; - -/** - * This is the Lithium API browser controller. This class introspects your application's libraries, - * plugins and classes to generate on-the-fly API documentation. - */ -class BrowserController extends \lithium\action\Controller { - - /** - * The `Extractor` class dependency, which can be replaced with a proxy file to read from - * a cache or database. - * - * @var array - */ - protected $_classes = array( - 'media' => 'lithium\net\http\Media', - 'response' => 'lithium\action\Response', - 'extractor' => 'li3_docs\extensions\docs\Extractor' - ); - - /** - * The name of the file used to document (describe) namespaces. By default, the document is read - * from the directory being examined, and the contents of it represent the "docblock" for the - * corresponding namespace. - * - * @var string - */ - public $docFile = 'readme.wiki'; - - /** - * This action introspects all libraries and plugins that exist in your app (even if they are - * not loaded), including the app itself and the Lithium core. - * - * @return array - */ - public function index() { - $libraries = Libraries::get(); - $config = Libraries::get('li3_docs'); - - if (isset($config['index'])) { - $libraries = array_combine( - $config['index'], - array_map(function($lib) { return Libraries::get($lib); }, $config['index']) - ); - } - return compact('libraries'); - } - - /** - * This action renders the detail page for all API elements, including namespaces, classes, - * properties and methods. The action determines what type of entity is being displayed, and - * gathers all available data on it. Any wiki text embedded in the data is then post-processed - * and prepped for display. - * - * @return array Returns an array with the following keys: - * - `'name'`: A string containing the full name of the entity being displayed - * - `'library'`: An array with the details of the current class library being - * browsed, in which the current entity is contained. - * - `'object'`: A multi-level array containing all data extracted about the - * current entity. - */ - public function view() { - $extractor = $this->_classes['extractor']; - $config = Libraries::get('li3_docs'); - - if (!$library = $extractor::library($this->request->lib)) { - return $this->render('../errors/not_found'); - } - if (isset($config['index']) && !in_array($this->request->lib, $config['index'])) { - return $this->render('../errors/not_found'); - } - $name = $library['prefix'] . join('\\', func_get_args()); - $options = array('namespaceDoc' => $this->docFile); - - $object = $extractor::get($this->request->lib, $name, $options); - $crumbs = $this->_crumbs($object); - return compact('name', 'library', 'object', 'crumbs'); - } - - protected function _crumbs($object) { - $path = array_filter(array_merge( - array($object['name']), explode('\\', $object['identifier']) - )); - $crumbs[] = array( - 'title' => $object['type'], - 'url' => null, - 'class' => 'type ' . $object['type'] - ); - $url = ''; - - foreach (array_slice($path, 0, -1) as $part) { - $url .= '/' . $part; - $crumbs[] = array('title' => $part, 'url' => 'docs' . $url, 'class' => null); - } - $ident = end($path); - - if (strpos($ident, '::') !== false) { - list($class, $ident) = explode('::', $ident, 2); - $crumbs[] = array('title' => $class, 'url' => "docs{$url}/{$class}", 'class' => null); - $isMethod = true; - } else { - $isMethod = false; - } - $crumbs[] = array('title' => $ident, 'url' => null, 'class' => $isMethod ? 'ident' : null); - return $crumbs; - } - - protected function _oldProcess($object) { - if (isset($object['info']['tags']['var'])) { - $object['type'] = $object['info']['tags']['var']; - } - $object['info'] += array('description' => ''); - - if ($object['info']['description']) { - $object['info']['description'] = $this->_embed($object['info']['description']); - } - - if (isset($object['info']['text'])) { - $object['info']['text'] = $this->_embed($object['info']['text']); - } - - if (isset($object['info']['tags']['return'])) { - list($type, $text) = explode(' ', $object['info']['tags']['return'], 2) + array('', ''); - $object['info']['return'] = compact('type', 'text'); - $object['info']['return']['text'] = $this->_embed($object['info']['return']['text']); - } - return $object; - } -} - -?> \ No newline at end of file diff --git a/extensions/helper/Docs.php b/extensions/helper/Docs.php index 500a050..cc709c4 100644 --- a/extensions/helper/Docs.php +++ b/extensions/helper/Docs.php @@ -18,7 +18,7 @@ class Docs extends \lithium\template\Helper { $parts = explode('\\', $class); $lib = array_shift($parts); $args = $parts; - return array('Browser::view', 'library' => 'li3_docs') + compact('lib', 'args'); + return array('ApiBrowser::view', 'library' => 'li3_docs') + compact('lib', 'args'); } } diff --git a/views/api_browser/index.html.php b/views/api_browser/index.html.php new file mode 100644 index 0000000..916d1b5 --- /dev/null +++ b/views/api_browser/index.html.php @@ -0,0 +1,10 @@ +<h2><?=$this->title($t('Libraries', array('scope' => 'li3_docs'))); ?></h2> + +<ul class="libraries"> + <?php foreach ($libraries as $lib => $config) { ?> + <?php $display = ucwords(str_replace('_', ' ', $lib)); ?> + <li><?=$this->html->link($display, compact('lib') + array( + 'library' => 'li3_docs', 'controller' => 'api_browser', 'action' => 'view' + )); ?></li> + <?php } ?> +</ul> \ No newline at end of file diff --git a/views/api_browser/view.html.php b/views/api_browser/view.html.php new file mode 100644 index 0000000..e7a2cf4 --- /dev/null +++ b/views/api_browser/view.html.php @@ -0,0 +1,49 @@ +<?php + +$scope = strtok($object['identifier'], '\\') . '_docs'; +$namespace = str_replace('\\', '/', $name); +$this->title($namespace); + +?> + +<?=$this->view()->render( + array('element' => $object['type']), + compact('namespace', 'object', 'scope'), + array('library' => 'li3_docs') +); ?> + +<?php // Related items ?> +<?=$this->view()->render( + array('element' => 'related'), compact('object', 'scope'), array('library' => 'li3_docs') +); ?> + +<?=$this->view()->render( + array('element' => 'links'), + compact('namespace', 'object', 'scope'), + array('library' => 'li3_docs') +); ?> + +<?php // Object subclasses ?> +<?php if ($object['subClasses']) { ?> + <h4><?=$t('Subclasses', array('scope' => 'li3_docs')); ?></h4> + <ul class="subclasses"> + <?php foreach ($object['subClasses'] as $class) { ?> + <?php $url = $this->docs->identifierUrl($class); ?> + <li><?php echo $this->html->link($class, $url); ?></li> + <?php } ?> + </ul> +<?php } ?> + +<?php // Method source ?> +<?php if (isset($object['source'])) { ?> + <div class="source-display"> + <div class="source-wrapper"> + <pre class="source-code"> + <code class="php"><?=$object['source']; ?></code> + </pre> + </div> + <button class="source-toggle"> + <?=$t('Show source', array('scope' => 'li3_docs')); ?> + </button> + </div> +<?php } ?> \ No newline at end of file diff --git a/views/browser/index.html.php b/views/browser/index.html.php deleted file mode 100644 index 1d46ce7..0000000 --- a/views/browser/index.html.php +++ /dev/null @@ -1,10 +0,0 @@ -<h2><?=$this->title($t('Libraries', array('scope' => 'li3_docs'))); ?></h2> - -<ul class="libraries"> - <?php foreach ($libraries as $lib => $config) { ?> - <?php $display = ucwords(str_replace('_', ' ', $lib)); ?> - <li><?=$this->html->link($display, compact('lib') + array( - 'library' => 'li3_docs', 'controller' => 'browser', 'action' => 'view' - )); ?></li> - <?php } ?> -</ul> diff --git a/views/browser/view.html.php b/views/browser/view.html.php deleted file mode 100644 index e7a2cf4..0000000 --- a/views/browser/view.html.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -$scope = strtok($object['identifier'], '\\') . '_docs'; -$namespace = str_replace('\\', '/', $name); -$this->title($namespace); - -?> - -<?=$this->view()->render( - array('element' => $object['type']), - compact('namespace', 'object', 'scope'), - array('library' => 'li3_docs') -); ?> - -<?php // Related items ?> -<?=$this->view()->render( - array('element' => 'related'), compact('object', 'scope'), array('library' => 'li3_docs') -); ?> - -<?=$this->view()->render( - array('element' => 'links'), - compact('namespace', 'object', 'scope'), - array('library' => 'li3_docs') -); ?> - -<?php // Object subclasses ?> -<?php if ($object['subClasses']) { ?> - <h4><?=$t('Subclasses', array('scope' => 'li3_docs')); ?></h4> - <ul class="subclasses"> - <?php foreach ($object['subClasses'] as $class) { ?> - <?php $url = $this->docs->identifierUrl($class); ?> - <li><?php echo $this->html->link($class, $url); ?></li> - <?php } ?> - </ul> -<?php } ?> - -<?php // Method source ?> -<?php if (isset($object['source'])) { ?> - <div class="source-display"> - <div class="source-wrapper"> - <pre class="source-code"> - <code class="php"><?=$object['source']; ?></code> - </pre> - </div> - <button class="source-toggle"> - <?=$t('Show source', array('scope' => 'li3_docs')); ?> - </button> - </div> -<?php } ?> \ No newline at end of file diff --git a/views/layouts/default.html.php b/views/layouts/default.html.php index e7cc3e3..9c7968c 100644 --- a/views/layouts/default.html.php +++ b/views/layouts/default.html.php @@ -28,7 +28,7 @@ use lithium\core\Environment; <div id="container"> <div id="header"> <h1><?=$this->html->link($t('Lithium API', array('scope' => 'li3_docs')), array( - 'library' => 'li3_docs', 'controller' => 'browser', 'action' => 'index' + 'library' => 'li3_docs', 'controller' => 'api_browser', 'action' => 'index' )); ?></h1> <ul class="crumbs"> <?php foreach (isset($crumbs) ? $crumbs : array() as $crumb): ?>