Extension Dokumentation mit reST rendern.

Nachfolgend wird beschrieben, wie die Dokumentation von Extensions als HTML Ausgabe mit reStructuredText (reST) im TYPO3 Look gerendert werden kann. Primär wird auf die Installation und Konfiguration der Komponenten auf einem Linux System eingegangen.

meets

Dokumentation

Aufgrund der fehlenden Unterstützung für Python 3 in t3sphinx (https://forge.typo3.org/issues/39875),
muss Python 2 verwendet werden !
Vielen Dank für diesen Hinweis an Andreas Groth !

Grundsätzlich muss am System Python installiert sein.
Zusätzlich muss PyYAML vorhanden sein.

Anschließend wird der reStructuredText Primer Sphinx installiert.

Jetzt können die RestTools von TYPO3 installiert werden.
Zunächst die Quellen per git holen. Dies kann an einem beliebigen Ort erfolgen.

  
$ git clone git://git.typo3.org/Documentation/RestTools.git

Um die Installation durchzuführen muss in folgendes Verzeichnis gewechselt werden.
RestTools/ExtendingSphinxForTYPO3/
Die Installation wird durch den nachfolgenden Befehlt als Root gestartet.

  
$ python setup.py install

Es folgt die Initialisierung eines neuen Dokumentation Projekts per sphinx-quickstart.
Nachfolgend die Ausgabe (inkl. Kommentare).

  
fazzyx@w530 ~/Documentation $ sphinx-quickstart 
Welcome to the Sphinx 1.2 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Enter the root path for documentation.
> Root path for the documentation [.]: 

You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/N) [n]: y

Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]: 

The project name will occur in several places in the built documentation.
> Project name: Dummy
> Author name(s): Claus Fassing

Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1.  If you don't need this dual structure,
just set both to the same value.
> Project version: 0.0.1
> Project release [0.0.1]: 0.0.1-alpha

The file name suffix for source files. Commonly, this is either ".txt"
or ".rst".  Only files with this suffix are considered documents.
> Source file suffix [.rst]: 

One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]: Index

Sphinx can also add configuration for epub output:
> Do you want to use the epub builder (y/N) [n]: 

Please indicate if you want to use one of the following Sphinx extensions:
> autodoc: automatically insert docstrings from modules (y/N) [n]: 
> doctest: automatically test code snippets in doctest blocks (y/N) [n]: 
> intersphinx: link between Sphinx documentation of different projects (y/N) [n]: y
> todo: write "todo" entries that can be shown or hidden on build (y/N) [n]: 
> coverage: checks for documentation coverage (y/N) [n]: 
> pngmath: include math, rendered as PNG images (y/N) [n]: 
> mathjax: include math, rendered in the browser by MathJax (y/N) [n]: 
> ifconfig: conditional inclusion of content based on config values (y/N) [n]: 
> viewcode: include links to the source code of documented Python objects (y/N) [n]: 

A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (Y/n) [y]: y
> Create Windows command file? (Y/n) [y]: n

Creating file ./source/conf.py.
Creating file ./source/Index.rst.
Creating file ./Makefile.

Finished: An initial directory structure has been created.

You should now populate your master file ./source/Index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
   make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.

Ist dies erfolgreich gewesen, ermitteln wir den Pfad zur erweiterten Konfiguration.
Das ist z.B. direkt per Python Interpreter möglich wie nachfolgend demonstriert.
Benötigt wird der Pfad zur Datei 'typo3_codeblock_for_conf.py'

  
fazzyx@w530 ~/Documentation/source $ python
Python 2.7.5 (default, Oct 14 2013, 09:13:45) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import t3sphinx
>>> dir(t3sphinx)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'fieldlisttable', 'os', 'package_dir', 'pathToGlobalYamlSettings', 'themes_dir', 'typo3_codeblock_for_conf_py', 'yamlsettings']
>>> t3sphinx.typo3_codeblock_for_conf_py
'/usr/lib64/python2.7/site-packages/t3sphinx/resources/typo3_codeblock_for_conf.py'
>>> quit()

Nachdem der Pfad bekannt ist, können die Konfigurationen zusammengeführt werden. 
Dazu muss in das 'source' Verzeichnis des zuvor erstellen Dokumentation Projekts gewechselt werden, oder der vollständige Pfad zur conf.py im nachfolgenden Befehl ergänzt werden.

  
cat /usr/lib64/python2.7/site-packages/t3sphinx/resources/typo3_codeblock_for_conf.py >> conf.py

Dadurch wird die t3sphinx Konfiguration an die zuvor erzeugte angehängt.
Wichtig ist noch den Ordner _not_versioned im source Verzeichnis vom Projekt anzulegen. Dieser bleibt zunächst leer, erst der Builder Process legt dort die gesammelten und zusammengeführten Konfigurationen ab. Ohne diesen Ordner kommt es aber zu einer Fehlermeldung.

Direkt im Projekt Verzeichnis sollte noch die Datei Settings.yml angelegt werden.
In dieser Datei werden die direkt das Projekt betreffenden Konfigurations Optionen angegeben.
Nachfolgend ein paar Beispiel Einträge für diese Datei. Wichtig ist hier html_theme und html_theme_path

  
# Settings.yml
---
conf.py:
  version: 0.0.1
  release: 0.0.1-beta
  copyright: 2014, Claus Fassing
  html_theme: typo3sphinx
  html_theme_path:
  - /usr/lib64/python2.7/site-packages/t3sphinx/themes
  - /home/fazzyx/RestTools/ExtendingSphinxForTYPO3/src/t3sphinx/
...

Sind alle Vorgänge positiv verlaufen, kann das HTML Build gestartet werden.
Die Initialisierung des Projekts hat bereits eine Index.rst Datei erzeugt. Diese reicht für einen ersten Test aus.
Dazu in den Projekt Ordner wechseln und den folgenden Befehl ausführen.

  
$ make html

Ist keine Fehlermeldung ausgegeben worden, befindet sich im 'build' Ordner vom Projekt Verzeichnis eine Index.html Datei, welche im Browser aufgerufen werden kann.

Zu sehen  gibt es dann das Manual mit t3sphinx Theme. In der Settings.yml kann auch als html_theme 't3org' oder 'typo3' angegeben werden.

Zudem erhält man Zugriff auf die Direktive 't3-field-list-table'

Ich hoffe diese Dokumentation ist zielführend, da die Informationen im Netz verteilt vorliegt und es auch keinen Hinweis auf dem benötigten Ordner '_not_versioned' gab.