f8f31dc4a4af2f47f38261e3371aaafae3fc1e4d
Author: Mark Story
Date: 2009-02-04 23:53:21 -0500
diff --git a/controllers/api_generator_controller.php b/controllers/api_generator_controller.php
index c3edb4b..b8f9cdb 100644
--- a/controllers/api_generator_controller.php
+++ b/controllers/api_generator_controller.php
@@ -120,7 +120,7 @@ class ApiGeneratorController extends ApiGeneratorAppController {
} catch(Exception $e) {
$this->_notFound($e->getMessage());
}
- $classIndex = $this->ApiClass->getClassIndex();
+ $classIndex = $this->ApiClass->getClassIndex(true);
list($dirs, $files) = $this->ApiFile->read($this->path . $previousPath);
if (!empty($docs)) {
diff --git a/models/api_class.php b/models/api_class.php
index 27d7848..4e5ffbf 100644
--- a/models/api_class.php
+++ b/models/api_class.php
@@ -52,7 +52,19 @@ class ApiClass extends ApiGeneratorAppModel {
)
),
);
-
+/**
+ * Flag bitmask for Pseudo classes (files with global functions)
+ * get a pseudo class assigned to them
+ *
+ * @var int
+ **/
+ const PSEUDO_CLASS = 1;
+/**
+ * Concrete class bitmask;
+ *
+ * @var string
+ **/
+ const CONCRETE_CLASS = 0;
/**
* Clears (truncates) the class index.
*
@@ -83,6 +95,33 @@ class ApiClass extends ApiGeneratorAppModel {
return $this->save();
}
/**
+ * Save a set of global functions to the ApiClass index.
+ * Will make one record with a 'class name' derived from the filename.
+ *
+ * @param array $functions Array of FunctionDocumentor objects to index.
+ * @param string $filename Name of file these things are found in.
+ * @return boolean
+ **/
+ public function savePseudoClassDocs($functions, $filename) {
+ $methodList = array();
+ $name = basename($filename);
+ $slug = str_replace('_', '-', Inflector::underscore($name));
+ foreach ($functions as $func) {
+ if ($func instanceof FunctionDocumentor) {
+ $methodList[] = $func->getName();
+ }
+ }
+ $data = array(
+ 'name' => $name,
+ 'slug' => $slug,
+ 'file_name' => $filename,
+ 'method_index' => implode($methodList, ' '),
+ 'flags' => ApiClass::PSEUDO_CLASS,
+ );
+ $this->set($data);
+ return $this->save();
+ }
+/**
* search method
*
* Find matching records for the given term or terms
@@ -113,11 +152,20 @@ class ApiClass extends ApiGeneratorAppModel {
/**
* Get the class index listing
- *
+ *
+ * @param boolean $includePseudoClass Whether you want to include 'pseudo' classes (no actual class)
* @return array
**/
- public function getClassIndex() {
- return $this->find('list', array('fields' => array('slug', 'name'), 'order' => 'ApiClass.name ASC'));
+ public function getClassIndex($includePseudoClass = false) {
+ $conditions = array();
+ if (!$includePseudoClass) {
+ $conditions['ApiClass.flags'] = ApiClass::CONCRETE_CLASS;
+ }
+ return $this->find('list', array(
+ 'fields' => array('slug', 'name'),
+ 'order' => 'ApiClass.name ASC',
+ 'conditions' => $conditions
+ ));
}
/**
* Generate a search index of methods or properties for the ClassDocumentor Object
@@ -156,7 +204,7 @@ class ApiClass extends ApiGeneratorAppModel {
$relevance = 0;
$this->_unsetUnmatching($obj, $terms, 'properties');
$this->_unsetUnmatching($obj, $terms, 'methods');
- foreach($terms as $term) {
+ foreach ($terms as $term) {
if (low($name) === $term) {
$relevance += 6;
} elseif (strpos(low($name), $term) === 0) {
@@ -166,7 +214,7 @@ class ApiClass extends ApiGeneratorAppModel {
if ($obj->methods) {
foreach ($obj->methods as $method) {
$_name = $method['name'];
- foreach($terms as $term) {
+ foreach ($terms as $term) {
if (low($_name) === $term) {
$relevance += 4;
} elseif (strpos(low($_name), $term) === 0) {
diff --git a/vendors/shells/api_index.php b/vendors/shells/api_index.php
index 66a3bd4..0cef498 100644
--- a/vendors/shells/api_index.php
+++ b/vendors/shells/api_index.php
@@ -143,6 +143,12 @@ class ApiIndexShell extends Shell {
$this->out('Added docs for ' . $classDocs->name . ' to index');
}
}
+ if (!empty($docsInFile['function'])) {
+ $this->ApiClass->create();
+ if ($this->ApiClass->savePseudoClassDocs($docsInFile['function'], $file)) {
+ $this->out('Added docs for global functions in ' . $file);
+ }
+ }
}
}
diff --git a/views/elements/function_summary.ctp b/views/elements/function_summary.ctp
index f759078..edec9b7 100644
--- a/views/elements/function_summary.ctp
+++ b/views/elements/function_summary.ctp
@@ -36,7 +36,19 @@
<?php endif; ?>
<dt><?php __('Function defined in file:'); ?></dt>
- <dd><?php echo $apiDoc->fileLink($doc->info['declaredInFile']); ?></dd>
+ <dd><?php
+ echo $apiDoc->fileLink($doc->info['declaredInFile']);
+ $pseudoClass = basename($doc->info['declaredInFile']);
+ if ($apiDoc->inClassIndex($pseudoClass)):
+ __(' on line ');
+ echo $html->link($doc->info['startLine'], array(
+ 'controller' => 'api_generator',
+ 'action' => 'view_source',
+ $pseudoClass,
+ '#line-'. $doc->info['startLine']
+ ));
+ endif;
+ ?> </dd>
<dt>
<?php foreach ($doc->info['comment']['tags'] as $name => $value): ?>
