Merged
Conversation
- Add ABC hierarchy: ExtraContext, ParsingPhaseExtraContext,
ParsedPhaseExtraContext, ResolvingPhaseExtraContext, GlobalExtraContext
- Add @extra_context decorator for registering custom extra context
- Template now has extra field to declare required context
- Templates use load('name') to access extra context
- Registry integration via REGISTRY.source
- Update documentation and examples
BREAKING CHANGE: Extra context access changed from {{ _name }} to
{% set _name = load('name') %}; context names no longer prefixed with '_'
- Remove REGISTRY.source property (decorators handle registration) - Remove ExtraContextRegistry, ExtraContextGenerator, ExtraContext from __all__ - Change on_anytime to take env instead of app - Simplify ExtraContextGenerator by extracting _generate method - Fix 'Source' -> 'Extra Context' naming in comments and docs
When template requests an extra context that is not registered or has wrong phase type, _generate now reports an error instead of silently skipping. Co-Authored-By: MiMo v2 Pro <mimo@xiaomi.com>
Co-Authored-By: MiMo v2 Pro <mimo@xiaomi.com>
- ExtraContext is now a type alias instead of ABC - Each phase class is its own ABC - ExtraContextGenerator validates requested contexts in __init__ - Uses todo set to track and generate only requested contexts Co-Authored-By: MiMo v2 Pro <mimo@xiaomi.com>
Test custom extra context registration with @extra_context decorator, load() function in templates, and Template.extra field. Co-Authored-By: MiMo v2 Pro <mimo@xiaomi.com>
Co-Authored-By: MiMo v2 Pro <mimo@xiaomi.com>
a04c547 to
be8d8d4
Compare
ac6c687 to
ba64f28
Compare
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
重构 extra context 系统,提供更扩展的 API:
ExtraContext、ParsingPhaseExtraContext、ParsedPhaseExtraContext、ResolvingPhaseExtraContext、GlobalExtraContext@extra_context装饰器用于注册自定义 extra contextTemplate新增extra字段声明需要的 contextload('name')显式加载 extra contextBreaking Changes
Extra context 访问方式变更:
{{ _doc.title }}{% set _doc = load('doc') %}{{ _doc.title }}Context 名称不再以
_前缀存储。