예제 #1
0
파일: tree.py 프로젝트: galaxysd/BitTorrent
def munge(document, template, linkrel, dir, fullpath, ext, url, config, outfileGenerator=getOutputFileName):
    fixRelativeLinks(template, linkrel)
    addMtime(template, fullpath)
    removeH1(document)
    if not config.get('noapi', False):
        fixAPI(document, url)
    fontifyPython(document)
    fixLinks(document, ext)
    addPyListings(document, dir)
    addHTMLListings(document, dir)
    addPlainListings(document, dir)
    putInToC(template, generateToC(document))
    footnotes(document)
    notes(document)

    setIndexLink(template, indexer.getIndexFilename())
    setVersion(template, config.get('version', ''))

    # Insert the document into the template
    chapterNumber = htmlbook.getNumber(fullpath)
    title = domhelpers.findNodesNamed(document, 'title')[0].childNodes
    setTitle(template, title, chapterNumber)
    if numberer.getNumberSections() and chapterNumber:
        numberDocument(document, chapterNumber)
    index(document, outfileGenerator(os.path.split(fullpath)[1], ext),
          htmlbook.getReference(fullpath))

    authors = domhelpers.findNodesNamed(document, 'link')
    authors = [(node.getAttribute('title',''), node.getAttribute('href', ''))
               for node in authors if node.getAttribute('rel', '') == 'author']
    setAuthors(template, authors)

    body = domhelpers.findNodesNamed(document, "body")[0]
    tmplbody = domhelpers.findElementsWithAttribute(template, "class",
                                                              "body")[0]
    tmplbody.childNodes = body.childNodes
    tmplbody.setAttribute("class", "content")
예제 #2
0
def munge(document, template, linkrel, dir, fullpath, ext, url, config, outfileGenerator=getOutputFileName):
    """
    Mutate C{template} until it resembles C{document}.

    @type document: A DOM Node or Document
    @param document: The input document which contains all of the content to be
    presented.

    @type template: A DOM Node or Document
    @param template: The template document which defines the desired
    presentation format of the content.

    @type linkrel: C{str}
    @param linkrel: An prefix to apply to all relative links in C{src} or
    C{href} attributes in the input document when generating the output
    document.

    @type dir: C{str}
    @param dir: The directory in which to search for source listing files.

    @type fullpath: C{str}
    @param fullpath: The file name which contained the input document.

    @type ext: C{str}
    @param ext: The extension to use when selecting an output file name.  This
    replaces the extension of the input file name.

    @type url: C{str}
    @param url: A string which will be interpolated with the fully qualified
    Python name of any API reference encountered in the input document, the
    result of which will be used as a link to API documentation for that name
    in the output document.

    @type config: C{dict}
    @param config: Further specification of the desired form of the output.
    Valid keys in this dictionary::

        noapi: If present and set to a True value, links to API documentation
               will not be generated.

        version: A string which will be included in the output to indicate the
                 version of this documentation.

    @type outfileGenerator: Callable of C{str}, C{str} returning C{str}
    @param outfileGenerator: Output filename factory.  This is invoked with the
    intput filename and C{ext} and the output document is serialized to the
    file with the name returned.

    @return: C{None}
    """
    fixRelativeLinks(template, linkrel)
    addMtime(template, fullpath)
    removeH1(document)
    if not config.get("noapi", False):
        fixAPI(document, url)
    fontifyPython(document)
    fixLinks(document, ext)
    addPyListings(document, dir)
    addHTMLListings(document, dir)
    addPlainListings(document, dir)
    putInToC(template, generateToC(document))
    footnotes(document)
    notes(document)

    setIndexLink(template, indexer.getIndexFilename())
    setVersion(template, config.get("version", ""))

    # Insert the document into the template
    chapterNumber = htmlbook.getNumber(fullpath)
    title = domhelpers.findNodesNamed(document, "title")[0].childNodes
    setTitle(template, title, chapterNumber)
    if numberer.getNumberSections() and chapterNumber:
        numberDocument(document, chapterNumber)
    index(document, outfileGenerator(os.path.split(fullpath)[1], ext), htmlbook.getReference(fullpath))

    authors = domhelpers.findNodesNamed(document, "link")
    authors = [
        (node.getAttribute("title", ""), node.getAttribute("href", ""))
        for node in authors
        if node.getAttribute("rel", "") == "author"
    ]
    setAuthors(template, authors)

    body = domhelpers.findNodesNamed(document, "body")[0]
    tmplbody = domhelpers.findElementsWithAttribute(template, "class", "body")[0]
    tmplbody.childNodes = body.childNodes
    tmplbody.setAttribute("class", "content")
예제 #3
0
def munge(document,
          template,
          linkrel,
          dir,
          fullpath,
          ext,
          url,
          config,
          outfileGenerator=getOutputFileName):
    """
    Mutate C{template} until it resembles C{document}.

    @type document: A DOM Node or Document
    @param document: The input document which contains all of the content to be
    presented.

    @type template: A DOM Node or Document
    @param template: The template document which defines the desired
    presentation format of the content.

    @type linkrel: C{str}
    @param linkrel: An prefix to apply to all relative links in C{src} or
    C{href} attributes in the input document when generating the output
    document.

    @type dir: C{str}
    @param dir: The directory in which to search for source listing files.

    @type fullpath: C{str}
    @param fullpath: The file name which contained the input document.

    @type ext: C{str}
    @param ext: The extension to use when selecting an output file name.  This
    replaces the extension of the input file name.

    @type url: C{str}
    @param url: A string which will be interpolated with the fully qualified
    Python name of any API reference encountered in the input document, the
    result of which will be used as a link to API documentation for that name
    in the output document.

    @type config: C{dict}
    @param config: Further specification of the desired form of the output.
    Valid keys in this dictionary::

        noapi: If present and set to a True value, links to API documentation
               will not be generated.

        version: A string which will be included in the output to indicate the
                 version of this documentation.

    @type outfileGenerator: Callable of C{str}, C{str} returning C{str}
    @param outfileGenerator: Output filename factory.  This is invoked with the
    intput filename and C{ext} and the output document is serialized to the
    file with the name returned.

    @return: C{None}
    """
    fixRelativeLinks(template, linkrel)
    addMtime(template, fullpath)
    removeH1(document)
    if not config.get('noapi', False):
        fixAPI(document, url)
    fontifyPython(document)
    fixLinks(document, ext)
    addPyListings(document, dir)
    addHTMLListings(document, dir)
    addPlainListings(document, dir)
    putInToC(template, generateToC(document))
    footnotes(document)
    notes(document)

    setIndexLink(template, indexer.getIndexFilename())
    setVersion(template, config.get('version', ''))

    # Insert the document into the template
    chapterNumber = htmlbook.getNumber(fullpath)
    title = domhelpers.findNodesNamed(document, 'title')[0].childNodes
    setTitle(template, title, chapterNumber)
    if numberer.getNumberSections() and chapterNumber:
        numberDocument(document, chapterNumber)
    index(document, outfileGenerator(os.path.split(fullpath)[1], ext),
          htmlbook.getReference(fullpath))

    authors = domhelpers.findNodesNamed(document, 'link')
    authors = [(node.getAttribute('title') or '', node.getAttribute('href')
                or '') for node in authors
               if node.getAttribute('rel') == 'author']
    setAuthors(template, authors)

    body = domhelpers.findNodesNamed(document, "body")[0]
    tmplbody = domhelpers.findElementsWithAttribute(template, "class",
                                                    "body")[0]
    tmplbody.childNodes = body.childNodes
    tmplbody.setAttribute("class", "content")