Browse Source

On surcharge la sidebar du template pour ajouter quelques liens (plugins, documentation, forge, ...)

ainsi éventuellement que le slogan.
master
Matthieu Marcillaud 9 months ago
parent
commit
b8f955c750
  1. 18
      placeholders/phpdoc.xml
  2. 4
      src/Package.php
  3. 14
      src/Stage/PhpDocumentorConfigStage.php
  4. 51
      templates/template/components/sidebar.html.twig
  5. 33
      templates/template/components/sidebar_origin.html.twig
  6. 6
      templates/template/css/custom.css.twig

18
placeholders/phpdoc.xml

@ -43,14 +43,14 @@
</guide>
</version>
<setting name="slogan" value="@SLOGAN@"/>
<setting name="description" value="@DESCRIPTION@"/>
<setting name="presentation" value="@PRESENTATION@"/>
<setting name="url_package" value="@URL_PACKAGE@"/>
<setting name="url_documentation" value="@URL_DOCUMENTATION@"/>
<setting name="url_development" value="@URL_DEVELOPMENT@"/>
<setting name="package.slogan" value="@SLOGAN@"/>
<setting name="package.description" value="@DESCRIPTION@"/>
<setting name="package.presentation" value="@PRESENTATION@"/>
<setting name="package.url_package" value="@URL_PACKAGE@"/>
<setting name="package.url_documentation" value="@URL_DOCUMENTATION@"/>
<setting name="package.url_development" value="@URL_DEVELOPMENT@"/>
<setting name="package.url_repository" value="@URL_REPOSITORY@"/>
<!--template name="string" location="string">
<parameter name="string" value="string"/>
</template -->
<setting name="guides.enabled" value="@GUIDES_ENABLED@"/>
<template name="default" />
</phpdocumentor>

4
src/Package.php

@ -19,6 +19,7 @@ class Package
private string $url_package = '';
private string $url_documentation = '';
private string $url_development = '';
private bool $with_rst_documentation = false;
public function __construct(
private string $input_directory,
@ -69,6 +70,9 @@ class Package
} else {
$this->logger->notice('Directory does not contains Spip or Plugin');
}
if (file_exists($this->input_directory.'/docs/index.rst')) {
$this->with_rst_documentation = true;
}
}
private function load(string $path_package)

14
src/Stage/PhpDocumentorConfigStage.php

@ -4,6 +4,7 @@ namespace Spip\Autodoc\Stage;
use Spip\Autodoc\Context;
use Spip\Autodoc\Exception\ContextException;
use Spip\Autodoc\Git;
use Spip\Autodoc\Package;
use Symfony\Component\Filesystem\Filesystem;
@ -67,7 +68,15 @@ class PhpDocumentorConfigStage implements StageInterface
]
);
$template = file_get_contents($context->get('phpdocumentor_template_xml'));
$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());
}
}
$replacements = [
'@INPUT_DIRECTORY@' => $context->get('input_directory'),
'@OUTPUT_DIRECTORY@' => $output_directory,
@ -82,7 +91,10 @@ class PhpDocumentorConfigStage implements StageInterface
'@URL_PACKAGE@' => $package->get('url_package'),
'@URL_DOCUMENTATION@' => $package->get('url_documentation'),
'@URL_DEVELOPMENT@' => $package->get('url_development'),
'@URL_REPOSITORY@' => $repository,
'@GUIDES_ENABLED@' => ($package->get('with_rst_documentation') ? 'true' : 'false'),
];
$template = file_get_contents($context->get('phpdocumentor_template_xml'));
$config = str_replace(array_keys($replacements), $replacements, $template);
$config_file = $config_directory . '/phpdoc_' . $prefix . '.xml';
file_put_contents($config_file, $config);

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

@ -0,0 +1,51 @@
{% extends 'components/sidebar_origin.html.twig' %}
{% block intro %}
{% if project.settings.custom['package.slogan'] %}
<p class='phpdocumentor-sidebar__slogan'>
{{- project.settings.custom['package.slogan'] -}}
</p>
{% endif %}
{#
{% if project.settings.custom['package.description'] %}
<div class='phpdocumentor-sidebar__description'>
{{- project.settings.custom['package.description'] -}}
</div>
{% endif %}
#}
{% if
project.settings.custom['package.url_package']
or project.settings.custom['package.url_documentation']
or project.settings.custom['package.url_development']
%}
<section class="phpdocumentor-sidebar__category">
<h2 class="phpdocumentor-sidebar__category-header">Links</h2>
{% if project.settings.custom['package.url_package'] %}
<h3 class="phpdocumentor-sidebar__root-package">
<a class="link-out" href="{{ project.settings.custom['package.url_package'] }}">Plugins.spip.net</a>
</h3>
{% endif %}
{% if project.settings.custom['package.url_documentation'] %}
<h3 class="phpdocumentor-sidebar__root-package">
<a class="link-out" href="{{ project.settings.custom['package.url_documentation'] }}">Documentation</a>
</h3>
{% endif %}
{% if project.settings.custom['package.url_repository'] %}
<h3 class="phpdocumentor-sidebar__root-package">
<a class="link-out" href="{{ project.settings.custom['package.url_repository'] }}">Forge</a>
</h3>
{% endif %}
{% if
project.settings.custom['package.url_development']
and (project.settings.custom['package.url_repository'] != project.settings.custom['package.url_development'])
%}
<h3 class="phpdocumentor-sidebar__root-package">
<a class="link-out" href="{{ project.settings.custom['package.url_development'] }}">Développement</a>
</h3>
{% endif %}
</section>
{% endif %}
{% endblock %}

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

@ -0,0 +1,33 @@
<input class="phpdocumentor-sidebar__menu-button" type="checkbox" id="sidebar-button" name="sidebar-button" />
<label class="phpdocumentor-sidebar__menu-icon" for="sidebar-button">
Menu
</label>
<aside class="phpdocumentor-column -four phpdocumentor-sidebar">
{% block intro %}{% endblock %}
{% for version in project.versions %}
{% for toc in version.tableOfContents %}
<section class="phpdocumentor-sidebar__category">
<h2 class="phpdocumentor-sidebar__category-header">{{ toc.name }}</h2>
{% for root in toc.roots %}
{{ toc(root, 'components/menu.html.twig', 1) }}
{% endfor %}
</section>
{% endfor %}
{% endfor %}
<section class="phpdocumentor-sidebar__category">
<h2 class="phpdocumentor-sidebar__category-header">Reports</h2>
{% if project.settings.custom['graphs.enabled'] %}
<h3 class="phpdocumentor-sidebar__root-package"><a href="graphs/classes.html">Class Diagram</a></h3>
{% endif %}
<h3 class="phpdocumentor-sidebar__root-package"><a href="reports/deprecated.html">Deprecated</a></h3>
<h3 class="phpdocumentor-sidebar__root-package"><a href="reports/errors.html">Errors</a></h3>
<h3 class="phpdocumentor-sidebar__root-package"><a href="reports/markers.html">Markers</a></h3>
</section>
<section class="phpdocumentor-sidebar__category">
<h2 class="phpdocumentor-sidebar__category-header">Indices</h2>
<h3 class="phpdocumentor-sidebar__root-package"><a href="indices/files.html">Files</a></h3>
</section>
</aside>

6
templates/template/css/custom.css.twig

@ -24,7 +24,11 @@
--spip-border-radius: 10px;
}
a.link-out:after,
a[href^="http://"]:after,
a[href^="https://"]:after {
content: "⬈";
}
.phpdocumentor-signature__name {
color: var(--spip-name-color);

Loading…
Cancel
Save