[DOC-23]Initial structure and Documentation Guide
[doc.git] / docs / how-to-use-docs / include-documentation.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2
3 .. _include-documentation:
4
5 ============================
6 Including your Documentation
7 ============================
8
9 .. contents::
10    :depth: 3
11    :local:
12
13 In your project repository
14 --------------------------
15
16 Add your documentation to your repository in the folder structure and
17 using templates as described above. The documentation templates 
18 are available in `doc/docs/templates/`, you should
19 copy the relevant templates to your <repo>/docs/ directory in your repository.
20 For instance if you want to document release-notes, then your steps shall be
21 as follows:
22
23 .. code-block:: bash
24
25    git clone ssh://<your_id>@gerrit.onap.org:29418/doc
26    cp -p doc/docs/templates/release-notes <your_repo>/docs/release-notes/
27
28
29 You should then add the relevant information to the template that will
30 explain the documentation. When you are done writing, you can commit
31 the documentation to the your project repository.
32
33 .. code-block:: bash
34
35    git add .
36    git commit --signoff --all
37    git review
38
39 In the ONAP doc Repository
40 --------------------------
41
42 To import project documents from project repositories, we use git submodules.
43 Each ONAP project providing documentation, other than the doc project, is loaded under  `doc/docs/submodules/` 
44 when needed for validating or publishing documentation.   To describe the relationship between content files
45 we use the `Sphinx toctree directive`.
46
47 The following diagram illustrates:
48   - all ONAP gerrit project repositories,
49   - the doc project repository including a main index.rst,
50   - other master document directories and/or RST files that may be created to organize sections and documents,
51   - the submodules directory where other repositories and directories/files may be referenced,
52   - the templates directory with one example, a release-notes template, and
53   - another project repository `appc` that provides documentation source by copying and filling in an instance of the release-notes template.
54
55
56 .. graphviz::
57
58    
59    digraph docstructure {
60    size="8,12";
61    node [fontname = "helvetica"];
62    // Align gerrit repos and docs directories
63    {rank=same doc aaf aai appc repoelipse vnfsdk vvp}
64    {rank=same releasenotestemplate localappcdocs }
65
66    //Show submodule linkage to docs directory
67    submodules -> localappcdocs [style=dotted];
68
69    //Illustrate Gerrit Repos and provide URL/Link for complete repo list
70    gerrit [label="gerrit.onap.org/r", href="https://gerrit.onap.org/r/#/admin/projects/" ];
71    gerrit -> doc;
72    gerrit -> aaf;
73    gerrit -> aai;
74    gerrit -> appc;
75    gerrit -> repoelipse;                                   repoelipse [label=". . . ."];
76    gerrit -> vnfsdk;
77    gerrit -> vvp;
78
79    //Show example of local appc instance release notes
80    appc -> localappcdocs;                               localappcdocs [label="docs"];
81    localappcdocs -> releasenotesinstance; releasenotesinstance        [label="release-notes"];
82    releasenotesinstance -> relnoteindexinstance; relnoteindexinstance [label="index.rst", shape=box];
83    releasenotesinstance -> relnoteotherinstance; relnoteotherinstance [label="... other sections", shape=box];
84
85    //Show detail structure of a portion of doc/docs _images _static _templates multiple master documents omitted
86    doc  -> docs;
87    docs -> confpy;                                             confpy [label="conf.py",shape=box];
88    docs -> toplevelindex;                               toplevelindex [label="index.rst", shape=box];
89    docs -> release;
90    docs -> rsttemplates;                                 rsttemplates [label="templates"];
91    docs -> indexdirelipse;                             indexdirelipse [label="...other\ndocuments"];
92    docs -> submodules
93
94    //Example Release notes document
95    release -> releasenotes;                              releasenotes [label="release-notes"];
96    releasenotes -> lowerlevelindex;                   lowerlevelindex [label="index.rst", shape=box];
97
98    //Example release-notes template
99    rsttemplates -> releasenotestemplate;         releasenotestemplate [label="release-notes"];
100    releasenotestemplate -> relnoteindex;                 relnoteindex [label="index.rst", shape=box];
101    releasenotestemplate -> relnoteother;                 relnoteother [label="... other sections", shape=box];
102    }
103
104 In the toctree
105 ++++++++++++++
106
107 To include your project specific documentation in the composite documentation,
108 first identify where your project documentation should be included.
109 Say your project provides release-notes and should be referenced in the `doc/docs/release/release-notes/index.rst toctree`, then:
110
111 .. code-block:: bash
112
113    git clone ssh://<your_id>@gerrit.onap.org:29418/doc
114    vim doc/docs/release/release-notes/index.rst
115
116 This opens the text editor. Identify where you want to add your release notes.
117 If your release notes are to be added to the toctree, simply include the path to
118 it, example:
119
120
121 .. code-block:: bash
122
123    .. toctree::
124       :maxdepth: 1
125
126       ../../submodules/<your_repo>/docs/release-notes/index
127
128 When finished, you can request a commit to the doc project repository.
129 Be sure to add the project leader of the docs project as a reviewr of the change you just pushed in gerrit.
130
131 .. code-block:: bash
132    
133    git add .
134    git commit --signoff --all
135    git review
136
137
138 As a Hyperlink
139 ++++++++++++++
140
141 It's pretty common to want to reference another location in the
142 ONAP documentation and it's pretty easy to do with
143 reStructuredText. This is a quick primer, more information is in the
144 `Sphinx section on Cross-referencing arbitrary locations
145 <http://www.sphinx-doc.org/en/stable/markup/inline.html#ref-role>`_.
146
147 Within a single document, you can reference another section simply by::
148
149    This is a reference to `The title of a section`_
150
151 Assuming that somewhere else in the same file there a is a section
152 title something like::
153
154    The title of a section
155    ^^^^^^^^^^^^^^^^^^^^^^
156
157 It's typically better to use ``:ref:`` syntax and labels to provide
158 links as they work across files and are resilient to sections being
159 renamed. First, you need to create a label something like::
160
161    .. _a-label:
162
163    The title of a section
164    ^^^^^^^^^^^^^^^^^^^^^^
165
166 .. note:: The underscore (_) before the label is required.
167
168 Then you can reference the section anywhere by simply doing::
169
170     This is a reference to :ref:`a-label`
171
172 or::
173
174     This is a reference to :ref:`a section I really liked <a-label>`
175
176 .. note:: When using ``:ref:``-style links, you don't need a trailing
177           underscore (_).
178
179 Because the labels have to be unique, it usually makes sense to prefix
180 the labels with the project name to help share the label space, e.g.,
181 ``sfc-user-guide`` instead of just ``user-guide``.
182
183
184 'doc8' Validation
185 -----------------
186 It is recommended that all rst content is validated by `doc8 <https://pypi.python.org/pypi/doc8>`_ standards.
187 To validate your rst files using doc8, install doc8.
188
189 .. code-block:: bash
190
191    sudo pip install doc8
192
193 doc8 can now be used to check the rst files. Execute as,
194
195 .. code-block:: bash
196
197    doc8 --ignore D000,D001 <file>
198
199
200 Testing: Build Documentation Locally
201 ------------------------------------
202
203 Composite DOC documentation
204 +++++++++++++++++++++++++++++++++
205 To build the whole documentation under doc/, follow these steps:
206
207 Install virtual environment.
208
209 .. code-block:: bash
210
211    sudo pip install virtualenv
212    cd /local/repo/path/to/project
213
214 Download the DOC repository.
215
216 .. code-block:: bash
217
218    git clone http://gerrit.onap.org/r/doc
219
220 Change directory to docs & install requirements.
221
222 .. code-block:: bash
223
224    cd doc
225    sudo pip install -r etc/requirements.txt
226
227 Update submodules, build documentation using tox & then open using any browser.
228
229 .. code-block:: bash
230
231    cd doc
232    git submodule update --init
233    tox -edocs
234    firefox docs/_build/html/index.html
235
236 .. note:: Make sure to run `tox -edocs` and not just `tox`.
237
238 Individual project documentation
239 ++++++++++++++++++++++++++++++++
240 To test how the documentation renders in HTML, follow these steps:
241
242 Install virtual environment.
243
244 .. code-block:: bash
245
246    sudo pip install virtualenv
247    cd /local/repo/path/to/project
248
249 Download the doc repository.
250
251 .. code-block:: bash
252
253    git clone http://gerrit.onap.org/r/doc
254
255 Change directory to doc & install requirements.
256
257 .. code-block:: bash
258
259    cd doc
260    sudo pip install -r etc/requirements.txt
261
262 Move the conf.py file to your project folder where RST files have been kept:
263
264 .. code-block:: bash
265
266    mv doc/docs/conf.py <path-to-your-folder>/
267
268 Move the static files to your project folder:
269
270 .. code-block:: bash
271
272    mv docs/_static/ <path-to-your-folder>/
273
274 Build the documentation from within your project folder:
275
276 .. code-block:: bash
277
278    sphinx-build -b html <path-to-your-folder> <path-to-output-folder>
279
280 Your documentation shall be built as HTML inside the
281 specified output folder directory.
282
283 .. note:: Be sure to remove the `conf.py`, the static/ files and the output folder from the `<project>/docs/`. This is for testing only. Only commit the rst files and related content.
284
285
286 Adding your project repository as a submodule
287 ---------------------------------------------
288
289 Clone the doc repository and add your submodule using the commands below and where $reponame is your repository name.
290
291 .. code-block:: bash
292
293   cd docs/submodules/
294   git submodule git https://gerrit.onap.org/r/$reponame
295   git submodule init $reponame/
296   git submodule update $reponame/
297   git add .
298   git review