Merge pull request #97 from webbuilders-group/windows-path-fix

BUGFIX: Fixed issues related to windows filesystem using backslash instead of forward slash
This commit is contained in:
Daniel Hensby 2016-02-22 14:58:43 +00:00
commit d5f53864d7
4 changed files with 27 additions and 11 deletions

View File

@ -92,4 +92,20 @@ class DocumentationHelper
return null; return null;
} }
/**
* Helper function to normalize paths to unix style directory separators
*
* @param string
*
* @return string
*/
public static function normalizePath($path)
{
if (DIRECTORY_SEPARATOR != '/') {
return str_replace(DIRECTORY_SEPARATOR, '/', $path);
}
return $path;
}
} }

View File

@ -145,7 +145,7 @@ class DocumentationManifest
'DocumentationEntity', $key 'DocumentationEntity', $key
); );
$entity->setPath(Controller::join_links($path, $lang, '/')); $entity->setPath(DocumentationHelper::normalizePath(Controller::join_links($path, $lang, '/')));
$entity->setTitle($details['Title']); $entity->setTitle($details['Title']);
$entity->setLanguage($lang); $entity->setLanguage($lang);
$entity->setVersion($version); $entity->setVersion($version);
@ -168,7 +168,7 @@ class DocumentationManifest
public function getRealPath($path) public function getRealPath($path)
{ {
if (substr($path, 0, 1) != '/') { if (!Director::is_absolute($path)) {
$path = Controller::join_links(BASE_PATH, $path); $path = Controller::join_links(BASE_PATH, $path);
} }
@ -201,7 +201,7 @@ class DocumentationManifest
continue; continue;
} }
$dir = Controller::join_links(BASE_PATH, $entity); $dir = DocumentationHelper::normalizePath(Controller::join_links(BASE_PATH, $entity));
if (is_dir($dir)) { if (is_dir($dir)) {
// check to see if it has docs // check to see if it has docs
@ -406,7 +406,7 @@ class DocumentationManifest
$this->pages[$link] = array( $this->pages[$link] = array(
'title' => $page->getTitle(), 'title' => $page->getTitle(),
'basename' => $basename, 'basename' => $basename,
'filepath' => $path, 'filepath' => DocumentationHelper::normalizePath($path),
'type' => get_class($page), 'type' => get_class($page),
'entitypath' => $this->entity->getPath(), 'entitypath' => $this->entity->getPath(),
'summary' => $page->getSummary() 'summary' => $page->getSummary()
@ -627,7 +627,7 @@ class DocumentationManifest
$base = Config::inst()->get('DocumentationViewer', 'link_base'); $base = Config::inst()->get('DocumentationViewer', 'link_base');
$entityPath = $this->normalizeUrl($entityPath); $entityPath = $this->normalizeUrl($entityPath);
$recordPath = $this->normalizeUrl($recordPath); $recordPath = $this->normalizeUrl($recordPath);
$recordParts = explode(DIRECTORY_SEPARATOR, trim($recordPath, '/')); $recordParts = explode('/', trim($recordPath, '/'));
$currentRecordPath = end($recordParts); $currentRecordPath = end($recordParts);
$depth = substr_count($entityPath, '/'); $depth = substr_count($entityPath, '/');
@ -640,8 +640,8 @@ class DocumentationManifest
} }
// only pull it up if it's one more level depth // only pull it up if it's one more level depth
if (substr_count($pagePath, DIRECTORY_SEPARATOR) == ($depth + 1)) { if (substr_count($pagePath, '/') == ($depth + 1)) {
$pagePathParts = explode(DIRECTORY_SEPARATOR, trim($pagePath, '/')); $pagePathParts = explode('/', trim($pagePath, '/'));
$currentPagePath = end($pagePathParts); $currentPagePath = end($pagePathParts);
if ($currentPagePath == $currentRecordPath) { if ($currentPagePath == $currentRecordPath) {
$mode = 'current'; $mode = 'current';

View File

@ -440,12 +440,12 @@ class DocumentationParser
// relative path (relative to module base folder), without the filename. // relative path (relative to module base folder), without the filename.
// For "sapphire/en/current/topics/templates", this would be "templates" // For "sapphire/en/current/topics/templates", this would be "templates"
$relativePath = dirname($page->getRelativePath()); $relativePath = DocumentationHelper::normalizePath(dirname($page->getRelativePath()));
if (strpos($page->getRelativePath(), 'index.md')) { if (strpos($page->getRelativePath(), 'index.md')) {
$relativeLink = $page->getRelativeLink(); $relativeLink = $page->getRelativeLink();
} else { } else {
$relativeLink = dirname($page->getRelativeLink()); $relativeLink = DocumentationHelper::normalizePath(dirname($page->getRelativeLink()));
} }
if ($relativePath == '.') { if ($relativePath == '.') {
@ -457,7 +457,7 @@ class DocumentationParser
} }
// file base link // file base link
$fileBaseLink = Director::makeRelative(dirname($page->getPath())); $fileBaseLink = DocumentationHelper::normalizePath(Director::makeRelative(dirname($page->getPath())));
if ($matches) { if ($matches) {
foreach ($matches[0] as $i => $match) { foreach ($matches[0] as $i => $match) {

View File

@ -126,7 +126,7 @@ class DocumentationPage extends ViewableData
if ($folder == $entity) { if ($folder == $entity) {
return $this->getEntity()->getTitle(); return $this->getEntity()->getTitle();
} else { } else {
$path = explode(DIRECTORY_SEPARATOR, trim($folder, DIRECTORY_SEPARATOR)); $path = explode('/', trim($folder, '/'));
$folderName = array_pop($path); $folderName = array_pop($path);
} }