Пример #1
0
def functional_component(children, header="Functional components!"):
    message = use_context("message")

    return html("""
        <h2>{header}</h2>
        <span>{message}</span>
        {children}
    """)
Пример #2
0
def test_wired_renderer_simplest_init_false(registry: InjectorRegistry):
    registry.register_injectable(Person, Person)
    container = registry.create_injectable_container()
    expected = '<div>Paul Everitt</div>'
    actual = render(
        html('<{Person} first_name="Paul" last_name="Everitt"/>'),
        container=container,
    )
    assert expected == actual
Пример #3
0
def test_wired_renderer_non_void(registry: InjectorRegistry):
    @dataclass
    class NonVoid:
        def __call__(self):
            return html('<i class="icon"></i>')

    registry.register_injectable(NonVoid, NonVoid)
    container = registry.create_injectable_container()
    expected = '<i class="icon"></i>'
    actual = render(html('<{NonVoid} />'), container=container)
    assert expected == actual
Пример #4
0
def test_render_context():
    def App():
        message = use_context("message")
        return html("<div>{message}<//><{functional_component}/>")

    vdom = html("""
  <{Context} message='c1'>
    <{App} />
  <//>
""")
    result = render(vdom)
    expected = '<div>c1</div><h2>Functional components!</h2><span>c1</span>'
    assert result == expected
def test_wired_renderer_second(registry: InjectorRegistry):
    container = registry.create_injectable_container(context=SecondContext())
    expected = '<h1>Hello World... Second Context</h1>'
    actual = render(html('''<{Heading} person="World"/>'''), container)
    assert expected == actual
 def __call__(self):
     return html(
         '''
     <h1>{self.greeting} {self.person}... {self.name}</h1>
     '''
     )
Пример #7
0
def test_render_safe_value():
    body = Markup('<span>Escape</span>')
    vdom = html('<div>{body}</div>')
    result = render(vdom)
    expected = '<div><span>Escape</span></div>'
    assert result == expected
Пример #8
0
def test_render_escaped_value():
    body = '<span>Escape</span>'
    vdom = html('<div>{body}</div>')
    result = render(vdom)
    expected = '<div>&lt;span&gt;Escape&lt;/span&gt;</div>'
    assert result == expected
Пример #9
0
 def App():
     message = use_context("message")
     return html("<div>{message}<//><{functional_component}/>")
Пример #10
0
 def __call__(self):
     return html('<i class="icon"></i>')
Пример #11
0
def test_wired_renderer_simplest_propoverride(registry: InjectorRegistry):
    registry.register_injectable(Heading, Heading)
    container = registry.create_injectable_container()
    expected = '<h1>Override</h1>'
    actual = render(html('<{Heading} name="Override"/>'), container=container)
    assert expected == actual
Пример #12
0
def test_wired_renderer_simplest_container(registry: InjectorRegistry):
    registry.register_injectable(Heading, Heading)
    container = registry.create_injectable_container()
    expected = '<h1>Hello</h1>'
    actual = render(html('''<{Heading}/>'''), container=container)
    assert expected == actual
Пример #13
0
 def __call__(self):
     full_name = ' '.join(self.full_name)  # noqa: F841
     return html('<div>{full_name}</div>')
Пример #14
0
 def __call__(self) -> VDOM:
     return html('''<h1>{self.name}</h1>''')