This section gives some guidelines to help us to write consistent and good
quality documentation for CKAN.

Documentation isn’t source code, and documentation standards don’t need to be
followed as rigidly as coding standards do. In the end, some documentation is
better than no documentation, it can always be improved later. So the
guidelines below are soft rules.

Having said that, we suggest just one hard rule: no new feature (or change to
an existing feature) should be missing from the docs (but see todo).

A series of blog posts about writing technical docs, a lot of our
guidelines were based on this.

See also

The quickest and easiest way to contribute documentation to CKAN is to sign up
for a free GitHub account and simply edit the CKAN Wiki.
Docs started on the wiki can make it onto docs.ckan.org later.
If you do want to contribute to docs.ckan.org directly, follow the
instructions on this page.

Tip: Use the reStructuredText markup format when creating a wiki page,
since reStructuredText is the format that docs.ckan.org uses, this will make
moving the documentation from the wiki into docs.ckan.org later easier.

The source files for the docs are in the doc directory of the CKAN git repo.
The following sections will walk you through the process of making changes to
these source files, and submitting your work to the CKAN project.

Create a Python virtual environment
(virtualenv), activate it, install CKAN into the virtual environment, and
install the dependencies necessary for building CKAN. In this example we’ll
create a virtualenv in a folder called pyenv. Run these commands in a
terminal:

To make changes to the documentation, use a text editor to edit the .rst
files in doc/. Save your changes and then build the docs
again (pythonsetup.pybuild_sphinx) and open the HTML files in a web
browser to preview your changes.

It’s important that the docs have a clear, simple and extendable structure
(and that we keep it that way as we add to them), so that both readers
and writers can easily answer the questions:
If you need to find the docs for a particular feature, where do you look?
If you need to add a new page to the docs, where should it go?

As Overview explains, the documentation is organized into several guides,
each for a different audience: a user guide for web interface users, an
extending guide for extension developers, a contributing guide for core
contributors, etc. These guides are ordered with the simplest guides first,
and the most advanced last.

In the source, each one of these guides is a subdirectory with its own
index.rst containing its own ..toctree:: directive that lists all of
the other files in that subdirectory. The root toctree just lists each of these
*/index.rst files.

When adding a new page to the docs, the first question to ask yourself is: who
is this page for? That should tell you which subdirectory to put your page in.
You then need to add your page to that subdirectory’s index.rst file.

Within each guide, the docs are broken up by topic. For example, the extending
guide has a page for the writing extensions tutorial, a page about testing
extensions, a page for the plugins toolkit reference, etc. Again, the topics
are ordered with the simplest first and the most advanced last, and reference
pages generally at the very end.

The changelog is one page that doesn’t fit into any of
the guides, because it’s relevant to all of the different audiences and not
only to one particular guide. So the changelog is simply a top-level page
on its own. Hopefully we won’t need to add many more of these top-level
pages. If you’re thinking about adding a page that serves two or more audiences
at once, ask yourself whether you can break that up into separate pages and
put each into one of the guides, then link them together using seealso
boxes.

Within a particular page, for example a new page documenting a new feature, our
suggestion for what sections the page might have is:

Overview: a conceptual overview of or introduction to the feature.
Explain what the feature provides, why someone might want to use it,
and introduce any key concepts users need to understand.
This is the why of the feature.

Some of the guides have subdirectories within them. For example
Maintainer’s guide contains a subdirectory
Installing CKAN
that collects together the various pages about installing CKAN with its own
doc/maintaining/installing/index.rst file.

While subdirectories are useful, we recommend that you don’t put further
subdirectories inside the subdirectories, try to keep it to at most two
levels of subdirectories inside the doc directory. Keep it simple,
otherwise the structure becomes confusing, difficult to get an overview of and
difficult to navigate.

Keep in mind that Sphinx requires the docs to have a simple, linear ordering.
With HTML pages it’s possible to design structure where, for example, someone
reads half of a page, then clicks on a link in the middle of the page to go
and read another page, then goes back to the middle of the first page and
continues reading where they left off. While technically you can do this in
Sphinx as well, it isn’t a good idea, things like the navigation links, table
of contents, and PDF version will break, users will end up going in circles,
and the structure becomes confusing.

So the pages of our Sphinx docs need to have a simple linear ordering - one
page follows another, like in a book.

When you build the docs, Sphinx prints out warnings about any broken
cross-references, syntax errors, etc. We aim not to have any of these warnings,
so when adding to or editing the docs make sure your changes don’t introduce
any new ones.

It’s best to delete the build directory and completely rebuild the docs, to
check for any warnings:

