Skip to content

Commit

Permalink
mangle paths and such to get source code links back
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewandante committed Dec 17, 2020
1 parent 7ef5066 commit 6a2208c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions conf/doctum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use Doctum\Project;
use Doctum\Doctum;
use SilverStripe\ApiDocs\Data\ApiJsonStore;
use SilverStripe\ApiDocs\Data\Config;
use SilverStripe\ApiDocs\Inspections\RecipeFinder;
use SilverStripe\ApiDocs\Inspections\RecipeVersionCollection;
use SilverStripe\ApiDocs\SilverStripeProject;
use SilverStripe\ApiDocs\Twig\NavigationExtension;

// Get config
Expand Down Expand Up @@ -76,7 +76,7 @@
// Override project
unset($doctum['project']);
$doctum['project'] = function ($sc) {
$project = new Project($sc['store'], $sc['_versions'], array(
$project = new SilverStripeProject($sc['store'], $sc['_versions'], array(
'build_dir' => $sc['build_dir'],
'cache_dir' => $sc['cache_dir'],
'remote_repository' => $sc['remote_repository'],
Expand Down
1 change: 1 addition & 0 deletions src/Parser/SilverStripeNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function addClassOrInterface(ClassLikeNode $node)
$class->setAliases($this->context->getAliases());
$class->setHash($this->context->getHash());
$class->setFile($this->context->getFile());
$class->setRelativeFilePath($this->context->getFile());

$comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $class);
$class->setDocComment($node->getDocComment());
Expand Down
15 changes: 15 additions & 0 deletions src/Reflection/SilverStripeClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctum\Reflection\ClassReflection;
use Doctum\Reflection\PropertyReflection;
use SilverStripe\ApiDocs\Data\Config;

class SilverStripeClassReflection extends ClassReflection
{
Expand All @@ -28,4 +29,18 @@ public function getConfigs()
{
return $this->configs;
}

public function getSourcePath($line = null)
{
$config = Config::getConfig();
$realPackagePath = realpath(Config::configPath($config['paths']['packages']));
$realRelativeFilePath = realpath($this->relativeFilePath);
$filePath = substr($realRelativeFilePath, strlen($realPackagePath) + 1);
$parts = explode('/', $filePath);
$package = "{$parts[0]}/{$parts[1]}";
$this->project->setRemoteRepository($config['packages'][$package]['repository']);
$relativePathFromPackage = substr($filePath, strlen($package));

return $this->project->getViewSourceUrl($relativePathFromPackage, $line);
}
}
25 changes: 25 additions & 0 deletions src/SilverStripeProject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace SilverStripe\ApiDocs;

use Doctum\Project;
use Doctum\RemoteRepository\GitHubRemoteRepository;
use SilverStripe\ApiDocs\Data\Config;

class SilverStripeProject extends Project
{
public function setRemoteRepository($remoteRepositoryName)
{
if (strpos($remoteRepositoryName, 'https://github.com/') !== false) {
$remoteRepositoryName = substr($remoteRepositoryName, strlen('https://github.com/'));
}

if (substr($remoteRepositoryName, -4) === '.git') {
$remoteRepositoryName = substr($remoteRepositoryName, 0, -4);
}

$this->config['remote_repository'] = new GitHubRemoteRepository(
$remoteRepositoryName,
Config::getConfig()['paths']['packages'] . "/{$remoteRepositoryName}"
);
}
}

0 comments on commit 6a2208c

Please sign in to comment.