Documentation Format¶
The Sylius documentation uses reStructuredText as its markup language and Sphinx for building the output (HTML, PDF, ...).
reStructuredText¶
reStructuredText “is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system”.
You can learn more about its syntax by reading existing Sylius documents or by reading the reStructuredText Primer on the Sphinx website.
If you are familiar with Markdown, be careful as things are sometimes very similar but different:
- Lists starts at the beginning of a line (no indentation is allowed);
- Inline code blocks use double-ticks (
``like this``).
Sphinx¶
Sphinx is a build system that adds some nice tools to create documentation from reStructuredText documents. As such, it adds new directives and interpreted text roles to standard reST markup.
Syntax Highlighting¶
All code examples uses PHP as the default highlighted language. You can change
it with the code-block directive:
.. code-block:: yaml
{ foo: bar, bar: { foo: bar, bar: baz } }
If your PHP code begins with <?php, then you need to use html+php as
the highlighted pseudo-language:
.. code-block:: html+php
<?php echo $this->foobar(); ?>
Примечание
A list of supported languages is available on the Pygments website.
Configuration Blocks¶
Whenever you show a configuration, you must use the configuration-block
directive to show the configuration in all supported configuration formats
(PHP, YAML, and XML)
.. configuration-block::
.. code-block:: yaml
# Configuration in YAML
.. code-block:: xml
<!-- Configuration in XML //-->
.. code-block:: php
// Configuration in PHP
The previous reST snippet renders as follow:
- YAML
# Configuration in YAML - XML
<!-- Configuration in XML //--> - PHP
// Configuration in PHP
The current list of supported formats are the following:
| Markup format | Displayed |
|---|---|
| html | HTML |
| xml | XML |
| php | PHP |
| yaml | YAML |
| jinja | Twig |
| html+jinja | Twig |
| html+php | PHP |
| ini | INI |
| php-annotations | Annotations |
Adding Links¶
To add links to other pages in the documents use the following syntax:
:doc:`/path/to/page`
Using the path and filename of the page without the extension, for example:
:doc:`/book/architecture`
:doc:`/bundles/SyliusAddressingBundle/installation`
The link text will be the main heading of the document linked to. You can also specify alternative text for the link:
:doc:`Simple CRUD </bundles/SyliusResourceBundle/installation>`
You can also add links to the API documentation:
:namespace:`Sylius\\Bundle\\CoreBundle`
:class:`Sylius\\Bundle\\CoreBundle\\Model\\Order`
:method:`Sylius\\Bundle\\AddressingBundle\\Matcher\\ZoneMatcher::match`
and to the PHP documentation:
:phpclass:`SimpleXMLElement`
:phpmethod:`DateTime::createFromFormat`
:phpfunction:`iterator_to_array`
Testing Documentation¶
To test documentation before a commit:
- Install Sphinx;
- Run the Sphinx quick setup;
- Install the Sphinx extensions (see below);
- Run
make htmland view the generated HTML in thebuilddirectory.
Installing the Sphinx extensions¶
- Download the extension from the source repository
- Copy the
sensiodirectory to the_extsfolder under your source folder (whereconf.pyis located) - Add the following to the
conf.pyfile:
# ...
sys.path.append(os.path.abspath('_exts'))
# adding PhpLexer
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
# ...
# add the extensions to the list of extensions
extensions = [..., 'sensio.sphinx.refinclude', 'sensio.sphinx.configurationblock', 'sensio.sphinx.phpcode']
# enable highlighting for PHP code not between ``<?php ... ?>`` by default
lexers['php'] = PhpLexer(startinline=True)
lexers['php-annotations'] = PhpLexer(startinline=True)
lexers['php-standalone'] = PhpLexer(startinline=True)
lexers['php-symfony'] = PhpLexer(startinline=True)
# use PHP as the primary domain
primary_domain = 'php'
# set URL for API links
api_url = 'http://api.sylius.org/master/%s'