Whenever mentioning another page or section in the docs, an external website, a
configuration setting, or a class, exception or function, etc. try to
cross-reference it. Using proper Sphinx cross-references is better than just
typing things like “see above/below” or “see section foo” because Sphinx
cross-refs are hyperlinked, and because if the thing you’re referencing to gets
moved or deleted Sphinx will update the cross-reference or print a warning.

Substitutions are a useful
way to define a value that’s needed in many places (eg. a command, the location
of a file, etc.) in one place and then reuse it many times.

You define the value once like this:

..|production.ini|replace::/etc/ckan/default/production.ini

and then reuse it like this:

Nowopenyour|production.ini|file.

|production.ini| will be replaced with the full value
/etc/ckan/default/production.ini.

Substitutions can also be useful for achieving consistent spelling and
capitalization of names like reStructuredText, PostgreSQL, Nginx, etc.

The rst_epilog setting in doc/conf.py contains a list of global
substitutions that can be used from any file.

Substitutions can’t immediately follow certain characters (with no space
in-between) or the substitution won’t work. If this is a problem, you can
insert an escaped space, the space won’t show up in the generated output and
the substitution will work:

pipinstall-e'git+\ |git_url|'

Similarly, certain characters are not allowed to immediately follow a
substitution (without a space) or the substitution won’t work. In this case you
can just escape the following characters, the escaped character will show up in
the output and the substitution will work:

We try to use autodoc to pull documentation from source code docstrings into
our Sphinx docs, wherever appropriate. This helps to avoid duplicating
documentation and also to keep the documentation closer to the code and
therefore more likely to be kept up to date.

Whenever you’re writing reference documentation for modules, classes, functions
or methods, exceptions, attributes, etc. you should probably be using autodoc.
For example, we use autodoc for the Action API reference, the
Plugin interfaces reference, etc.

No new feature (or change to an existing feature) should be missing from the
docs. It’s best to document new features or changes as you implement them,
but if you really need to merge something without docs then at least add a
todo directive to mark where docs
need to be added or updated (if it’s a new feature, make a new page or section
just to contain the todo):

Seealso boxes are particularly useful when two pages are related, but don’t
belong next to each other in the same section of the docs. For example, we have
docs about how to upgrade CKAN, these belong in the maintainer’s guide because
they’re for maintainers. We also have docs about how to do a new release, these
belong in the contributing guide because they’re for developers. But both
sections are about CKAN releases, so we link each to the other using seealso
boxes.

If you’re going to paste example code into the docs, or add a tutorial about
how to do something with code, then:

The code should be in standalone Python, HTML, JavaScript etc. files,
not pasted directly into the .rst files.
You then pull the code into your .rst file using a Sphinx
..literalinclude:: directive (see example below).

The code in the standalone files should be a complete working example,
with tests.
Note that not all of the code from the example needs to appear in the docs,
you can include just parts of it using ..literalinclude::, but the
example code needs to be complete so it can be tested.

This is so that we don’t end up with a lot of broken, outdated examples and
tutorials in the docs because breaking changes have been made to CKAN since the
docs were written. If your example code has tests, then when someone makes a
change in CKAN that breaks your example those tests will fail, and they’ll know
they have to fix their code or update your example.

..literalinclude:: ../../ckanext/example_iauthfunctions/plugin_v3.py
:start-after:# We have the logged-in user's user name, get their user id.:end-before:# Finally, we can test whether the user is a member of the curators group.

You may notice that ckanext/example_iauthfunctions
contains multiple versions of the same example plugin, plugin_v1.py,
plugin_v2.py, etc. This is because the tutorial walks the user through
first making a trivial plugin, and then adding more and more advanced features
one by one. Each step of the tutorial needs to have its own complete,
standalone example plugin with its own tests.

For more examples, look into the source files for other tutorials in the docs.

These should always be capitalized as shown above (including capital first
letters for Python and Nginx even when they’re not the first word in a
sentence). doc/conf.py defines substitutions for each of these so you
don’t have to remember them, see Substitutions.

Web site

Two words, with Web always capitalized

frontend

Not front-end

command line

Two words, not commandline or command-line
(this is because we want to be like Neal Stephenson)

CKAN config file or configuration file

Not settings file, ini file, etc. Also, the config file contains config
options such as ckan.site_id, and each config option is set to a
certain setting or value such as ckan.site_id=demo.ckan.org.

Use “we”, for example “We’ll publish a call for translations to the
ckan-dev and ckan-discuss mailing lists, announcing that the new
version is ready to be translated” instead of “A call for translations will
be published”.

Refer to the reader personally as “you”, as if you’re giving verbal
instructions to someone in the room: “First, you’ll need to do X. Then, when
you’ve done Y, you can start working on Z” (instead of stuff like
“First X must be done, and then Y must be done…”).