ff112b50530801c924eae47314478315d0b44897

Author: Mark Story

Date: 2009-05-31 15:18:25 -0400

Modifying trimFileName to scan through basePath looking for possible matches. Fixes full path showing on view_source. Test case added.

diff --git a/tests/cases/helpers/api_doc.test.php b/tests/cases/helpers/api_doc.test.php index 4517229..bfa2593 100644 --- a/tests/cases/helpers/api_doc.test.php +++ b/tests/cases/helpers/api_doc.test.php @@ -54,6 +54,10 @@ class ApiDocHelperTestCase extends CakeTestCase { function testTrimFileName() { $result = $this->ApiDoc->trimFileName($this->_pluginPath . '/tests/cases/helpers/api_doc.test.php'); $this->assertEqual($result, '/tests/cases/helpers/api_doc.test.php'); + + $result = $this->ApiDoc->trimFileName('/some/other/path/tests/cases/helpers/api_doc.test.php'); + $expected = '/tests/cases/helpers/api_doc.test.php'; + $this->assertEqual($result, $expected, 'Trim path with different bases is not working %s'); } /** * testFileLink diff --git a/views/api_generator/view_source.ctp b/views/api_generator/view_source.ctp index 59eac4f..bb66f1b 100644 --- a/views/api_generator/view_source.ctp +++ b/views/api_generator/view_source.ctp @@ -5,6 +5,6 @@ */ $this->pageTitle = $apiDoc->trimFileName($filename); ?> -<h1><?php echo $filename; ?></h1> +<h1><?php echo $apiDoc->trimFileName($filename); ?></h1> <?php echo $apiUtils->highlight($contents); ?> diff --git a/views/helpers/api_doc.php b/views/helpers/api_doc.php index eb77c0c..a886dea 100644 --- a/views/helpers/api_doc.php +++ b/views/helpers/api_doc.php @@ -109,7 +109,37 @@ class ApiDocHelper extends AppHelper { if ($this->inBasePath($filename)) { return str_replace($this->_basePath, '', $filename); } + $realPath = $this->_searchBasePath($filename); + if ($this->inBasePath($realPath)) { + return $this->trimFileName($realPath); + } + return $filename; + } + +/** + * Will break a filename up and scan through the basePath for + * any possible matches. + * + * @return string Adjusted path. + **/ + protected function _searchBasePath($filename) { + $pathBits = explode(DS, $filename); + $currentPath = $testPath = $this->_basePath; + while (!empty($pathBits)) { + $pathSegment = array_shift($pathBits); + $testPath .= $pathSegment; + if (count($pathBits)) { + $testPath .= DS; + } + if (is_dir($testPath) || file_exists($testPath)) { + $currentPath = $testPath; + } else { + $testPath = $currentPath; + } + } + return $currentPath; } + /** * Set the Class list so that linkClassName will know which classes are in the index. *