Interpolation Resolution #106
ianjosephwilson
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Along the same lines of the attribute resolution I was trying to document how the interpolations are resolved. This is what I have so far. This reduces some of the API surface area in certain situations but allows us to start thinking about what is actually permitted in each case. Whereas before it seemed that we tried to do everything in every case and it was really hard to reason about IMO.
Adding Text/Elements
Interpolation in element (has parent tag) or bare (no parent tag)
t'''<div>{t"Hello and {'good day to you'}"} World</div>'''str-- processed with an escape function that isMarkupawareNone-- ignored (essentially the same as"")Template-- processed recursively, should inherit normal text contextIterable-- processed recursively, must consist of values of these same "kinds"str.HasHTMLDunderwill be detected by the escaping function and pass through unescaped.t'<title>{"Hello"} World</title>'t'<script>var x = {15};</script>'t'<!-- Example {3} -->'__html__is allowed to bypass escaping.str-- processed in"".join()(escaped as sum of parts, method depends on parent)HasHTMLDunder-- allowed for exact matches otherwise an exception is raisedNone-- ignored (essentially the same as"")Template-- an exception is raisedIterable-- an exception is raised"".join()afterstr()is appliedex_t = t'Hello {"World"}'t'<div>{ex_t}</div>'t'<script>{ex_t}</script>'raises exceptiont'The greeting is {ex_t}'raises exceptionInvoking Components
Interpolation as tag, can be in an "startend" / self-closing tag or in a pair of "start"/"end" tags.
t'<{value}>...'t'<{value} />'Callable[..., Template]- executed as component function,Templateshould adhere to "Normal Text" rules.Callable[..., Callable[[], Template]]-- created with first call, then result is called to createTemplate,Templateshould adhere to "Normal Text" rules.childrenkw arg that will be filled by whateverTemplatecontent was between its tags.t"".childrenkw arg is defined and there are no**kwargsdefined then no children will be passed to the callable even if the children do exist in the originalTemplate.t'...</{value}>'Callable-- must be identical to start tag's valueDefining Attributes (For Elements or Components)
Interpolation as attribute name, value or part of value.
We mostly ironed this out already and it seems to be working okay waiting on more real-world usage.
t'<div title={value}></div>'object-- merged into pool of attributes unless special handling applies, see belowt'<div title="Mr. {value}"></div>'str()before applying"".join()and finally escaping.t'<div {value}></div>'dict[str, object]-- key/value pairs from.items()are merged into pool of attributes unless special handling applies, see belowNone-- ignored, no attributes are mergedNone | False-- attribute will be omittedTrue-- attribute will be a bare attributestr()-- escaped value will be used for attribute's valueclassclassattribute AND/ORclassis used in any kind of attribute interpolation.classes: dict[str, bool]class_value = " ".join(f"{key}" for key, value in classes.items() if value) or Nonestylestyleattribute AND/ORstyleis used in any kind of attribute interpolation.styles: dict[str, str|None]style_value = "; ".join([f"{pn}: {pv}" for pn, pv in styles.items() if pv is not None]) or Noneariadict[str, str|bool|None|object]str-- as-isbool-- transformed to"true"forTrueand"false"forFalseNone-- as-isstr()None-- ignored, no attributes expanded into pooldatadict[str, str|bool|None]str | bool | None-- as-isstr()None-- ignored, no attributes expanded into poolBeta Was this translation helpful? Give feedback.
All reactions