[py-svn] r35476 - in py/dist/py/apigen: . rest rest/testing

guido at codespeak.net guido at codespeak.net
Fri Dec 8 14:02:01 CET 2006


Author: guido
Date: Fri Dec  8 14:02:00 2006
New Revision: 35476

Added:
   py/dist/py/apigen/rest/testing/test_htmlhandlers.py
Modified:
   py/dist/py/apigen/apigen.js
   py/dist/py/apigen/rest/htmlhandlers.py
   py/dist/py/apigen/style.css
Log:
Removed #<url> hack (mostly, if possible I want to add something similar, but
less intrusive, later), fixed breadcrumbs by generating them from the filename
(on the server) instead of adding bits on navigation.


Modified: py/dist/py/apigen/apigen.js
==============================================================================
--- py/dist/py/apigen/apigen.js	(original)
+++ py/dist/py/apigen/apigen.js	Fri Dec  8 14:02:00 2006
@@ -1,42 +1,3 @@
-var anchors = [];
-function set_breadcrumb(el) {
-    var breadcrumb = document.getElementById('breadcrumb');
-    var href = el.href;
-    if (href.indexOf('module_') > -1) {
-        anchors = [];
-    };
-    for (var i=0; i < anchors.length; i++) {
-        if (anchors[i].href == href) {
-            anchors = anchors.slice(0, i);
-        };
-    };
-    var clone = el.cloneNode(true);
-    if (anchors.length && clone.childNodes[0].nodeValue.indexOf('.') > -1) {
-        var chunks = clone.childNodes[0].nodeValue.split('.');
-        clone.childNodes[0].nodeValue = chunks[chunks.length - 1];
-    };
-    anchors.push(clone);
-    while (breadcrumb.hasChildNodes()) {
-        breadcrumb.removeChild(breadcrumb.childNodes[0]);
-    };
-    for (var i=0; i < anchors.length; i++) {
-        breadcrumb.appendChild(anchors[i]);
-        if (i < anchors.length - 1) {
-            breadcrumb.appendChild(document.createTextNode('.'));
-        };
-    };
-};
-
-function set_location(el) {
-    var currloc = document.location.toString();
-    var url = currloc;
-    if (currloc.indexOf('#') > -1) {
-        var chunks = currloc.split('#');
-        url = chunks[0];
-    };
-    document.location = url + '#' + escape(el.getAttribute('href'));
-};
-
 function loadloc() {
     /* load iframe content using # part of the url */
     var loc = document.location.toString();

Modified: py/dist/py/apigen/rest/htmlhandlers.py
==============================================================================
--- py/dist/py/apigen/rest/htmlhandlers.py	(original)
+++ py/dist/py/apigen/rest/htmlhandlers.py	Fri Dec  8 14:02:00 2006
@@ -1,19 +1,60 @@
 from py.__.rest.transform import HTMLHandler, entitize
-from py.xml import html
+from py.xml import html, raw
 
 class PageHandler(HTMLHandler):
     def startDocument(self):
-        self.title = 'api reference'
         super(PageHandler, self).startDocument()
         self.head.append(html.link(type='text/css', rel='stylesheet',
                                    href='style.css'))
+        title = self.title[0]
+        breadcrumb = ''.join([unicode(el) for el in self.breadcrumb(title)])
+        self.body.append(html.div(raw(breadcrumb), class_='breadcrumb'))
 
     def handleLink(self, text, target):
         self.tagstack[-1].append(html.a(text, href=target,
-                                        onclick=('parent.set_breadcrumb(this);'
-                                                 'parent.set_location(this);'),
                                         target='content'))
 
+    def breadcrumb(self, title):
+        if title != 'index':
+            type, path = title.split('_', 1)
+            path = path.split('.')
+            module = None
+            cls = None
+            func = None
+            meth = None
+            if type == 'module':
+                module = '.'.join(path)
+            elif type == 'class':
+                module = '.'.join(path[:-1])
+                cls = path[-1]
+            elif type  == 'method':
+                module = '.'.join(path[:-2])
+                cls = path[-2]
+                meth = path[-1]
+            else:
+                module = '.'.join(path[:-1])
+                func = path[-1]
+            if module:
+                yield html.a(module, href='module_%s.html' % (module,))
+                if type != 'module':
+                    yield u'.'
+            if cls:
+                s = cls
+                if module:
+                    s = '%s.%s' % (module, cls)
+                yield html.a(cls, href='class_%s.html' % (s,))
+                if type != 'class':
+                    yield u'.'
+            if meth:
+                s = '%s.%s' % (cls, meth)
+                if module:
+                    s = '%s.%s.%s' % (module, cls, meth)
+                yield html.a(meth, href='method_%s.html' % (s,))
+            if func:
+                s = func
+                if module:
+                    s = '%s.%s' % (module, func)
+                yield html.a(func, href='function_%s.html' % (s,))
 
 class IndexHandler(PageHandler):
     ignore_text = False
@@ -21,9 +62,6 @@
     def startDocument(self):
         super(IndexHandler, self).startDocument()
         self.head.append(html.script(type='text/javascript', src='apigen.js'))
-        self.body.attr.onload = ('set_breadcrumb('
-                                    'document.getElementsByTagName("a")[0]);'
-                                    'loadloc();')
         self._push(html.div(id='sidebar'))
 
     def endDocument(self):
@@ -44,8 +82,3 @@
             return
         super(IndexHandler, self).handleText(text)
 
-    def handleLink(self, text, target):
-        self.tagstack[-1].append(html.a(text, href=target,
-                                        onclick='set_breadcrumb(this)',
-                                        target='content'))
-

Added: py/dist/py/apigen/rest/testing/test_htmlhandlers.py
==============================================================================
--- (empty file)
+++ py/dist/py/apigen/rest/testing/test_htmlhandlers.py	Fri Dec  8 14:02:00 2006
@@ -0,0 +1,41 @@
+import py
+from py.__.apigen.rest.htmlhandlers import PageHandler
+
+def test_breadcrumb():
+    h = PageHandler()
+    for fname, expected in [
+            ('module_py', '<a href="module_py.html">py</a>'),
+            ('module_py.test',
+                '<a href="module_py.test.html">py.test</a>'),
+            ('class_py.test',
+                ('<a href="module_py.html">py</a>.'
+                 '<a href="class_py.test.html">test</a>')),
+            ('class_py.test.foo',
+                ('<a href="module_py.test.html">py.test</a>.'
+                 '<a href="class_py.test.foo.html">foo</a>')),
+            ('class_py.test.foo.bar',
+                ('<a href="module_py.test.foo.html">py.test.foo</a>.'
+                 '<a href="class_py.test.foo.bar.html">bar</a>')),
+            ('function_foo', '<a href="function_foo.html">foo</a>'),
+            ('function_foo.bar',
+                ('<a href="module_foo.html">foo</a>.'
+                 '<a href="function_foo.bar.html">bar</a>')),
+            ('function_foo.bar.baz',
+                ('<a href="module_foo.bar.html">foo.bar</a>.'
+                 '<a href="function_foo.bar.baz.html">baz</a>')),
+            ('method_foo.bar',
+                ('<a href="class_foo.html">foo</a>.'
+                 '<a href="method_foo.bar.html">bar</a>')),
+            ('method_foo.bar.baz',
+                ('<a href="module_foo.html">foo</a>.'
+                 '<a href="class_foo.bar.html">bar</a>.'
+                 '<a href="method_foo.bar.baz.html">baz</a>')),
+            ('method_foo.bar.baz.qux',
+                ('<a href="module_foo.bar.html">foo.bar</a>.'
+                 '<a href="class_foo.bar.baz.html">baz</a>.'
+                 '<a href="method_foo.bar.baz.qux.html">qux</a>')),
+            ]:
+        html = ''.join([unicode(el) for el in h.breadcrumb(fname)])
+        print fname
+        print html
+        assert html == expected

Modified: py/dist/py/apigen/style.css
==============================================================================
--- py/dist/py/apigen/style.css	(original)
+++ py/dist/py/apigen/style.css	Fri Dec  8 14:02:00 2006
@@ -2,7 +2,7 @@
   width: 9em;
   float: left;
   vertical-align: top;
-  margin-top: 0px;
+  margin-top: 0.5em;
 }
 
 #main {
@@ -17,6 +17,7 @@
 
 #breadcrumb {
   height: 5%;
+  display: none;
 }
 
 body, div, p, h1, h2, h3, h4 {
@@ -31,11 +32,11 @@
 }
 
 ul {
-  padding-left: 2em;
+  padding-left: 0em;
   margin-top: 0px;
 }
 
 ul li {
-  list-style-type: katakana;
+  list-style-type: none;
 }
 



More information about the pytest-commit mailing list