Browse Source

Centraliser les paramètres de header (titre, soustitre, topnav)

master
Matthieu Marcillaud 9 months ago
parent
commit
79fd530cf1
  1. 3
      src/Command/FromDirectory.php
  2. 3
      src/Command/FromFile.php
  3. 3
      src/Command/FromGit.php
  4. 3
      src/Command/MakeIndex.php
  5. 11
      src/Context.php
  6. 10
      src/Stage/IndexStage.php
  7. 14
      src/Stage/PhpDocumentorConfigStage.php
  8. 8
      templates/index.html.twig
  9. 2
      templates/phpdoc.xml.twig

3
src/Command/FromDirectory.php

@ -55,8 +55,7 @@ class FromDirectory extends Command
if ($input->hasOption('prefix') and $input->getOption('prefix')) {
$context->set('default_prefix', $input->getOption('prefix'));
}
$context->set('topnav', $input->getOption('topnav'));
$context->set('topnav_spip', $input->getOption('topnav_spip'));
$context->header->set('topnav', $input->getOption('topnav_spip') ? Context::TOPNAV_SPIP : $input->getOption('topnav'));
$context->phpdocumentor->options->set('force', $input->getOption('force'));
$this->pipeline($context);

3
src/Command/FromFile.php

@ -78,8 +78,7 @@ https://git.spip.net/spip-contrib-extensions/champs_extras_core@master;cextras
$context->set('only_this_prefix', $input->getOption('outputs'));
}
$context->set('topnav', $input->getOption('topnav'));
$context->set('topnav_spip', $input->getOption('topnav_spip'));
$context->header->set('topnav', $input->getOption('topnav_spip') ? Context::TOPNAV_SPIP : $input->getOption('topnav'));
$context->phpdocumentor->options->set('force', $input->getOption('force'));
$autodoc = new AutodocFile(

3
src/Command/FromGit.php

@ -68,8 +68,7 @@ class FromGit extends Command
$context->directory->set('output', $input->getOption('output'));
$context->set('default_prefix', $input->getOption('prefix') ?: pathinfo($source, \PATHINFO_FILENAME));
$context->set('topnav', $input->getOption('topnav'));
$context->set('topnav_spip', $input->getOption('topnav_spip'));
$context->header->set('topnav', $input->getOption('topnav_spip') ? Context::TOPNAV_SPIP : $input->getOption('topnav'));
$context->phpdocumentor->options->set('force', $input->getOption('force'));
$branch = $input->getOption('branch');

3
src/Command/MakeIndex.php

@ -43,8 +43,7 @@ class MakeIndex extends Command
if ($input->getOption('outputs')) {
$context->directory->set('output_base', $input->getOption('outputs'));
}
$context->set('topnav', $input->getOption('topnav'));
$context->set('topnav_spip', $input->getOption('topnav_spip'));
$context->header->set('topnav', $input->getOption('topnav_spip') ? Context::TOPNAV_SPIP : $input->getOption('topnav'));
$this->pipeline($context);

11
src/Context.php

@ -9,6 +9,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
class Context extends Container
{
const TOPNAV_SPIP = '//boussole.spip.net/?page=spipnav.js&lang=fr';
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->set('io', new SymfonyStyle($input, $output));
@ -17,8 +19,13 @@ class Context extends Container
$this->set('php', PHP_BINARY);
$this->set('default_prefix', 'default');
$this->set('only_this_prefix', null);
$this->set('topnav', null);
$this->set('topnav_spip', null);
$this->set('header', new Container([
'title' => 'SPIP Code',
'subtitle' => 'Documentation du code de SPIP et de ses plugins',
'url' => 'https://code.spip.net/',
'topnav' => null,
]));
$cwd = getcwd();
$var = $cwd . '/var';

10
src/Stage/IndexStage.php

@ -99,19 +99,11 @@ class IndexStage implements StageInterface {
$organizations[$other] = $other;
}
$topnav = match (true) {
!$context->empty('topnav_spip') => PhpDocumentorConfigStage::TOPNAV_SPIP,
!$context->empty('topnav') => $context->get('topnav'),
default => null,
};
$template = new Template($context->directory->templates, $context->directory->output_base);
$template->generate('index.html.twig', [
'title' => 'SPIP Code',
'subtitle' => 'Documentation du code de SPIP et ses plugins',
'header' => $context->header,
'groups' => $groups,
'organizations' => $organizations,
'topnav' => $topnav,
]);
}

14
src/Stage/PhpDocumentorConfigStage.php

@ -16,7 +16,6 @@ use Symfony\Component\Filesystem\Filesystem;
*/
class PhpDocumentorConfigStage implements StageInterface
{
const TOPNAV_SPIP = '//boussole.spip.net/?page=spipnav.js&lang=fr';
public function __invoke(Context $context): Context
{
@ -84,24 +83,13 @@ class PhpDocumentorConfigStage implements StageInterface
private function generateConfig(Context $context) {
$template = new Template($context->directory->templates, $context->directory->config);
$topnav = match (true) {
!$context->empty('topnav_spip') => $this::TOPNAV_SPIP,
!$context->empty('topnav') => $context->get('topnav'),
default => null,
};
// FIXME: externaliser en config ...
$header = new stdClass();
$header->title = 'SPIP Code';
$header->subtitle = 'Documentation du code de SPIP et ses plugins';
$header->url = 'https://code.spip.net/';
$content = $template->render('phpdoc.xml.twig', [
'title' => $context->title,
'presentation' => $context->presentation,
'package' => $context->package,
'directory' => $context->directory,
'git' => $context->has('git') ? $context->git : null,
'topnav' => $topnav,
'header' => $header
'header' => $context->header,
]);
$file = 'phpdoc_' . ($context->package->prefix ?: $context->default_prefix) . '.xml';
$template->write($file, $content);

8
templates/index.html.twig

@ -13,11 +13,11 @@
<link rel="stylesheet" href="autodoc.css" />
<link rel="shortcut icon" type="image/png" href="favicon.png" />
{%- if topnav %}
{%- if header.topnav %}
<script type="text/javascript">
(function() {
var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
g.type='text/javascript';g.defer=true;g.async=true;g.src="{{ topnav|raw }}";s.parentNode.insertBefore(g,s);
g.type='text/javascript';g.defer=true;g.async=true;g.src="{{ header.topnav|raw }}";s.parentNode.insertBefore(g,s);
})();
</script>
{%- endif -%}
@ -27,13 +27,13 @@
<header class="autodoc-header" id="header">
<div class='autodoc-container'>
<div class="autodoc-title">
<h1>{{ title }}</h1>
<h1>{{ header.title }}</h1>
</div>
</div>
</header>
<div class="autodoc-navbar">
<div class="autodoc-container">
<strong class="autodoc-subtitle">{{ subtitle }}</strong>
<strong class="autodoc-subtitle">{{ header.subtitle }}</strong>
</div>
</div>

2
templates/phpdoc.xml.twig

@ -56,7 +56,7 @@
<setting name="package.url_documentation" value="{{ package.url_documentation }}"/>
<setting name="package.url_development" value="{{ package.url_development }}" />
<setting name="package.url_repository" value="{{ git.repositoryurl }}"/>
<setting name="js.topnav" value="{{ topnav }}"/>
<setting name="js.topnav" value="{{ header.topnav }}"/>
<setting name="header.url" value="{{ header.url }}"/>
<setting name="header.title" value="{{ header.title }}"/>
<setting name="header.subtitle" value="{{ header.subtitle }}"/>

Loading…
Cancel
Save