Skip to content

docs(generate): add developer guide for optional features support (post-3.0.16) #778

@derks

Description

@derks

Summary

Add a developer-facing guide for the new optional-features support in
cement.ext.ext_generate (landed in PR #768, target release 3.0.16) to
the GitBook developer docs at https://docs.builtoncement.com. Sphinx is
API-reference only — narrative usage docs live in GitBook.

Defer until after 3.0.16 cut

Holding this until the 3.0.16 release is cut so the docs land against
released behavior. Avoids documenting an interface that could still
shift between now and the release tag.

Where the feature lives

  • Implementation: cement/ext/ext_generate.py_process_features()
    on GenerateTemplateAbstractBase
  • Demo: demo/generate-features/ (working webapp template + README)
  • Tests: tests/ext/test_ext_generate.py (test6–test15 fixtures cover
    enabled/disabled, transitive requires, out-of-order requires,
    unknown/missing config, null blocks)
  • Changelog: `3.0.15 - DEVELOPMENT` → Bugs + Features

What the doc should cover

  1. Mental model — features as Y/N toggles with enabled /
    disabled side-effect blocks plus optional requires.
  2. `.generate.yml` schema reference — one table for the
    feature-root keys (`name`, `default`, `requires`, `enabled`,
    `disabled`) and one for the block keys (`variables`, `exclude`,
    `ignore`).
  3. CLI invocation — `--defaults` vs interactive vs `--clone`,
    plus `--force`. Note that interactive prompts are now lazy:
    prerequisites resolved before dependents are prompted; declining a
    prerequisite skips the dependent prompt entirely.
  4. Reading feature state in templates — `features.` is
    exposed in the Jinja2 context; gate content with
    `{% if features.docker %} ... {% endif %}`. Variables injected by
    an enabled block are top-level template vars.
  5. Worked example — point at `demo/generate-features/`; show the
    three expected output trees from its README.
  6. Authoring checklist — base variables → optional-feature
    bucketing → `disabled.ignore` for files to skip → `enabled.variables`
    for extra prompts → `requires` for dependencies → `{% if %}` for
    gated rendered content → test both `--defaults` and an interactive
    decline.
  7. Pitfalls — `exclude` vs `ignore` semantics, regex anchoring
    (`'.Dockerfile.'` not `'Dockerfile'`), explicit YAML `null`
    coalesces to `[]` (no crash), cyclic `requires` will
    `RecursionError`, `requires` only references other feature
    names (not arbitrary variables).
  8. Validation behavior — missing `name` and unknown `requires`
    raise `ValueError` (so the validation survives `python -O`).

Suggested GitBook location

Under the existing `generate` extension page on docs.builtoncement.com,
likely as a new subsection ("Optional Features") after the existing
variable-prompt content.

Acceptance

  • GitBook page published and linked from the generate-extension
    parent page
  • Worked example in the doc verified against the shipped 3.0.16
    artifact (run `pip install cement==3.0.16 && pdm run python
    myapp.py generate webapp /tmp/out --defaults` and confirm output
    matches docs)
  • Cross-link from CHANGELOG `3.0.16` Features entry to the
    GitBook page once published
  • Linked from PR feat(ext.generate): add optional features support for templates #768 description as the canonical follow-up doc
    pointer

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions