Skip to content

Writing the Docs

How a page on this site is put together, so a change to the docs reads like the pages around it. Every rule here is one the site already keeps, and Grids is the example throughout.

Diagram: the parts of a guide page, as the Grids page has them. 1, the title, Grids, names the topic in a few words. 2, the summary says what the page lets you do, in one or two sentences. 3, the minimal example, the Board view, is complete and runnable, with a numbered note on a line that needs one. 4, the drawing shows that example running: Kael clicks the middle cell and it turns blue with a cross. 5, the sections, A Board of Buttons, A Board Drawn in Text, and Size Limits, go from the common case to the rare, and the rarest sit in a collapsed note, Less common cases. 6, Related links to the homes of topics the page mentions.

The Shape of a Page

A guide page has six parts, in this order:

  1. A title naming the topic in a few words: "Grids", "Who Can Click".
  2. A summary of a few sentences saying what the page lets the reader do.
  3. The minimal example: complete, runnable as shown, and in its V2 form.
  4. A drawing of the page's main idea. When it shows the example running, the example comes first, as on Grids. Some pages open their first section with both instead.
  5. Sections, from the common case to the rare. The cases most readers never meet go in a collapsed note at the end of their section, usually titled "Less common cases".
  6. Related: a short list of links, three or four on most pages, to the homes of topics the page mentions.

A guide page runs to about 400 lines and a section to about 150. A section that outgrows that is usually a page of its own. A section's index page introduces it and lists its pages, and a reference page has a form of its own, under Reference Entries.

Drawings

Pages carry a drawing for each mechanism they explain: an animation when order or timing is the point, a still when the point is a shape or a comparison. You do not need to make one. If your change explains something new, say in the pull request what the drawing should show and which section it belongs under, and it will be drawn to match the rest of the site.

A list of options, an error message, or a convention gets no drawing, since a picture would only repeat the sentence. Each drawing's alt text says what it shows, in the order it happens, so a reader who cannot see it misses nothing. A page's images may total 2 MB. Past that, the build fails and names the page.

Voice

Pages Voice Sounds like
Learn, How-to Speaks to the reader, in steps "Ask someone else to click."
Guide Describes what the library does, with "you" where it helps "pop() does not hand back the view you left."
Reference Third person, present tense, short "Returns True when the submission was accepted and the callback ran, False when a validator refused it."

On every page, keep sentences short and give each paragraph one idea, in four sentences at most. Three or more parallel items make a list. Quotes are straight, and a long dash has no place: a colon, a comma, parentheses, or a new sentence does that job. Plain words beat grand ones ("use", not "utilize").

One Word per Idea

Word Means Not
CascadeUI the project's name in text, headings included cascadeUI, which is the lettering in the logo and banners, or cascadeui, the import name
view the Python object: StatefulLayoutView and the classes built on it panel, menu, UI
panel what people see in Discord: the message and its controls view
message Discord's message object, where the difference matters
screen one view in a navigation stack: "the settings screen" page, which is a paginator's
click what a person does to a button press, tap
pick choosing an option in a select select, as a verb
submit sending a modal
interaction Discord's event object, or the platform rule a click
acknowledge answering an interaction within 3 seconds (defer() is the method) ack
close ending a view: exit(), a timeout, a deletion kill, destroy

Headings are in Title Case and name the topic: "Closing a View", with exit() in the text below it. When the topic is one call, the call follows a colon: "Slow Work: safe_defer()". A name from code keeps its own spelling, as in "Coming from discord.py", and so does a message a heading quotes.

Give a heading a short id, and keep the id when the heading is renamed, so links to it still land:

### Two-Click Controls in Your Own Code { #two-press-controls }

One page explains each topic, and every other page that needs it says one sentence and links there. On the Home, Learn, Guide, How-to, and Example Cogs pages, the first mention of a public name links to its reference entry, unless the word names something else there, such as another function's argument or a DevTools command. A reference page links a name only where an entry's text needs another entry, and the Code Map, whose rows name the library's files, links none.

Code Examples

  • An example runs as shown, or marks what it leaves out with # .... A block needs no mark for what the reader already has: names an earlier block on the page defined, the objects its surrounding code hands it (self, interaction, ctx, bot, a member), and the bot's own data and functions, such as db or save_profile(). A top-level await stands for code inside a command. Every name the library or discord.py supplies is imported in the first block on the page that uses it.
  • Imports come from cascadeui, never from a subpackage or the module a name happens to live in. The test helpers are the one exception: they come from cascadeui.testing, which the package root leaves out. The Stability Policy says which names are public.
  • A name already used for the same thing is used again: CounterView for a counter, SettingsView for settings, bot, interaction. A reader moving between pages meets the same example.
  • A note on one line goes in a numbered annotation, # (1)!, with the note in a list under the block, in place of a paragraph after it. Grids' cell() line has one.
  • A number carries its unit and matches Discord Limits: "3 seconds", "40 components".
  • The V2 form comes first. Where V1 differs, a "V1 and V2" section near the end says how, or a content tab sits beside the example.

Callouts and Collapsed Notes

Two kinds of callout, at most three on a page: note for context worth knowing, and warning for something that breaks if it is ignored. Less common cases go in a collapsed note at the end of their section, each case opening with its name in bold:

??? note "Less common cases"
    **No space between cells.** `cell_sep` is what goes between cells, a space unless you give another.

Reference Entries

Each public name has one entry. Its heading is the signature with a short id. Then come one to three sentences on what it does with a link to the guide page that explains it, a bullet for each parameter, what it returns, and what it raises.

How the behavior works belongs on the guide page. refresh() is a typical entry.

Checking a Change

Run each example you add against the library before opening the pull request. Then preview the site and build it strictly, with the commands in Building the Docs: the strict build fails on a link to a page or heading that does not exist.