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