Browse Source

On génère un fichier autodoc.json sur chaque projet.

On s’en servira plus tard pour générer un index (html) des différentes documentations
master
Matthieu Marcillaud 9 months ago
parent
commit
c741241405
  1. 4
      src/Command/FromDirectory.php
  2. 4
      src/Command/FromGit.php
  3. 4
      src/Command/FromSpip.php
  4. 10
      src/Git.php
  5. 2
      src/Stage/CheckStage.php
  6. 2
      src/Stage/GitStage.php
  7. 52
      src/Stage/JsonAutodocStage.php
  8. 2
      src/Stage/PackageStage.php
  9. 11
      src/Stage/PhpDocumentorConfigStage.php
  10. 2
      src/Stage/PhpDocumentorStage.php
  11. 7
      templates/template/components/sidebar.html.twig
  12. 2
      templates/template/components/sidebar_origin.html.twig
  13. 8
      templates/template/css/custom.css.twig

4
src/Command/FromDirectory.php

@ -10,6 +10,7 @@ use League\Pipeline\InterruptibleProcessor;
use League\Pipeline\Pipeline;
use Spip\Autodoc\Context;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\JsonAutodocStage;
use Spip\Autodoc\Stage\PackageStage;
use Spip\Autodoc\Stage\PhpDocumentorConfigStage;
use Spip\Autodoc\Stage\PhpDocumentorStage;
@ -70,7 +71,8 @@ class FromDirectory extends Command
->pipe(new CheckStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());
$pipeline->process($context);
}

4
src/Command/FromGit.php

@ -13,6 +13,7 @@ use Spip\Autodoc\Exception\AutodocException;
use Spip\Autodoc\Git;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\GitStage;
use Spip\Autodoc\Stage\JsonAutodocStage;
use Spip\Autodoc\Stage\PackageStage;
use Spip\Autodoc\Stage\PhpDocumentorConfigStage;
use Spip\Autodoc\Stage\PhpDocumentorStage;
@ -84,7 +85,8 @@ class FromGit extends Command
->pipe(new GitStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());
$pipeline->process($context);
}

4
src/Command/FromSpip.php

@ -11,6 +11,7 @@ use League\Pipeline\Pipeline;
use Spip\Autodoc\Context;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\GitSpipStage;
use Spip\Autodoc\Stage\JsonAutodocStage;
use Spip\Autodoc\Stage\PackageStage;
use Spip\Autodoc\Stage\PhpDocumentorConfigStage;
use Spip\Autodoc\Stage\PhpDocumentorStage;
@ -52,7 +53,8 @@ class FromSpip extends FromGit
->pipe(new GitSpipStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());
$pipeline->process($context);
}

10
src/Git.php

@ -48,4 +48,14 @@ class Git
return $this;
}
/**
* L’url web du repository
*/
public function getRepositoryUrl(): ?string {
if (strpos($this->getUrl(), 'https://') === 0) {
return preg_replace('/[.]git$/', '', $this->getUrl());
}
return null;
}
}

2
src/Stage/CheckStage.php

