|
6 | 6 | Renderer
|
7 | 7 | ========
|
8 | 8 |
|
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. |
0 commit comments