Skip to content

Commit d4bf48b

Browse files
committed
[DOCS] Document the renderer
1 parent 74b3ed0 commit d4bf48b

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\Renderer;
6+
7+
use phpDocumentor\Guides\Renderer\BaseTypeRenderer;
8+
9+
final class PlaintextRenderer extends BaseTypeRenderer
10+
{
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use MyVendor\MyExtension\Renderer\PlaintextRenderer;
4+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
5+
6+
return static function (ContainerConfigurator $container): void {
7+
$container->services()
8+
->defaults()->autowire()
9+
// ...
10+
->set(PlaintextRenderer::class)
11+
->tag(
12+
'phpdoc.renderer.typerenderer',
13+
[
14+
'noderender_tag' => 'phpdoc.guides.noderenderer.txt',
15+
'format' => 'txt',
16+
],
17+
);
18+
};

docs/components/renderer.rst

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,58 @@
66
Renderer
77
========
88

9-
.. warning::
10-
This needs to be documented
9+
A Renderer transforms the :abbreviation:`AST (abstract syntax tree)` into a
10+
desired output format.
11+
12+
The most common renderers handle each document separately. For example the
13+
:php:class:`\phpDocumentor\Guides\Renderer\HtmlRenderer` renders the AST into
14+
HTML.
15+
16+
Each renderer must implement
17+
:php:interface:`\phpDocumentor\Guides\Renderer\TypeRenderer`.
18+
19+
Basic document
20+
type renderers like the HTML or Latex renderer can extend
21+
the :php:class:`\phpDocumentor\Guides\Renderer\BaseTypeRenderer`. The
22+
:php:`BaseTypeRenderer` creates a
23+
:php:class:`\phpDocumentor\Guides\Handlers\RenderDocumentCommand` for each
24+
document in the document tree. The :php:`RenderDocumentCommand` passes the
25+
rendering to the NodeRenders which do the actual rendering.
26+
27+
All renderers must be registered in the ContainerConfigurator of the extension
28+
with the tag :php:`'phpdoc.renderer.typerenderer'` and additional format information.
29+
30+
Example: a plaintext renderer
31+
=============================
32+
33+
Create a class called :php:`PlaintextRenderer` which just extends
34+
:php:class:`\phpDocumentor\Guides\Renderer\BaseTypeRenderer`.
35+
36+
.. literalinclude:: _renderer/_PlaintextRenderer.php
37+
:language: php
38+
:caption: src/Renderer/PlaintextRenderer.php
39+
40+
Register the new renderer in the container:
41+
42+
.. literalinclude:: _renderer/_myextension.php
43+
:language: php
44+
:caption: resources/config/myextension.php
45+
46+
You can now configure your project to also generate output in plaintext:
47+
48+
.. code-block:: php
49+
:caption: guides.xml
50+
51+
<?xml version="1.0" encoding="UTF-8" ?>
52+
<guides xmlns="https://www.phpdoc.org/guides"
53+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
55+
>
56+
<extension class="MyVendor\MyExtension"/>
57+
<output-format>txt</output-format>
58+
</guides>
59+
60+
You can now define :ref:`custom templates <extending_templates>` or even custom
61+
NodeRenderer for the new output format.
62+
63+
.. todo: document NodeRenderer and then link them from here.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ If you are looking for a complete solution to create a documentation website the
4646
cli/index
4747
developers/index
4848
architecture
49+
components/index
4950
reference/index
5051
contributions/index

0 commit comments

Comments
 (0)