@ -9,7 +9,7 @@ class CheckStage implements StageInterface
{
public function __invoke(Context $context): Context
{
$context->add('steps', $this::class);
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: " . $this::class);
$context->get('logger')->debug("Cwd: " . $context->get('cwd_directory'));
$context->get('logger')->debug("Php: " . PHP_BINARY);

2
src/Stage/GitStage.php

@ -14,7 +14,7 @@ class GitStage implements StageInterface
public function __invoke(Context $context): Context
{
$context->add('steps', $this::class);
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: ".$this::class);
if (

52
src/Stage/JsonAutodocStage.php

@ -0,0 +1,52 @@
<?php
namespace Spip\Autodoc\Stage;
use DateTime;
use DateTimeInterface;
use Spip\Autodoc\Context;
use Spip\Autodoc\Exception\ContextException;
use Spip\Autodoc\Git;
use Spip\Autodoc\Package;
use stdClass;
/**
* Ajoute un autodoc.json dans le répertoire de sortie de la documentation.
*
* Sera faisable directement en étendant le template 'default' avec
* https://github.com/phpDocumentor/phpDocumentor/issues/2875
*/
class JsonAutodocStage implements StageInterface
{
public function __invoke(Context $context): Context
{
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: " . $this::class);
if (!in_array(PhpDocumentorStage::class, $context->get('stages'))) {
throw new ContextException(sprintf('Stage "%s" needs to be done after stage "%s".', 'JsonAutodocStage', 'PhpDocumentorStage'));
}
$output_directory = $context->get('output_directory');
/** @var Package */
$package = $context->get('package');
$json = new stdClass();
$json->title = $context->get('title');
$json->prefix = $package->get('prefix');
$json->slogan = $package->get('slogan');
$json->version = $package->get('version');
$json->revision = ($context->has('git') ? $context->get('git')->getCommit() : '');
$json->date = (new DateTime())->format(DateTimeInterface::W3C);
$json->urls = new stdClass();
$json->urls->package = $package->get('url_package');
$json->urls->documentation = $package->get('url_documentation');
$json->urls->development = $package->get('url_development');
$json->urls->repository = $context->has('git_asked') ? ($context->get('git_asked')->getRepositoryUrl() ?? '') : '';
file_put_contents($output_directory . '/autodoc.json', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$context->set('autodoc.json', $json);
return $context;
}
}

2
src/Stage/PackageStage.php

@ -14,7 +14,7 @@ class PackageStage implements StageInterface
{
public function __invoke(Context $context): Context
{
$context->add('steps', $this::class);
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: ".$this::class);
if (!$context->has('input_directory')) {

11
src/Stage/PhpDocumentorConfigStage.php

@ -15,7 +15,7 @@ class PhpDocumentorConfigStage implements StageInterface
{
public function __invoke(Context $context): Context
{
$context->add('steps', $this::class);
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: " . $this::class);
if (
@ -68,14 +68,7 @@ class PhpDocumentorConfigStage implements StageInterface
]
);
$repository = '';
if ($context->has('git_asked')) {
/** @var Git */
$git = $context->get('git_asked');
if (strpos($git->getUrl(), 'https://') === 0) {
$repository = preg_replace('/[.]git$/', '', $git->getUrl());
}
}
$repository = $context->has('git_asked') ? ($context->get('git_asked')->getRepositoryUrl() ?? '') : '';
$replacements = [
'@INPUT_DIRECTORY@' => $context->get('input_directory'),

2
src/Stage/PhpDocumentorStage.php

@ -10,7 +10,7 @@ class PhpDocumentorStage implements StageInterface
{
public function __invoke(Context $context): Context
{
$context->add('steps', $this::class);
$context->add('stages', $this::class);
$context->get('logger')->debug("Pass: ".$this::class);
$cmd = $context->get('php') . ' ' . Path::makeRelative($context->get('phpdocumentor'), $context->get('cwd_directory'));

7
templates/template/components/sidebar.html.twig

@ -61,4 +61,11 @@
</section>
{% endif %}
{% endblock %}
{% block outro %}
<div class='phpdocumentor-sidebar__outro'>
<p class='phpdocumentor-sidebar__date'>Documentation générée le {{ 'now'|date('d m Y') }} à {{ 'now'|date('h\\hi') }}</p>
</div>
{% endblock %}

2
templates/template/components/sidebar_origin.html.twig

@ -30,4 +30,6 @@
<h2 class="phpdocumentor-sidebar__category-header">Indices</h2>
<h3 class="phpdocumentor-sidebar__root-package"><a href="indices/files.html">Files</a></h3>
</section>
{% block outro %}{% endblock %}
</aside>

8
templates/template/css/custom.css.twig

@ -42,6 +42,14 @@ a[href^="https://"]:after {
.phpdocumentor-sidebar__version {
margin-bottom: 0 !important;
}
.phpdocumentor-sidebar__outro {
margin-top: 5em;
padding: .5em 1em;
background-color: var(--light-gray);
}
.phpdocumentor-sidebar__date {
margin-bottom: 0 !important;
}
.phpdocumentor-signature__name {

Loading…
Cancel
Save