Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Modifying trimFileName to scan through basePath looking for possible …
Browse files Browse the repository at this point in the history
…matches. Fixes full path showing on view_source. Test case added.
  • Loading branch information
markstory committed May 31, 2009
1 parent ddde937 commit ff112b5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/cases/helpers/api_doc.test.php
Expand Up @@ -54,6 +54,10 @@ function testInBasePath() {
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
Expand Down
2 changes: 1 addition & 1 deletion views/api_generator/view_source.ctp
Expand Up @@ -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); ?>
30 changes: 30 additions & 0 deletions views/helpers/api_doc.php
Expand Up @@ -109,7 +109,37 @@ public function trimFileName($filename) {
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.
*
Expand Down

0 comments on commit ff112b5

Please sign in to comment.