blob: aaac33ecbb4cd521b05ca743dc07fe2a076c832b [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#################################
2Writing CodeIgniter Documentation
3#################################
4
5CodeIgniter uses Sphinx to generate its documentation in a variety of formats,
6using reStructuredText to handle the formatting. If you are familiar with
7Markdown or Textile, you will quickly grasp reStructuredText. The focus is
James L Parry8a474f82014-11-25 08:58:48 -08008on readability and user friendliness.
Derek Jones8ede1a22011-10-05 13:34:52 -05009While they can be quite technical, we always write for humans!
10
James L Parry8a474f82014-11-25 08:58:48 -080011A local table of contents should always be included, like the one below.
12It is created automatically by inserting the following:
Derek Jones8ede1a22011-10-05 13:34:52 -050013
Derek Jones220358a2013-07-21 13:34:09 -070014::
Derek Jones8ede1a22011-10-05 13:34:52 -050015
Derek Jones220358a2013-07-21 13:34:09 -070016 .. contents::
17 :local:
18
19 .. raw:: html
20
Andrey Andreev7622ec62016-11-21 11:56:21 +020021 <div class="custom-index container"></div>
Derek Jones220358a2013-07-21 13:34:09 -070022
23.. contents::
24 :local:
25
26.. raw:: html
27
28 <div class="custom-index container"></div>
29
30The <div> that is inserted as raw HTML is a hook for the documentation's
31JavaScript to dynamically add links to any function and method definitions
32contained in the current page.
Derek Jones8ede1a22011-10-05 13:34:52 -050033
34**************
35Tools Required
36**************
37
38To see the rendered HTML, ePub, PDF, etc., you will need to install Sphinx
39along with the PHP domain extension for Sphinx. The underlying requirement
40is to have Python installed. Lastly, you will install the CI Lexer for
41Pygments, so that code blocks can be properly highlighted.
42
43.. code-block:: bash
44
James L Parry60516ab2014-11-10 22:33:52 -080045 easy_install "sphinx==1.2.3"
Andrey Andreev7622ec62016-11-21 11:56:21 +020046 easy_install "sphinxcontrib-phpdomain==0.1.3.post1"
Derek Jones8ede1a22011-10-05 13:34:52 -050047
48Then follow the directions in the README file in the :samp:`cilexer` folder
49inside the documentation repository to install the CI Lexer.
50
51
52
53*****************************************
54Page and Section Headings and Subheadings
55*****************************************
56
57Headings not only provide order and sections within a page, but they also
58are used to automatically build both the page and document table of contents.
59Headings are formed by using certain characters as underlines for a bit of
60text. Major headings, like page titles and section headings also use
61overlines. 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 Jones220358a2013-07-21 13:34:09 -070069
Derek Jones8ede1a22011-10-05 13:34:52 -050070The :download:`TextMate ELDocs Bundle <./ELDocs.tmbundle.zip>` can help you
71create these with the following tab triggers::
72
73 title->
Derek Jones220358a2013-07-21 13:34:09 -070074
Derek Jones8ede1a22011-10-05 13:34:52 -050075 ##########
76 Page Title
77 ##########
78
79 sec->
Derek Jones220358a2013-07-21 13:34:09 -070080
Derek Jones8ede1a22011-10-05 13:34:52 -050081 *************
82 Major Section
83 *************
Derek Jones220358a2013-07-21 13:34:09 -070084
Derek Jones8ede1a22011-10-05 13:34:52 -050085 sub->
Derek Jones220358a2013-07-21 13:34:09 -070086
Derek Jones8ede1a22011-10-05 13:34:52 -050087 Subsection
88 ==========
Derek Jones220358a2013-07-21 13:34:09 -070089
Derek Jones8ede1a22011-10-05 13:34:52 -050090 sss->
Derek Jones220358a2013-07-21 13:34:09 -070091
Derek Jones8ede1a22011-10-05 13:34:52 -050092 SubSubSection
93 -------------
Derek Jones220358a2013-07-21 13:34:09 -070094
Derek Jones8ede1a22011-10-05 13:34:52 -050095 ssss->
Derek Jones220358a2013-07-21 13:34:09 -070096
Derek Jones8ede1a22011-10-05 13:34:52 -050097 SubSubSubSection
98 ^^^^^^^^^^^^^^^^
Derek Jones220358a2013-07-21 13:34:09 -070099
Derek Jones8ede1a22011-10-05 13:34:52 -0500100 sssss->
Derek Jones220358a2013-07-21 13:34:09 -0700101
Derek Jones8ede1a22011-10-05 13:34:52 -0500102 SubSubSubSubSection (!)
103 """""""""""""""""""""""
104
105
106
107
108********************
109Method Documentation
110********************
111
112When documenting class methods for third party developers, Sphinx provides
James L Parry8a474f82014-11-25 08:58:48 -0800113directives to assist and keep things simple.
114For example, consider the following ReST:
Derek Jones8ede1a22011-10-05 13:34:52 -0500115
116.. code-block:: rst
117
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200118 .. php:class:: Some_class
Derek Jones8ede1a22011-10-05 13:34:52 -0500119
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200120 .. php:method:: some_method ( $foo [, $bar [, $bat]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500121
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 Parry8a474f82014-11-25 08:58:48 -0800127 :param mixed $bar: A data array that must contain a something and something else
Derek Jones8ede1a22011-10-05 13:34:52 -0500128 :param bool $bat: whether or not to do something
129 :returns: FALSE on failure, TRUE if successful
Andrey Andreev1e411362014-02-07 15:53:02 +0200130 :rtype: bool
Derek Jones220358a2013-07-21 13:34:09 -0700131
Derek Jones8ede1a22011-10-05 13:34:52 -0500132 ::
133
purwandi6f185982011-10-07 09:21:30 +0700134 $this->load->library('some_class');
Derek Jones8ede1a22011-10-05 13:34:52 -0500135
136 $bar = array(
137 'something' => 'Here is this parameter!',
138 'something_else' => 42
139 );
140
purwandi6f185982011-10-07 09:21:30 +0700141 $bat = $this->some_class->should_do_something();
Derek Jones8ede1a22011-10-05 13:34:52 -0500142
purwandi6f185982011-10-07 09:21:30 +0700143 if ($this->some_class->some_method(4, $bar, $bat) === FALSE)
Derek Jones8ede1a22011-10-05 13:34:52 -0500144 {
145 show_error('An Error Occurred Doing Some Method');
146 }
Derek Jones220358a2013-07-21 13:34:09 -0700147
Derek Jones8ede1a22011-10-05 13:34:52 -0500148 .. note:: Here is something that you should be aware of when using some_method().
149 For real.
Derek Jones220358a2013-07-21 13:34:09 -0700150
Andrey Andreev1e411362014-02-07 15:53:02 +0200151 See also :meth:`Some_class::should_do_something`
Derek Jones8ede1a22011-10-05 13:34:52 -0500152
Derek Jones8ede1a22011-10-05 13:34:52 -0500153
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200154 .. php:method:: should_do_something()
Derek Jones8ede1a22011-10-05 13:34:52 -0500155
James L Parry8a474f82014-11-25 08:58:48 -0800156 :returns: Whether or not something should be done
Andrey Andreev1e411362014-02-07 15:53:02 +0200157 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500158
159
160It creates the following display:
161
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200162.. php:class:: Some_class
Derek Jones8ede1a22011-10-05 13:34:52 -0500163
Derek Jones8ede1a22011-10-05 13:34:52 -0500164
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200165 .. php:method:: some_method ( $foo [, $bar [, $bat]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500166
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 Parry8a474f82014-11-25 08:58:48 -0800172 :param mixed $bar: A data array that must contain a something and something else
Derek Jones8ede1a22011-10-05 13:34:52 -0500173 :param bool $bat: whether or not to do something
174 :returns: FALSE on failure, TRUE if successful
Andrey Andreev1e411362014-02-07 15:53:02 +0200175 :rtype: bool
Derek Jones220358a2013-07-21 13:34:09 -0700176
Derek Jones8ede1a22011-10-05 13:34:52 -0500177 ::
178
purwandi6f185982011-10-07 09:21:30 +0700179 $this->load->library('some_class');
Derek Jones8ede1a22011-10-05 13:34:52 -0500180
181 $bar = array(
182 'something' => 'Here is this parameter!',
183 'something_else' => 42
184 );
185
purwandi6f185982011-10-07 09:21:30 +0700186 $bat = $this->some_class->should_do_something();
Derek Jones8ede1a22011-10-05 13:34:52 -0500187
purwandi6f185982011-10-07 09:21:30 +0700188 if ($this->some_class->some_method(4, $bar, $bat) === FALSE)
Derek Jones8ede1a22011-10-05 13:34:52 -0500189 {
190 show_error('An Error Occurred Doing Some Method');
191 }
Derek Jones220358a2013-07-21 13:34:09 -0700192
Derek Jones8ede1a22011-10-05 13:34:52 -0500193 .. note:: Here is something that you should be aware of when using some_method().
194 For real.
Derek Jones220358a2013-07-21 13:34:09 -0700195
Andrey Andreev1e411362014-02-07 15:53:02 +0200196 See also :meth:`Some_class::should_do_something`
Derek Jones8ede1a22011-10-05 13:34:52 -0500197
Derek Jones8ede1a22011-10-05 13:34:52 -0500198
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200199 .. php:method:: should_do_something()
Derek Jones8ede1a22011-10-05 13:34:52 -0500200
James L Parry8a474f82014-11-25 08:58:48 -0800201 :returns: Whether or not something should be done
Andrey Andreev7622ec62016-11-21 11:56:21 +0200202 :rtype: bool