class Heading: person: str name: Annotated[str, Context(), Attr('name')] greeting: Annotated[str, Get(Settings), Attr('greeting')] def __call__(self): return html('''<h1>{self.greeting} {self.person}, {self.name}</h1>''')
def target( customer_name: Annotated[ str, Context(), Attr('name'), ], ): return customer_name
def test_context(regular_container): pipeline = (Context(), ) result = process_pipeline( regular_container, pipeline, start=View, ) assert result == regular_container.context
class View: customer_name: Annotated[str, Context(), Attr('name'), ] @property def name(self): return f'Hello {self.customer_name}'
class FrenchView: customer_name: Annotated[str, Context(), Attr('name'), ] @property def name(self): return f'Bonjour {self.customer_name}'
class Greeting: name: Annotated[str, Context(), Attr('name')] def __call__(self): return html('<h1>Hello {self.name}</h1>')
class SecondHeading: person: str name: Annotated[str, Context(), Attr('name')] greeting: Annotated[str, Get(Settings), Attr('greeting')]
class Target: customer_name: Annotated[str, Context(), Attr('name'), ] def __call__(self): return self.customer_name
class FrenchGreeting: name: Annotated[str, Context(), Attr('name')] def __call__(self): return html('<h1>Bonjour {self.name}</h1>')
class DummyView(View): context_title: Annotated[DummyContext, Context(), Attr('title')] resource_title: Annotated[DummyContext, Get(Resource, attr='title')] def __call__(self) -> VDOM: return html('<div>Hello {self.context_title} from {self.resource_title}</div>')
class Heading: title: Annotated[ str, Context(), Attr('name'), ]
class Heading: customer: Annotated[ Customer, Context(), ]
class ContextView: name: Annotated[str, Context(), Attr('name')] def __call__(self) -> str: return html('<div>Hello Customer</div>')