Commit: 712be93e13399e7242a12bc91c2d402565cc483a

Author: Nate Abele | Date: 2009-10-12 17:21:29 -0400
Initial project commit. Contains basic, unstyled class info listings.
diff --git a/.gitignore b/.gitignore index e69de29..e43b0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000..0049163 --- /dev/null +++ b/config/routes.php @@ -0,0 +1,10 @@ +<?php + +use \cake\http\Router; + +Router::connect('/docs', array('plugin' => 'lithium_docs', 'controller' => 'browser')); +Router::connect('/docs/{:library}/{:args}', array( + 'plugin' => 'lithium_docs', 'controller' => 'browser', 'action' => 'view' +)); + +?> \ No newline at end of file diff --git a/controllers/BrowserController.php b/controllers/BrowserController.php new file mode 100644 index 0000000..e241125 --- /dev/null +++ b/controllers/BrowserController.php @@ -0,0 +1,76 @@ +<?php + +namespace lithium_docs\controllers; + +use \DirectoryIterator; +use \cake\core\Libraries; +use \cake\util\reflection\Inspector; + +class BrowserController extends \cake\action\Controller { + + public function index() { + $pluginsDir = new DirectoryIterator(CAKE_APP_PATH . '/libraries/plugins'); + $plugins = array(); + + foreach ($pluginsDir as $plugin) { + if ($plugin->isDir() && !$plugin->isDot()) { + $plugins[$plugin->getPathName()] = $plugin->getFileName(); + } + } + $libraries = Libraries::get(); + $this->set(compact('plugins', 'libraries')); + } + + public function view() { + $lib = $this->request->params['library']; + $library = Libraries::get($lib); + $name = $library['prefix'] . join('\\', func_get_args()); + + $object = array( + 'identifier' => $name, + 'type' => null, + 'info' => null, + 'classes' => null, + 'methods' => null, + 'properties' => null, + 'parent' => null, + 'subClasses' => null, + 'children' => null + ); + $object['type'] = Inspector::type($name); + + switch ($object['type']) { + case 'namespace': + $object['children'] = Libraries::find($lib, array( + 'namespaces' => true, + 'path' => '/' . join('/', (array)$this->request->params['args']) + )); + break; + case 'class': + $object['parent'] = get_parent_class($name); + $object['methods'] = Inspector::methods($name, null, array('public' => false)); + + if ($object['parent']) { + $object['properties'] = array_diff_key( + get_class_vars($name), + get_class_vars($object['parent']) + ); + } + $classes = Libraries::find($lib, array('recursive' => true)); + + $object['subClasses'] = array_filter($classes, function($class) use ($name) { + if (preg_match('/\\\(libraries|plugins)\\\/', $class)) { + return false; + } + return get_parent_class($class) == $name; + }); + sort($object['subClasses']); + break; + } + $object['info'] = Inspector::info($object['identifier']); + + return compact('name', 'library', 'object'); + } +} + +?> \ No newline at end of file diff --git a/views/browser/index.html.php b/views/browser/index.html.php new file mode 100644 index 0000000..ac8457a --- /dev/null +++ b/views/browser/index.html.php @@ -0,0 +1,6 @@ +<ul> + <?php foreach ($libraries as $name => $config) { ?> + <?php $display = ucwords(str_replace('_', ' ', $name)); ?> + <li><a href="<?php echo $name; ?>"><?php echo $display; ?></a></li> + <?php } ?> +</ul> diff --git a/views/browser/view.html.php b/views/browser/view.html.php new file mode 100644 index 0000000..0f0f451 --- /dev/null +++ b/views/browser/view.html.php @@ -0,0 +1,83 @@ +<span class="type"><?=$object['type']; ?></span> + +<h3> +<?php + $path = array_filter(array_merge( + array($library['name']), explode('\\', $object['identifier']) + )); + $url = ''; + + foreach (array_slice($path, 0, -1) as $part) { + $url .= '/' . $part; + echo $this->html->link($part, 'docs' . $url) . ' \ '; + } + echo end($path); + $curPath = str_replace('\\', '/', $name); +?> +</h3> + +<?php if ($object['children']) { ?> + <h4>Package contents</h4> + <ul class="children"> + <?php foreach ($object['children'] as $class) { ?> + <?php $className = end(explode('\\', $class)); ?> + <li><?=$this->html->link($className, 'docs/' . $class); ?></li> + <?php } ?> + </ul> +<?php } ?> + +<?php if ($object['parent']) { ?> + <?php $parent = $object['parent']; ?> + <h4>Parent class</h4> + <span class="parent"> + <?=$this->html->link($parent, 'docs/' . str_replace('\\', '/', $parent)); ?> + </span> +<?php } ?> + +<?php if ($object['subClasses']) { ?> + <h4>Subclasses</h4> + <ul class="subclasses"> + <?php foreach ($object['subClasses'] as $class) { ?> + <?php $url = 'docs/' . str_replace('\\', '/', $class); ?> + <li><?=$this->html->link($class, $url); ?></li> + <?php } ?> + </ul> +<?php } ?> + +<?php if ($object['info']['description']) { ?> + <h4>Description</h4> + <p class="description wiki-text"><?=$object['info']['description']; ?></p> + + <?php if (!empty($object['info']['text'])) { ?> + <p class="text wiki-text"><?=$object['info']['text']; ?></p> + <?php } ?> +<?php } ?> + +<?php if ($object['methods']) { ?> + <h4>Methods</h4> + <ul class="methods"> + <?php foreach ($object['methods'] as $method) { ?> + <li><?=$this->html->link($method->name, "docs/{$curPath}::{$method->name}()"); ?></li> + <?php } ?> + </ul> +<?php } ?> + +<?php if (isset($object['info']['tags']['params'])) { ?> + <h4>Parameters</h4> + <ul class="parameters"> + <?php foreach ($object['info']['tags']['params'] as $name => $data) { ?> + <li> + <span class="type"><?=$data['type']; ?></span> + <?=$name; ?> + <span class="description wiki-text"><?=$data['text']; ?></span> + </li> + <?php } ?> + </ul> +<?php } ?> + +<?php if (isset($object['info']['tags']['return'])) { ?> + <h4>Returns</h4> + <span class="return wiki-text"> + <?=$object['info']['tags']['return']; ?> + </span> +<?php } ?> diff --git a/views/layouts/default.html.php b/views/layouts/default.html.php new file mode 100644 index 0000000..b5cb7d8 --- /dev/null +++ b/views/layouts/default.html.php @@ -0,0 +1,21 @@ +<html> +<head> + <title><?=$this->title(); ?></title> + <?=$this->html->script('http://thechaw.com/js/jquery-1.3.1.min.js'); ?> + <?=$this->html->script('http://thechaw.com/js/gshowdown.min.js'); ?> + <?=$this->scripts(); ?> + <script type="text/javascript"> + var converter = new Showdown.converter("/"); + + $(document).ready(function(){ + $(".wiki-text").each(function () { + $(this).html(converter.makeHtml(jQuery.trim($(this).text()))); + }); + }); + </script> +</head> +<body> + <h1>Lithium API Browser</h1> + <?=@$this->content(); ?> +</body> +</html>