Browse Source

On sait générer un index. Reste à le décorer…

master
Matthieu Marcillaud 9 months ago
parent
commit
7e9cc6b192
  1. 2
      phpdoc/template/components/sidebar.html.twig
  2. 40
      src/Stage/IndexStage.php
  3. 2
      src/Stage/JsonAutodocStage.php
  4. 2
      src/Stage/PhpDocumentorConfigStage.php
  5. 69
      templates/index.html.twig

2
phpdoc/template/components/sidebar.html.twig vendored

@ -66,6 +66,6 @@
{% block outro %}
<div class='phpdocumentor-sidebar__outro'>
<p class='phpdocumentor-sidebar__date'>Documentation générée le {{ 'now'|date('d m Y', "Europe/Paris") }} à {{ 'now'|date('h\\hi', "Europe/Paris") }}</p>
<p class='phpdocumentor-sidebar__date'>Documentation générée le {{ 'now'|date('d m Y', "Europe/Paris") }} à {{ 'now'|date('H\\hi', "Europe/Paris") }}</p>
</div>
{% endblock %}

40
src/Stage/IndexStage.php

@ -20,26 +20,27 @@ class IndexStage implements StageInterface {
}
$list = $this->load($context->directory->output_base);
$sorted = $this->sort($list);
dump($sorted);
$list = $this->sort($list);
$this->createIndex($context, $list);
return $context;
}
/** @return array<string, stdClass> */
public function load(string $output_base_directory): array {
private function load(string $output_base_directory): array {
$list = [];
$projects = glob($output_base_directory . '/*/autodoc.json');
foreach ($projects as $project) {
$dir = basename(dirname($project));
$json = json_decode(file_get_contents($project));
$list[$dir] = $json;
$json->path = $dir;
$list[] = $json;
}
return $list;
}
/** @return array<string, stdClass> */
public function sort(array $list): array {
private function sort(array $list): array {
$groups = [];
foreach ($list as $project) {
$organization = basename(dirname($project->urls->repository ?: '')) ?: 'other';
@ -55,4 +56,33 @@ class IndexStage implements StageInterface {
}
return $groups;
}
private function createIndex(Context $context, array $groups) {
// charger Twig, générer la page et l'enregitrer
$loader = new \Twig\Loader\FilesystemLoader($context->directory->templates);
$twig = new \Twig\Environment($loader);
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');
$organizations = [
'spip' => 'SPIP',
'spip-core' => 'Core',
'spip-contrib-extensions' => 'Plugins',
'spip-contrib-outils' => 'Outils',
'spip-contrib-squelettes' => 'Squelettes',
'other' => 'Autres',
];
$others = array_diff(array_keys($groups), array_keys($organizations));
foreach ($others as $other) {
$organizations[$other] = $other;
}
$index = $twig->render('index.html.twig', [
'title' => 'Documentation automatique de SPIP et ses plugins',
'groups' => $groups,
'organizations' => $organizations,
]);
file_put_contents($context->directory->output_base . '/index.html', $index);
return $context;
}
}

2
src/Stage/JsonAutodocStage.php

@ -42,7 +42,7 @@ class JsonAutodocStage implements StageInterface
$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() ?? '') : '';
$json->urls->repository = $context->has('git') ? ($context->get('git')->getRepositoryUrl() ?? '') : '';
file_put_contents($output_directory . '/autodoc.json', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));

2
src/Stage/PhpDocumentorConfigStage.php

@ -76,8 +76,6 @@ class PhpDocumentorConfigStage implements StageInterface
private function generateConfig(Context $context) {
$repository = $context->has('git_asked') ? ($context->get('git_asked')->getRepositoryUrl() ?? '') : '';
// charger Twig, générer la page et l'enregitrer
$loader = new \Twig\Loader\FilesystemLoader($context->directory->templates);
$twig = new \Twig\Environment($loader);

69
templates/index.html → templates/index.html.twig

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ titre }}</title>
<title>{{ title }}</title>
<meta charset="utf-8" />
@ -28,7 +28,7 @@
<div class='container'>
<div class="heading row">
<div class="titre span12">
<h1><span></span>{{ titre }}</h1>
<h1><span></span>{{ title }}</h1>
</div>
</div>
</div><!-- .container -->
@ -50,38 +50,41 @@
<div class="principal">
<div class="content" id="content">
<h1 class='hide'>{{ titre }}</h1>
<h1 class='hide'>{{ title }}</h1>
<h2>Liste des documentations du code PHP de plugin pour SPIP :</h2>
<table class="table">
<thead>
<tr><th>Nom</th><th>Description</th><th>Autres liens</th></tr>
</thead>
<tbody>
{% for plugin in plugins %}
<tr>
<th><a href="{{ plugin.prefixe ~ '/'}}">
{{ plugin.nom }}</a></th>
<td>{{ plugin.slogan }}</td>
<td>
{%- if plugin.annuaire %}
<a href="{{ plugin.annuaire }}">Annuaire</a>
{%- endif %}
{%- if plugin.documentation %}
{{- plugin.annuaire ? ' <span class="sep">/</span> '}}
<a href="{{ plugin.documentation }}">Documentation</a>
{%- endif %}
{%- if plugin.developpement %}
{{- (plugin.annuaire or plugin.documentation) ? ' <span class="sep">/</span> '}}
<a href="{{ plugin.developpement }}">Suivi</a>
{%- endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% for organization, name in organizations %}
{% if groups[organization] %}
<h2>{{ name }}</h2>
<table class="table">
<thead>
<tr><th>Nom</th><th>Description</th><th>Autres liens</th></tr>
</thead>
<tbody>
{% for package in groups[organization] %}
<tr>
<th><a href="{{ package.path ~ '/'}}">
{{ package.title }}</a></th>
<td>{{ package.slogan }}</td>
<td class="links">
{%- if package.urls.package %}
<a href="{{ package.urls.package }}" class="spip_out">Annuaire</a>
{%- endif %}
{%- if package.urls.documentation %}
<a href="{{ package.urls.documentation }}" class="spip_out">Documentation</a>
{%- endif %}
{%- if package.urls.repository %}
<a href="{{ package.urls.repository }}" class="spip_out">Forge</a>
{%- endif %}
{%- if package.urls.development and (package.urls.development != package.urls.repository) %}
<a href="{{ package.urls.development }}" class="spip_out">Développement</a>
{%- endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endfor %}
</div><!-- #content -->
</div><!-- .principal -->
Loading…
Cancel
Save