Esempio n. 1
0
def test_Template_multi_transform():
    class template(wiseguy.template.Template):
        element = wiseguy.html.jade('''
html
  head
    title
  body
   div''')
        transforms = [
            wiseguy.template.Transform(
                "head", lambda head, template: template.element.add(
                    "head title", "flibble")),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add(
                    "body div", wiseguy.html.Html("Wibble, %s" % body))),
            wiseguy.template.Transform(
                ("head", "body"),
                lambda head, body, template: template.element.add(
                    "body div", wiseguy.html.Html("%s, %s" % (head, body))))
        ]

    template.apply(dict(head="flamble"))
    assert template.keys() == set(["body"])

    html = template.render(body="flimble").strip()
    expected = """
<html>
<head><title>flibble</title></head>
<body><div>
<p>Wibble, flimble</p>
<p>flamble, flimble</p>
</div></body>
</html>""".strip()
    assert html == expected
Esempio n. 2
0
def test_Template_multiple_renderings():
    class template(wiseguy.template.Template):
        element = wiseguy.html.jade('''
html
  head
    title
  body
   div''')
        transforms = [
            wiseguy.template.Transform(
                "head", lambda head, template: template.element.add(
                    "head title", "flibble")),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add(
                    "body div", wiseguy.html.Html("Wibble, %s" % body))),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add(
                    "body div", wiseguy.html.Html("Wobble, %s" % body)))
        ]

    html = template.render(body="Foo").strip()
    assert template.keys() == set(["body", "head"])
    expected = """
<html>
<head><title></title></head>
<body><div>
<p>Wibble, Foo</p>
<p>Wobble, Foo</p>
</div></body>
</html>""".strip()
    assert html == expected

    html = template.render(body="Bar").strip()
    assert template.keys() == set(["body", "head"])
    expected = """
<html>
<head><title></title></head>
<body><div>
<p>Wibble, Bar</p>
<p>Wobble, Bar</p>
</div></body>
</html>""".strip()
    assert html == expected
Esempio n. 3
0
def test_Template_multiple_renderings():
    class template(wiseguy.template.Template):
        element = wiseguy.html.jade(
            """
html
  head
    title
  body
   div"""
        )
        transforms = [
            wiseguy.template.Transform("head", lambda head, template: template.element.add("head title", "flibble")),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add("body div", wiseguy.html.Html("Wibble, %s" % body))
            ),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add("body div", wiseguy.html.Html("Wobble, %s" % body))
            ),
        ]

    html = template.render(body="Foo").strip()
    assert template.keys() == set(["body", "head"])
    expected = """
<html>
<head><title></title></head>
<body><div>
<p>Wibble, Foo</p>
<p>Wobble, Foo</p>
</div></body>
</html>""".strip()
    assert html == expected

    html = template.render(body="Bar").strip()
    assert template.keys() == set(["body", "head"])
    expected = """
<html>
<head><title></title></head>
<body><div>
<p>Wibble, Bar</p>
<p>Wobble, Bar</p>
</div></body>
</html>""".strip()
    assert html == expected
Esempio n. 4
0
def test_Template_multi_transform():
    class template(wiseguy.template.Template):
        element = wiseguy.html.jade(
            """
html
  head
    title
  body
   div"""
        )
        transforms = [
            wiseguy.template.Transform("head", lambda head, template: template.element.add("head title", "flibble")),
            wiseguy.template.Transform(
                "body", lambda body, template: template.element.add("body div", wiseguy.html.Html("Wibble, %s" % body))
            ),
            wiseguy.template.Transform(
                ("head", "body"),
                lambda head, body, template: template.element.add(
                    "body div", wiseguy.html.Html("%s, %s" % (head, body))
                ),
            ),
        ]

    template.apply(dict(head="flamble"))
    assert template.keys() == set(["body"])

    html = template.render(body="flimble").strip()
    expected = """
<html>
<head><title>flibble</title></head>
<body><div>
<p>Wibble, flimble</p>
<p>flamble, flimble</p>
</div></body>
</html>""".strip()
    assert html == expected