dc01d417fa49327c538061acd636996bcf12eee0
Author: Mark Story
Date: 2009-06-14 20:37:08 -0400
diff --git a/models/api_package.php b/models/api_package.php
index 4b203b3..df31685 100644
--- a/models/api_package.php
+++ b/models/api_package.php
@@ -89,7 +89,8 @@ class ApiPackage extends ApiGeneratorAppModel {
$packages = array();
foreach (array('package', 'subpackage') as $key) {
if (isset($docBlock['tags'][$key])) {
- $packages = array_merge($packages, explode('.', $docBlock['tags'][$key]));
+ $newPackages = array_map('trim', explode('.', $docBlock['tags'][$key]));
+ $packages = array_merge($packages, $newPackages);
}
}
return array_values(array_unique($packages));
diff --git a/tests/cases/models/api_package.test.php b/tests/cases/models/api_package.test.php
index 226a4b6..e86a8be 100644
--- a/tests/cases/models/api_package.test.php
+++ b/tests/cases/models/api_package.test.php
@@ -118,6 +118,16 @@ class ApiPackageTestCase extends CakeTestCase {
$result = $this->ApiPackage->parsePackage($docBlock);
$expected = array('cake', 'model', 'behavior');
$this->assertEqual($result, $expected, 'Duplicates not removed %s');
+
+ $docBlock = array(
+ 'tags' => array(
+ 'package' => ' cake ',
+ 'subpackage' => ' cake.model.behavior'
+ )
+ );
+ $result = $this->ApiPackage->parsePackage($docBlock);
+ $expected = array('cake', 'model', 'behavior');
+ $this->assertEqual($result, $expected, 'Duplicates not removed %s');
}
/**
diff --git a/vendors/css/base.css b/vendors/css/base.css
index fe93a10..6f21f2e 100644
--- a/vendors/css/base.css
+++ b/vendors/css/base.css
@@ -492,6 +492,16 @@ Documentation Page Styles
}
/**
+* Package Index
+*******************/
+.package-tree .package-tree {
+ margin-left:15px;
+}
+.package-tree li {
+ margin:3px 0;
+}
+
+/**
* Code highlighting
****************************/
.code-container {
diff --git a/views/api_packages/index.ctp b/views/api_packages/index.ctp
index e69de29..b91e4e3 100644
--- a/views/api_packages/index.ctp
+++ b/views/api_packages/index.ctp
@@ -0,0 +1,2 @@
+<h1><?php __('Packages'); ?></h1>
+<?php echo $apiDoc->generatePackageTree($packageIndex); ?>
\ No newline at end of file
diff --git a/views/helpers/api_doc.php b/views/helpers/api_doc.php
index 6d62f57..6f9daf5 100644
--- a/views/helpers/api_doc.php
+++ b/views/helpers/api_doc.php
@@ -48,6 +48,11 @@ class ApiDocHelper extends AppHelper {
'action' => 'view_class',
'plugin' => 'api_generator',
),
+ 'package' => array(
+ 'controller' => 'api_packages',
+ 'action' => 'view',
+ 'plugin' => 'api_generator'
+ )
);
/**
* classList
@@ -64,6 +69,7 @@ class ApiDocHelper extends AppHelper {
$view = ClassRegistry::getObject('view');
$this->setBasePath($view->getVar('basePath'));
}
+
/**
* set the basePath
*
@@ -72,6 +78,7 @@ class ApiDocHelper extends AppHelper {
public function setBasePath($path) {
$this->_basePath = Folder::slashTerm(realpath($path));
}
+
/**
* inBasePath
*
@@ -82,6 +89,7 @@ class ApiDocHelper extends AppHelper {
function inBasePath($filename) {
return (strpos($filename, $this->_basePath) !== false);
}
+
/**
* Create a link to a filename if it is in the basePath
*
@@ -152,6 +160,7 @@ class ApiDocHelper extends AppHelper {
public function setClassIndex($classList) {
$this->_classList = $classList;
}
+
/**
* Check if a class is in the classIndex
*
@@ -161,6 +170,7 @@ class ApiDocHelper extends AppHelper {
public function inClassIndex($className) {
return in_array($className, $this->_classList);
}
+
/**
* Create a link to a class name if it exists in the classList
*
@@ -178,6 +188,7 @@ class ApiDocHelper extends AppHelper {
}
return $className;
}
+
/**
* Check the access string against the excluded method access.
*
@@ -194,6 +205,7 @@ class ApiDocHelper extends AppHelper {
}
return false;
}
+
/**
* Slugs a classname to match the format in the database.
*
@@ -203,6 +215,7 @@ class ApiDocHelper extends AppHelper {
public function slugClassName($className) {
return str_replace('_', '-', Inflector::underscore($className));
}
+
/**
* Create a nested inheritance tree from an array.
* Uses an array stack like a tree. So
@@ -227,4 +240,40 @@ class ApiDocHelper extends AppHelper {
}
return '<p class="inheritance-tree">' . $out . '</p>';
}
+
+/**
+ * Generate an HTML tree structure out of a package Index tree.
+ *
+ * @param array $packageTree Array of package tree from find(threaded)
+ * @return string Formatted HTML
+ **/
+ public function generatePackageTree($packageTree) {
+ $out = '<ul class="package-tree">' . "\n";
+ foreach ($packageTree as $branch) {
+ $children = null;
+ $link = $this->packageLink($branch['ApiPackage']['name']);
+ if (!empty($branch['children'])) {
+ $children = $this->generatePackageTree($branch['children']);
+ }
+ $out .= sprintf("\t<li>%s %s</li>\n", $link, $children);
+ }
+ $out .= "</ul>\n";
+ return $out;
+ }
+
+/**
+ * Create a link to a package
+ *
+ * @param string $package The package name you want to link to.
+ * @param array $url A url array to override defaults
+ * @param array $attributes Additional attributes for an html link if generated.
+ * @return string Html link
+ **/
+ public function packageLink($apiPackage, $url = array(), $attributes = array()) {
+ $url = array_merge($this->_defaultUrl['package'], $url);
+ $slug = $this->slugClassName($apiPackage);
+ $url[] = $slug;
+ return $this->Html->link($apiPackage, $url, $attributes);
+ }
+
}
\ No newline at end of file
