Refactor v2 config: separate schema from generator configuration#157
Merged
Refactor v2 config: separate schema from generator configuration#157
Conversation
Split the flat cookieplone.json v2 format into distinct `schema` and
`config` sections. Generator settings (extensions, no_render, versions,
subtemplates) now live under `config` instead of being mixed with form
fields in `properties`.
Key changes:
- Add `SubTemplate` TypedDict and JSON Schema validation in
`cookieplone/config/schemas.py`.
- `ParsedConfig` and `CookieploneState` use `list[SubTemplate]` for
typed subtemplate entries.
- `config.versions` is injected as a top-level context namespace
(`{{ versions.<key> }}`), alongside `cookiecutter`.
- New `process_subtemplates` utility renders Jinja2 `enabled`
expressions against the current context.
- `create_jinja_env` injects context into `env.globals` so Jinja2
expressions can resolve `cookiecutter.*` and `versions.*` variables.
- Documentation updated for schema-v2 reference and subtemplates concept.
Closes #156
Add sub-template vocabulary to Vale accept list and remove colon from heading to satisfy Microsoft.HeadingColons rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the
cookieplone.jsonv2 format to cleanly separate the form schema (user-facing questions) from generator configuration (extensions, no_render, versions, subtemplates).Key changes
SubTemplateTypedDict (cookieplone/config/schemas.py): typed structure for subtemplate entries withid,title, andenabledkeys, plus JSON Schema validation for the full v2 config format.config.versionsas top-level context namespace: version pinning values are now accessible via{{ versions.<key> }}(alongside{{ cookiecutter.<key> }}), injected intostate.dataat creation time.enabledfield: subtemplateenabledvalues can be static ("1"/"0") or Jinja2 expressions (e.g.{{ cookiecutter.has_frontend }}), rendered against the current context during generation.create_jinja_envfacade: wrapsStrictEnvironmentcreation and injects context intoenv.globalsso Jinja2 expressions can resolve template variables.process_subtemplatesutility: converts v2 subtemplate dicts into the[id, title, enabled]list format expected by post-generation hooks.Files changed (highlights)
cookieplone/config/schemas.py,cookieplone/utils/subtemplates.pycookieplone/config/state.py,cookieplone/config/v2.py,cookieplone/config/v1.pycookieplone/generator/main.pycookieplone/utils/cookiecutter.py,cookieplone/utils/config.pydocs/src/reference/schema-v2.md,docs/src/concepts/subtemplates.mdtests/config/test_schemas.py,tests/utils/test_subtemplates.py,tests/utils/test_cookiecutter.py, + updates to existing test filesTest plan
SubTemplateTypedDict and JSON Schema validationcreate_jinja_env(context injection, globals resolution)process_subtemplates(static values, Jinja2 expressions, empty lists)_generate_stateversions injection intostate.dataruffandruff-formatpass via pre-commit hooksCloses #156