Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ################################# |
| 2 | Writing CodeIgniter Documentation |
| 3 | ################################# |
| 4 | |
| 5 | CodeIgniter uses Sphinx to generate its documentation in a variety of formats, |
| 6 | using reStructuredText to handle the formatting. If you are familiar with |
| 7 | Markdown or Textile, you will quickly grasp reStructuredText. The focus is |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 8 | on readability and user friendliness. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 9 | While they can be quite technical, we always write for humans! |
| 10 | |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 11 | A local table of contents should always be included, like the one below. |
| 12 | It is created automatically by inserting the following: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 13 | |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 14 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 15 | |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 16 | .. contents:: |
| 17 | :local: |
| 18 | |
| 19 | .. raw:: html |
| 20 | |
Andrey Andreev | 7622ec6 | 2016-11-21 11:56:21 +0200 | [diff] [blame] | 21 | <div class="custom-index container"></div> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 22 | |
| 23 | .. contents:: |
| 24 | :local: |
| 25 | |
| 26 | .. raw:: html |
| 27 | |
| 28 | <div class="custom-index container"></div> |
| 29 | |
| 30 | The <div> that is inserted as raw HTML is a hook for the documentation's |
| 31 | JavaScript to dynamically add links to any function and method definitions |
| 32 | contained in the current page. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 33 | |
| 34 | ************** |
| 35 | Tools Required |
| 36 | ************** |
| 37 | |
| 38 | To see the rendered HTML, ePub, PDF, etc., you will need to install Sphinx |
| 39 | along with the PHP domain extension for Sphinx. The underlying requirement |
| 40 | is to have Python installed. Lastly, you will install the CI Lexer for |
| 41 | Pygments, so that code blocks can be properly highlighted. |
| 42 | |
| 43 | .. code-block:: bash |
| 44 | |
James L Parry | 60516ab | 2014-11-10 22:33:52 -0800 | [diff] [blame] | 45 | easy_install "sphinx==1.2.3" |
Andrey Andreev | 7622ec6 | 2016-11-21 11:56:21 +0200 | [diff] [blame] | 46 | easy_install "sphinxcontrib-phpdomain==0.1.3.post1" |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 47 | |
| 48 | Then follow the directions in the README file in the :samp:`cilexer` folder |
| 49 | inside the documentation repository to install the CI Lexer. |
| 50 | |
| 51 | |
| 52 | |
| 53 | ***************************************** |
| 54 | Page and Section Headings and Subheadings |
| 55 | ***************************************** |
| 56 | |
| 57 | Headings not only provide order and sections within a page, but they also |
| 58 | are used to automatically build both the page and document table of contents. |
| 59 | Headings are formed by using certain characters as underlines for a bit of |
| 60 | text. Major headings, like page titles and section headings also use |
| 61 | overlines. Other headings just use underlines, with the following hierarchy:: |
| 62 | |
| 63 | # with overline for page titles |
| 64 | * with overline for major sections |
| 65 | = for subsections |
| 66 | - for subsubsections |
| 67 | ^ for subsubsubsections |
| 68 | " for subsubsubsubsections (!) |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 69 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 70 | The :download:`TextMate ELDocs Bundle <./ELDocs.tmbundle.zip>` can help you |
| 71 | create these with the following tab triggers:: |
| 72 | |
| 73 | title-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 74 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 75 | ########## |
| 76 | Page Title |
| 77 | ########## |
| 78 | |
| 79 | sec-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 80 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 81 | ************* |
| 82 | Major Section |
| 83 | ************* |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 84 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 85 | sub-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 86 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 87 | Subsection |
| 88 | ========== |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 89 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 90 | sss-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 91 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 92 | SubSubSection |
| 93 | ------------- |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 94 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 95 | ssss-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 96 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 97 | SubSubSubSection |
| 98 | ^^^^^^^^^^^^^^^^ |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 99 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 100 | sssss-> |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 101 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 102 | SubSubSubSubSection (!) |
| 103 | """"""""""""""""""""""" |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | ******************** |
| 109 | Method Documentation |
| 110 | ******************** |
| 111 | |
| 112 | When documenting class methods for third party developers, Sphinx provides |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 113 | directives to assist and keep things simple. |
| 114 | For example, consider the following ReST: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 115 | |
| 116 | .. code-block:: rst |
| 117 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 118 | .. php:class:: Some_class |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 119 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 120 | .. php:method:: some_method ( $foo [, $bar [, $bat]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 121 | |
| 122 | This function will perform some action. The ``$bar`` array must contain |
| 123 | a something and something else, and along with ``$bat`` is an optional |
| 124 | parameter. |
| 125 | |
| 126 | :param int $foo: the foo id to do something in |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 127 | :param mixed $bar: A data array that must contain a something and something else |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 128 | :param bool $bat: whether or not to do something |
| 129 | :returns: FALSE on failure, TRUE if successful |
Andrey Andreev | 1e41136 | 2014-02-07 15:53:02 +0200 | [diff] [blame] | 130 | :rtype: bool |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 131 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 132 | :: |
| 133 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 134 | $this->load->library('some_class'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 135 | |
| 136 | $bar = array( |
| 137 | 'something' => 'Here is this parameter!', |
| 138 | 'something_else' => 42 |
| 139 | ); |
| 140 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 141 | $bat = $this->some_class->should_do_something(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 142 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 143 | if ($this->some_class->some_method(4, $bar, $bat) === FALSE) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 144 | { |
| 145 | show_error('An Error Occurred Doing Some Method'); |
| 146 | } |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 147 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 148 | .. note:: Here is something that you should be aware of when using some_method(). |
| 149 | For real. |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 150 | |
Andrey Andreev | 1e41136 | 2014-02-07 15:53:02 +0200 | [diff] [blame] | 151 | See also :meth:`Some_class::should_do_something` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 152 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 153 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 154 | .. php:method:: should_do_something() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 155 | |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 156 | :returns: Whether or not something should be done |
Andrey Andreev | 1e41136 | 2014-02-07 15:53:02 +0200 | [diff] [blame] | 157 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 158 | |
| 159 | |
| 160 | It creates the following display: |
| 161 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 162 | .. php:class:: Some_class |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 163 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 164 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 165 | .. php:method:: some_method ( $foo [, $bar [, $bat]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 166 | |
| 167 | This function will perform some action. The ``$bar`` array must contain |
| 168 | a something and something else, and along with ``$bat`` is an optional |
| 169 | parameter. |
| 170 | |
| 171 | :param int $foo: the foo id to do something in |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 172 | :param mixed $bar: A data array that must contain a something and something else |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 173 | :param bool $bat: whether or not to do something |
| 174 | :returns: FALSE on failure, TRUE if successful |
Andrey Andreev | 1e41136 | 2014-02-07 15:53:02 +0200 | [diff] [blame] | 175 | :rtype: bool |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 176 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 177 | :: |
| 178 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 179 | $this->load->library('some_class'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 180 | |
| 181 | $bar = array( |
| 182 | 'something' => 'Here is this parameter!', |
| 183 | 'something_else' => 42 |
| 184 | ); |
| 185 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 186 | $bat = $this->some_class->should_do_something(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 187 | |
purwandi | 6f18598 | 2011-10-07 09:21:30 +0700 | [diff] [blame] | 188 | if ($this->some_class->some_method(4, $bar, $bat) === FALSE) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 189 | { |
| 190 | show_error('An Error Occurred Doing Some Method'); |
| 191 | } |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 192 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 193 | .. note:: Here is something that you should be aware of when using some_method(). |
| 194 | For real. |
Derek Jones | 220358a | 2013-07-21 13:34:09 -0700 | [diff] [blame] | 195 | |
Andrey Andreev | 1e41136 | 2014-02-07 15:53:02 +0200 | [diff] [blame] | 196 | See also :meth:`Some_class::should_do_something` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 197 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 198 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 199 | .. php:method:: should_do_something() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 200 | |
James L Parry | 8a474f8 | 2014-11-25 08:58:48 -0800 | [diff] [blame] | 201 | :returns: Whether or not something should be done |
Andrey Andreev | 7622ec6 | 2016-11-21 11:56:21 +0200 | [diff] [blame] | 202 | :rtype: bool |