コード例 #1
0
def test_simple_doc_with_raw_texts():
    doc = Doc()
    with doc.tag("doc"):
        doc.cdata("the cdata string\nwith\nbroken\nlines")

        with doc.tag("body", id="the_id", klass="A"):
            doc.asis("<h2>\n  some <b>raw</b> html\n</h2>")
            doc.text("that's it")
    assert str(doc) == """\
コード例 #2
0
    def test_classes_handling(self):
        doc = Doc()

        with doc.tag("main", klass="bad_class primary light"):
            with doc.tag("div", id="c", klass="inside", style="B"):
                with doc.tag('p', klass="paragraph"):
                    doc.text("some")
                    doc.text("text")
                    doc.discard_class("paragraph")
                doc.toggle_class("option")

            doc.add_class("secondary")
            doc.discard_class("bad_class")
            doc.toggle_class("light")

        assert str(doc) == """\
コード例 #3
0
def test_simple_doc():
    doc = Doc()
    doc.asis('<!doctype html>\n')
    with doc.tag("html"):
        doc.comment("HERE COMMES THE HEAD!")
        with doc.tag("head"):
            doc.line("style", '#that {\ncss: style;\ndefinition: 1px;\n}')

        doc.nl()
        doc.comment("HERE COMMES THE BODY!")
        with doc.tag("body", "optional", id="the_id", klass="A"):
            with doc.tag("p", klass="B"):
                doc.text("that text")
            with doc.tag("div", id="content"):
                with doc.tag("ul", ("id", "di"), klass="Cc",
                             style="the_style"):
                    doc.comment("AND THE LIST!")
                    for k in range(2):
                        doc.line("li", "that %s" % k, style="u")
                doc.text("that's it")

    assert str(doc) == """\
コード例 #4
0
 def test_discarding(self):
     doc = Doc()
     with doc.tag("one", klass="B  A C"):
         doc.discard_class("B N D")
     assert str(doc) == "<one class='A C'></one>"
コード例 #5
0
 def test_toggling(self):
     doc = Doc()
     with doc.tag("one", klass="B A C"):
         doc.text("text")
         doc.toggle_class("B B D")
     assert str(doc) == "<one class='A C D'>text</one>"