|
| 1 | +Documentation Standards |
| 2 | +======================= |
| 3 | + |
| 4 | +In order to help the reader as much as possible and to create code examples that |
| 5 | +look and feel familiar, you should follow these standards. |
| 6 | + |
| 7 | +Sphinx |
| 8 | +------ |
| 9 | + |
| 10 | +* The following characters are choosen for different heading levels: level 1 |
| 11 | + is ``=``, level 2 ``-``, level 3 ``~``, level 4 ``.`` and level 5 ``"``; |
| 12 | +* Each line should break approximately after the first word that crosses the |
| 13 | + 72nd character (so most lines end up being 72-78 characters); |
| 14 | +* The ``::`` shorthand is *preferred* over ``.. code-block:: php`` to begin a PHP |
| 15 | + code block (read `the Sphinx documentation`_ to see when you should use the |
| 16 | + shorthand); |
| 17 | +* Inline hyperlinks are **not** used. Seperate the link and their target |
| 18 | + definition, which you add on the bottom of the page; |
| 19 | +* You should use a form of *you* instead of *we*. |
| 20 | + |
| 21 | +Example |
| 22 | +~~~~~~~ |
| 23 | + |
| 24 | +.. code-block:: ReST |
| 25 | +
|
| 26 | + Example |
| 27 | + ======= |
| 28 | +
|
| 29 | + When you are working on the docs, you should follow the `Symfony Docs`_ |
| 30 | + standards. |
| 31 | +
|
| 32 | + Level 2 |
| 33 | + ------- |
| 34 | +
|
| 35 | + A PHP example would be:: |
| 36 | +
|
| 37 | + echo 'Hello World'; |
| 38 | +
|
| 39 | + Level 3 |
| 40 | + ~~~~~~~ |
| 41 | +
|
| 42 | + .. code-block:: php |
| 43 | +
|
| 44 | + echo 'You cannot use the :: shortcut here'; |
| 45 | +
|
| 46 | + .. _`Symfony Docs`: http://symfony.com/doc/current/contributing/documentation/standards.html |
| 47 | +
|
| 48 | +Code Examples |
| 49 | +------------- |
| 50 | + |
| 51 | +* The code follows the :doc:`Symfony Coding Standards</contributing/code/standards>` |
| 52 | + as well as the `Twig Coding Standards`_; |
| 53 | +* To avoid horizontal scrolling on code blocks, we prefer to break a line |
| 54 | + correctly if it crosses the 85th character; |
| 55 | +* When you fold one or more lines of code, place ``...`` in a comment at the point |
| 56 | + of the fold. These comments are: ``// ...`` (php), ``# ...`` (yaml/bash), ``{# ... #}`` |
| 57 | + (twig), ``<!-- ... -->`` (xml/html), ``; ...`` (ini), ``...`` (text); |
| 58 | +* When you fold a part of a line, e.g. a variable value, put ``...`` (without comment) |
| 59 | + at the place of the fold; |
| 60 | +* Description of the folded code: (optional) |
| 61 | + If you fold several lines: the description of the fold can be placed after the ``...`` |
| 62 | + If you fold only part of a line: the description can be placed before the line; |
| 63 | +* If useful, a ``codeblock`` should begin with a comment containing the filename |
| 64 | + of the file in the code block. Don't place a blank line after this comment, |
| 65 | + unless the next line is also a comment; |
| 66 | +* You should put a ``$`` in front of every bash line. |
| 67 | + |
| 68 | +Formats |
| 69 | +~~~~~~~ |
| 70 | + |
| 71 | +Configuration examples should show all supported formats using |
| 72 | +:ref:`configuration blocks <docs-configuration-blocks>`. The supported formats |
| 73 | +(and their orders) are: |
| 74 | + |
| 75 | +* **Configuration** (including services and routing): Yaml, Xml, Php |
| 76 | +* **Validation**: Yaml, Annotations, Xml, Php |
| 77 | +* **Doctrine Mapping**: Annotations, Yaml, Xml, Php |
| 78 | + |
| 79 | +Example |
| 80 | +~~~~~~~ |
| 81 | + |
| 82 | +.. code-block:: php |
| 83 | +
|
| 84 | + // src/Foo/Bar.php |
| 85 | +
|
| 86 | + // ... |
| 87 | + class Bar |
| 88 | + { |
| 89 | + // ... |
| 90 | +
|
| 91 | + public function foo($bar) |
| 92 | + { |
| 93 | + // set foo with a value of bar |
| 94 | + $foo = ...; |
| 95 | +
|
| 96 | + // ... check if $bar has the correct value |
| 97 | +
|
| 98 | + return $foo->baz($bar, ...); |
| 99 | + } |
| 100 | + } |
| 101 | +
|
| 102 | +.. caution:: |
| 103 | + |
| 104 | + In Yaml you should put a space after ``{`` and before ``}`` (e.g. ``{ _controller: ... }``), |
| 105 | + but this should not be done in Twig (e.g. ``{'hello' : 'value'}``). |
| 106 | + |
| 107 | +.. _`the Sphinx documentation`: http://sphinx-doc.org/rest.html#source-code |
0 commit comments