Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.81k stars 801 forks source link

[Docs] Automate docs generation for BINDINGS et al #1705

Open rodrigogiraoserrao opened 1 year ago

rodrigogiraoserrao commented 1 year ago

A widget's BINDINGS and COMPONENT_CLASSES have tables that are partially generated by tools/widget_documentation.py but that must be kept updated by hand.

Investigate whether we can make a mkdocs/mkdocstrings plugin that inspects attributes like BINDINGS and COMPONENT_CLASSES to build their tables on the fly.

What about DEFAULT_CSS? Can we document their values (e.g., by setting the docstring to match the string value itself)?

willmcgugan commented 1 year ago

Default css is not a bad idea. Could be very useful in docs.

rodrigogiraoserrao commented 1 year ago

Default css is not a bad idea. Could be very useful in docs.

Yup. That was more of a rhetoric question so that I wouldn't forget about it. The default css should definitely be documented but the only obvious alternative I know of would make the full string appear inlined with the attribute in the header... Which is not what we want.

With the plugin we could inject it into the docstring and surrounded by backticks to style it as Textual CSS.

rodrigogiraoserrao commented 1 year ago

For widgets, can we collect all the attributes that are reactive and list them in a separate table? E.g., to include them in the reference pages.

merriam commented 4 months ago

OK, so I wrote a hack with tree_sitter and can parse out CSS_DEFAULTS from Python, then parse it as a CSS language.

Now what?

Consider this rule:

     DataTable {
        background: $surface ;
        color: $text;
        height: auto;
        max-height: 100%;
    }

Outside of DEFAULT_CSS, what else should get parsed?

merriam commented 3 months ago

Just as an FYI. I'm still playing with this:

If anyone wishes, I can post the code so far (tools/widget_walk.py and tools/test_widget_walk*).