[py-svn] r36762 - in py/dist/py/apigen: . testing
hpk at codespeak.net
hpk at codespeak.net
Sun Jan 14 22:06:05 CET 2007
Author: hpk
Date: Sun Jan 14 22:06:04 2007
New Revision: 36762
Modified:
py/dist/py/apigen/htmlgen.py
py/dist/py/apigen/layout.py
py/dist/py/apigen/linker.py
py/dist/py/apigen/testing/test_apigen_example.py
py/dist/py/apigen/testing/test_apigen_functional.py
py/dist/py/apigen/testing/test_linker.py
Log:
produce relative links, and not use a "base" part in the html header
anymore.
Modified: py/dist/py/apigen/htmlgen.py
==============================================================================
--- py/dist/py/apigen/htmlgen.py (original)
+++ py/dist/py/apigen/htmlgen.py Sun Jan 14 22:06:04 2007
@@ -317,7 +317,8 @@
page = wrap_page(project, 'sources for %s' % (fspath.basename,),
tag, nav, outputbase)
outputpath.ensure()
- outputpath.write(page.unicode().encode("utf8"))
+ content = page.unicode() #linker.call_withbase(reltargetpath, page.unicode)
+ outputpath.write(content.encode("utf8"))
def prepare_class_api_pages(linker, dsa, base, classes_dotted_names):
passed = []
@@ -340,7 +341,7 @@
for dotted_name, tag, nav, reltargetpath in data:
page = wrap_page(project, 'api documentation for %s' % (dotted_name,),
tag, nav, outputbase)
- content = page.unicode()
+ content = linker.call_withbase(reltargetpath, page.unicode)
targetpath = outputbase.ensure(reltargetpath)
targetpath.write(content.encode("utf8"))
@@ -359,7 +360,7 @@
for dotted_name, tag, nav, reltargetpath in data:
page = wrap_page(project, 'api documentation for %s' % (dotted_name,),
tag, nav, outputbase)
- content = page.unicode()
+ content = linker.call_withbase(reltargetpath, page.unicode)
targetpath = outputbase.join(reltargetpath)
targetpath.ensure()
targetpath.write(content.encode("utf8"))
@@ -379,7 +380,7 @@
for dotted_name, tag, nav, reltargetpath in data:
page = wrap_page(project, 'api documentation for %s' % (dotted_name,),
tag, nav, outputbase)
- content = page.unicode()
+ content = linker.call_withbase(reltargetpath, page.unicode)
targetpath = outputbase.join(reltargetpath)
targetpath.ensure()
targetpath.write(content.encode("utf8"))
@@ -413,15 +414,14 @@
for dotted_name, tag, nav, reltargetpath in data:
page = wrap_page(project, 'index of namespace %s' % (dotted_name,),
tag, nav, outputbase)
- content = page.unicode()
+ content = linker.call_withbase(reltargetpath, page.unicode)
targetpath = outputbase.join(reltargetpath)
targetpath.ensure()
targetpath.write(content.encode("utf8"))
def wrap_page(project, title, contentel, navel, outputpath):
page = LayoutPage(project, title, nav=navel, encoding='UTF-8',
- stylesheeturl='style.css',
- base='file://%s/' % (outputpath.strpath))
+ stylesheeturl='style.css',)
page.set_content(contentel)
here = py.magic.autopath().dirpath()
style = here.join('style.css').read()
Modified: py/dist/py/apigen/layout.py
==============================================================================
--- py/dist/py/apigen/layout.py (original)
+++ py/dist/py/apigen/layout.py Sun Jan 14 22:06:04 2007
@@ -9,11 +9,8 @@
class LayoutPage(Page):
""" this provides the layout and style information """
- base = 'http://localhost/tmp/py_apigen_output/'
-
def __init__(self, *args, **kwargs):
self.nav = kwargs.pop('nav')
- self.base = kwargs.pop('base', self.base)
super(LayoutPage, self).__init__(*args, **kwargs)
def set_content(self, contentel):
@@ -23,6 +20,4 @@
super(LayoutPage, self).fill()
self.menubar[:] = []
self.menubar.append(self.nav)
- if self.base:
- self.head.insert(0, py.xml.html.base(href=self.base))
Modified: py/dist/py/apigen/linker.py
==============================================================================
--- py/dist/py/apigen/linker.py (original)
+++ py/dist/py/apigen/linker.py Sun Jan 14 22:06:04 2007
@@ -14,6 +14,8 @@
return unicode(self._linker.get_target(self._linkid))
class Linker(object):
+ fromlocation = None
+
def __init__(self):
self._linkid2target = {}
@@ -25,11 +27,18 @@
self._linkid2target[linkid] = target
def get_target(self, linkid):
- return self._linkid2target[linkid]
-
- def get_target_relative(self, linkid, fromlocation):
- ref = self.get_target(linkid)
- return relpath(fromlocation, ref)
+ linktarget = self._linkid2target[linkid]
+ if self.fromlocation is not None:
+ linktarget = relpath(self.fromlocation, linktarget)
+ return linktarget
+
+ def call_withbase(self, base, func, *args, **kwargs):
+ assert self.fromlocation is None
+ self.fromlocation = base
+ try:
+ return func(*args, **kwargs)
+ finally:
+ del self.fromlocation
def relpath(p1, p2, sep='/', back='..'):
if (p1.startswith(sep) ^ p2.startswith(sep)):
Modified: py/dist/py/apigen/testing/test_apigen_example.py
==============================================================================
--- py/dist/py/apigen/testing/test_apigen_example.py (original)
+++ py/dist/py/apigen/testing/test_apigen_example.py Sun Jan 14 22:06:04 2007
@@ -130,7 +130,7 @@
assert clsfile.check()
html = clsfile.read()
assert html.find(
- 'href="api/pkg.SomeClass.__init__.html">__init__') > -1
+ 'href="pkg.SomeClass.__init__.html">__init__') > -1
_checkhtml(html)
def test_build_class_api_pages_base_link(self):
@@ -147,7 +147,7 @@
clsfile = base.join('api/pkg.SomeSubClass.html')
assert clsfile.check()
html = clsfile.read()
- assert html.find('href="api/pkg.SomeClass.html">pkg.SomeClass') > -1
+ assert html.find('href="pkg.SomeClass.html">pkg.SomeClass') > -1
_checkhtml(html)
def test_build_source_pages(self):
@@ -170,7 +170,7 @@
build_method_api_pages(self.linker, methodsdata, self.project, base)
build_source_pages(self.linker, sourcedata, self.project, base)
funchtml = base.join('api/pkg.SomeClass.html').read()
- assert funchtml.find('href="source/pkg/someclass.py.html"') > -1
+ assert funchtml.find('href="../source/pkg/someclass.py.html"') > -1
_checkhtml(funchtml)
def test_create_namespace_tree(self):
Modified: py/dist/py/apigen/testing/test_apigen_functional.py
==============================================================================
--- py/dist/py/apigen/testing/test_apigen_functional.py (original)
+++ py/dist/py/apigen/testing/test_apigen_functional.py Sun Jan 14 22:06:04 2007
@@ -23,15 +23,15 @@
someclass_api = apidir.join('pkg.SomeClass.html')
assert someclass_api.check(file=True)
assert someclass_api.read().find(
- '<a href="api/pkg.SomeClass.html">SomeClass</a>') > -1
+ '<a href="pkg.SomeClass.html">SomeClass</a>') > -1
someclass_init_api = apidir.join('pkg.SomeClass.__init__.html')
assert someclass_init_api.check(file=True)
assert someclass_init_api.read().find(
- '<a href="api/pkg.SomeClass.__init__.html">__init__</a>') > -1
+ '<a href="pkg.SomeClass.__init__.html">__init__</a>') > -1
namespace_api = apidir.join('pkg.html')
assert namespace_api.check(file=True)
assert namespace_api.read().find(
- '<a href="api/pkg.SomeClass.html">SomeClass</a>') > -1
+ '<a href="pkg.SomeClass.html">SomeClass</a>') > -1
sourcedir = tempdir.join('source')
assert sourcedir.check(dir=True)
Modified: py/dist/py/apigen/testing/test_linker.py
==============================================================================
--- py/dist/py/apigen/testing/test_linker.py (original)
+++ py/dist/py/apigen/testing/test_linker.py Sun Jan 14 22:06:04 2007
@@ -13,9 +13,11 @@
linker = Linker()
lazyhref = linker.get_lazyhref('py.path.local')
linker.set_link('py.path.local', 'py/path/local.html')
- relpath = linker.get_target_relative('py.path.local', 'py/index.html')
+ relpath = linker.call_withbase('py/index.html',
+ linker.get_target, 'py.path.local')
assert relpath == 'path/local.html'
+
testspec = [
'a a/b a/b',
More information about the pytest-commit
mailing list