Example #1
0
def nevowify(filename, linkrel, ext, url, templ, options=None, outfileGenerator=tree.getOutputFileName):
    if options is None:
        options = {}
    pclass = options['pageclass']
    pclass = reflect.namedObject(pclass)
    page = pclass(docFactory=loaders.htmlfile(filename))
    s = page.renderString()
    s = ____wait(s)

    newFilename = outfileGenerator(filename, ext)

    if options.has_key('nolore'):
        f = open(newFilename, 'w')
        f.write(s)
        f.close()
        return

    doc = parseStringAndReport(s)
    clonedNode = templ.cloneNode(1)
    tree.munge(doc, clonedNode, linkrel, os.path.dirname(filename), filename, ext,
               url, options, outfileGenerator)
    tree.makeSureDirectoryExists(newFilename)
    f = open(newFilename, 'wb')
    clonedNode.writexml(f)
    f.close()
Example #2
0
def nevowify(filename,
             linkrel,
             ext,
             url,
             templ,
             options=None,
             outfileGenerator=tree.getOutputFileName):
    if options is None:
        options = {}
    pclass = options['pageclass']
    pclass = reflect.namedObject(pclass)
    page = pclass(docFactory=loaders.htmlfile(filename))
    s = page.renderString()
    s = ____wait(s)

    newFilename = outfileGenerator(filename, ext)

    if options.has_key('nolore'):
        open(newFilename, 'w').write(s)
        return

    doc = parseStringAndReport(s)
    clonedNode = templ.cloneNode(1)
    tree.munge(doc, clonedNode, linkrel, os.path.dirname(filename), filename,
               ext, url, options, outfileGenerator)
    tree.makeSureDirectoryExists(newFilename)
    clonedNode.writexml(open(newFilename, 'wb'))
Example #3
0
 def test_munge(self):
     indexer.setIndexFilename("lore_index_file.html")
     doc = microdom.parse(open(self.file))
     templ = microdom.parse(open(d['template']))
     node = templ.cloneNode(1)
     tree.munge(doc, node, self.linkrel, os.path.dirname(self.file),
                self.file, d['ext'], d['baseurl'], d)
     self.assertEqualsFile('good_internal.xhtml', node.toprettyxml())
 def test_munge(self):
     indexer.setIndexFilename("lore_index_file.html")
     doc = microdom.parse(open(self.file))
     templ = microdom.parse(open(d['template']))
     node = templ.cloneNode(1)
     tree.munge(doc, node, self.linkrel,
                os.path.dirname(self.file),
                self.file,
                d['ext'], d['baseurl'], d)
     self.assertEqualsFile('good_internal.xhtml', node.toprettyxml())
Example #5
0
    def test_mungeAuthors(self):
        """
        If there is a node with a I{class} attribute set to C{"authors"},
        L{tree.munge} adds anchors as children to it, takeing the necessary
        information from any I{link} nodes in the I{head} with their I{rel}
        attribute set to C{"author"}.
        """
        document = dom.parseString(
            """\
<html>
  <head>
    <title>munge authors</title>
    <link rel="author" title="foo" href="bar"/>
    <link rel="author" title="baz" href="quux"/>
    <link rel="author" title="foobar" href="barbaz"/>
  </head>
  <body>
    <h1>munge authors</h1>
  </body>
</html>"""
        )
        template = dom.parseString(
            """\
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <title />
  </head>

  <body>
    <div class="body" />
    <div class="authors" />
  </body>
</html>
"""
        )
        tree.munge(document, template, self.linkrel, os.path.dirname(self.file), self.file, d["ext"], d["baseurl"], d)

        self.assertXMLEqual(
            template.toxml(),
            """\
<?xml version="1.0" ?><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>munge authors</title>
  <link href="bar" rel="author" title="foo"/><link href="quux" rel="author" title="baz"/><link href="barbaz" rel="author" title="foobar"/></head>

  <body>
    <div class="content">
    <span/>
  </div>
    <div class="authors"><span><a href="bar">foo</a>, <a href="quux">baz</a>, and <a href="barbaz">foobar</a></span></div>
  </body>
</html>""",
        )
Example #6
0
    def test_mungeAuthors(self):
        """
        If there is a node with a I{class} attribute set to C{"authors"},
        L{tree.munge} adds anchors as children to it, takeing the necessary
        information from any I{link} nodes in the I{head} with their I{rel}
        attribute set to C{"author"}.
        """
        document = dom.parseString(
            """\
<html>
  <head>
    <title>munge authors</title>
    <link rel="author" title="foo" href="bar"/>
    <link rel="author" title="baz" href="quux"/>
    <link rel="author" title="foobar" href="barbaz"/>
  </head>
  <body>
    <h1>munge authors</h1>
  </body>
</html>""")
        template = dom.parseString(
            """\
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <title />
  </head>

  <body>
    <div class="body" />
    <div class="authors" />
  </body>
</html>
""")
        tree.munge(
            document, template, self.linkrel, os.path.dirname(self.file),
            self.file, d['ext'], d['baseurl'], d)

        self.assertXMLEqual(
            template.toxml(),
            """\
<?xml version="1.0" ?><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>munge authors</title>
  <link href="bar" rel="author" title="foo"/><link href="quux" rel="author" title="baz"/><link href="barbaz" rel="author" title="foobar"/></head>

  <body>
    <div class="content">
    <span/>
  </div>
    <div class="authors"><span><a href="bar">foo</a>, <a href="quux">baz</a>, and <a href="barbaz">foobar</a></span></div>
  </body>
</html>""")
Example #7
0
    def test_munge(self):
        indexer.setIndexFilename("lore_index_file.html")
        doc = dom.parse(open(self.file))
        node = dom.parse(open(d['template']))
        tree.munge(doc, node, self.linkrel, os.path.dirname(self.file),
                   self.file, d['ext'], d['baseurl'], d)

        self.assertXMLEqual(
            """\
<?xml version="1.0" ?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head><title>Twisted Documentation: My Test Lore Input</title></head>
  <body bgcolor="white">
    <h1 class="title">My Test Lore Input</h1>
    <div class="content">
<span/>
<p>A Body.</p>
</div>
    <a href="lore_index_file.html">Index</a>
  </body>
</html>""", node.toxml())
Example #8
0
    def test_munge(self):
        indexer.setIndexFilename("lore_index_file.html")
        doc = dom.parse(open(self.file))
        node = dom.parse(open(d["template"]))
        tree.munge(doc, node, self.linkrel, os.path.dirname(self.file), self.file, d["ext"], d["baseurl"], d)

        self.assertXMLEqual(
            """\
<?xml version="1.0" ?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head><title>Twisted Documentation: My Test Lore Input</title></head>
  <body bgcolor="white">
    <h1 class="title">My Test Lore Input</h1>
    <div class="content">
<span/>
<p>A Body.</p>
</div>
    <a href="lore_index_file.html">Index</a>
  </body>
</html>""",
            node.toxml(),
        )