def munge(document, template, linkrel, d, fullpath, ext, url, config): # FIXME: This has *way* to much duplicated crap in common with tree.munge #fixRelativeLinks(template, linkrel) removeH1(document) fixAPI(document, url) fontifyPython(document) addPyListings(document, d) addHTMLListings(document, d) #fixLinks(document, ext) #putInToC(template, generateToC(document)) template = template.cloneNode(1) # Insert the slides into the template slides = [] pos = 0 for title, slide in splitIntoSlides(document): t = template.cloneNode(1) text = dom.Text() text.data = title setTitle(t, [text]) tmplbody = domhelpers.findElementsWithAttribute(t, "class", "body")[0] tmplbody.childNodes = slide tmplbody.setAttribute("class", "content") # FIXME: Next/Prev links # FIXME: Perhaps there should be a "Template" class? (setTitle/setBody # could be methods...) slides.append(HTMLSlide(t, title, pos)) pos += 1 insertPrevNextLinks(slides, os.path.splitext(os.path.basename(fullpath)), ext) return slides
def test_fixAPI(self): """ The element passed to L{tree.fixAPI} has all of its children with the I{API} class rewritten to contain links to the API which is referred to by the text they contain. """ parent = dom.Element('div') link = dom.Element('span') link.setAttribute('class', 'API') text = dom.Text() text.data = 'foo' link.appendChild(text) parent.appendChild(link) tree.fixAPI(parent, 'http://example.com/%s') self.assertEqual( parent.toxml(), '<div><span class="API">' '<a href="http://example.com/foo" title="foo">foo</a>' '</span></div>')
def test_fixAPI(self): """ The element passed to L{tree.fixAPI} has all of its children with the I{API} class rewritten to contain links to the API which is referred to by the text they contain. """ parent = dom.Element("div") link = dom.Element("span") link.setAttribute("class", "API") text = dom.Text() text.data = "foo" link.appendChild(text) parent.appendChild(link) tree.fixAPI(parent, "http://example.com/%s") self.assertEqual( parent.toxml(), '<div><span class="API">' '<a href="http://example.com/foo" title="foo">foo</a>' "</span></div>", )
def test_fixAPIBase(self): """ If a node with the I{API} class and a value for the I{base} attribute is included in the DOM passed to L{tree.fixAPI}, the link added to that node refers to the API formed by joining the value of the I{base} attribute to the text contents of the node. """ parent = dom.Element('div') link = dom.Element('span') link.setAttribute('class', 'API') link.setAttribute('base', 'bar') text = dom.Text() text.data = 'baz' link.appendChild(text) parent.appendChild(link) tree.fixAPI(parent, 'http://example.com/%s') self.assertEqual( parent.toxml(), '<div><span class="API">' '<a href="http://example.com/bar.baz" title="bar.baz">baz</a>' '</span></div>')
def test_fixAPIBase(self): """ If a node with the I{API} class and a value for the I{base} attribute is included in the DOM passed to L{tree.fixAPI}, the link added to that node refers to the API formed by joining the value of the I{base} attribute to the text contents of the node. """ parent = dom.Element("div") link = dom.Element("span") link.setAttribute("class", "API") link.setAttribute("base", "bar") text = dom.Text() text.data = "baz" link.appendChild(text) parent.appendChild(link) tree.fixAPI(parent, "http://example.com/%s") self.assertEqual( parent.toxml(), '<div><span class="API">' '<a href="http://example.com/bar.baz" title="bar.baz">baz</a>' "</span></div>", )