-
Notifications
You must be signed in to change notification settings - Fork 6
Transformer Proof-of-Concept #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Transformer Proof-of-Concept #101
Conversation
…s in structure template interpolations.
…marker for this during parsing instead of having this weird component return API.
|
Minor point, related to component result types and my String assertions are certainly easiest, until the moment it gets even a bit structural. Node assertions have proven really convenient, with the added benefit that they are accessibility-focused. |
|
@pauleveritt Just to clarify, can the "node"ifying occur at the "very end" or does it have to occur at every level? It seems that you could just wrap the highest level template under test and convert that to nodes. Besides giving hints to tooling with For example something like this: def Heading(children: Template) -> Template:
return t'<h2>{children}</h2>'
def Section(title: str) -> Template:
return t'<section><{Heading}>{title}</{Heading}></section>'
def Body(sections: list[SectionDO]) -> Template:
return t'<body>{[t"<{Section} title={section.title} />" for section in sections]}</body>'
# Just makes a tree of Templates into Nodes but do it all at once:
node = html(Body(sections=[SectionDO(title="News"), SectionDO(title="Sports")]))
assert isinstance(node, Element)
# The optimized for making strings version.
html_str = html_to_str(Body(sections=[SectionDO(title="News"), SectionDO(title="Sports")]))def Heading(children: Node) -> Node:
return html(t'<h2>{children}</h2>')
def Section(title: str) -> Node:
return html(t'<section><{Heading}>{title}</{Heading}></section>')
def Body(sections: list[SectionDO]) -> Node:
return html(t'<body>{[t"<{Section} title={section.title} />" for section in sections]}</body>')
node = html(Body(sections=[SectionDO(title="News"), SectionDO(title="Sports")]))
assert isinstance(node, Element) |
|
@ianjosephwilson That certainly would work for test-writing but it would eliminate other uses of But I'm also interested in interoperability. For example, I have a decorator that lets an |
b7bfe25 to
6455889
Compare
Proof of concept for discussion, needs tests and more refactoring.
TNodetree into a newTemplateafter parsing to determine the structure.Templatedirectly tostrwithoutNodeusing iterative solution.tdom's rendering of descendents by returning adict[str, object]in a 2-tupletdomto set context vars for descendent components to access by returning(Template, {'context_values': ((CTX_VAR, 'value-to-set'),)})kwargscan be provided to participating components (beyond justchildren).def Component(sys_context, children) -> TemplateSome of this we might be able to back-port into
tdom'sNoderenderer.