[svn r37812] Using style.css from the doc directory for apigen now, with some overrides in

a seperate stylesheet. Cleaned up the stylesheet and script handling a bit:
stylesheets and scripts are now defined in the LayoutPage class (where they're
easily customizable). Also removed some old unused code and moved the H class
(html related) stuff to its own file. The idea is that this will become the
place where all the layout is defined.

--HG--
branch : trunk
This commit is contained in:
guido 2007-02-02 16:49:58 +01:00
parent 24539c3797
commit 37a4bfd5ad
5 changed files with 125 additions and 186 deletions

81
py/apigen/html.py Normal file
View File

@ -0,0 +1,81 @@
from py.xml import html
# HTML related stuff
class H(html):
class Content(html.div):
pass # style = html.Style(margin_left='15em')
class Description(html.div):
pass
class NamespaceDescription(Description):
pass
class NamespaceItem(html.div):
pass
class NamespaceDef(html.h1):
pass
class ClassDescription(Description):
pass
class ClassDef(html.h1):
pass
class MethodDescription(Description):
pass
class MethodDef(html.h2):
pass
class FunctionDescription(Description):
pass
class FunctionDef(html.h2):
pass
class ParameterDescription(html.div):
pass
class Docstring(html.pre):
style = html.Style(width='100%')
pass
class Navigation(html.div):
#style = html.Style(min_height='99%', float='left', margin_top='1.2em',
# overflow='auto', width='15em', white_space='nowrap')
pass
class NavigationItem(html.div):
pass
class BaseDescription(html.a):
pass
class SourceDef(html.div):
pass
class NonPythonSource(html.pre):
pass # style = html.Style(margin_left='15em')
class DirList(html.div):
pass # style = html.Style(margin_left='15em')
class DirListItem(html.div):
pass
class ValueDescList(html.ul):
def __init__(self, *args, **kwargs):
super(H.ValueDescList, self).__init__(*args, **kwargs)
class ValueDescItem(html.li):
pass
class CallStackDescription(Description):
pass
class CallStackItem(html.div):
class_ = 'callstackitem'

View File

@ -8,6 +8,7 @@ from py.__.apigen.source import color as source_color
from py.__.apigen.tracer.description import is_private
from py.__.apigen.rest.genrest import split_of_last_part
from py.__.apigen.linker import relpath
from py.__.apigen.html import H
sorted = py.builtin.sorted
html = py.xml.html
@ -45,83 +46,6 @@ def deindent(str, linesep='\n'):
ret.append(line[deindent:])
return '%s\n' % (linesep.join(ret),)
# HTML related stuff
class H(html):
class Content(html.div):
style = html.Style(margin_left='15em')
class Description(html.div):
pass
class NamespaceDescription(Description):
pass
class NamespaceItem(html.div):
pass
class NamespaceDef(html.h1):
pass
class ClassDescription(Description):
pass
class ClassDef(html.h1):
pass
class MethodDescription(Description):
pass
class MethodDef(html.h2):
pass
class FunctionDescription(Description):
pass
class FunctionDef(html.h2):
pass
class ParameterDescription(html.div):
pass
class Docstring(html.pre):
#style = html.Style(white_space='pre', min_height='3em')
pass
class Navigation(html.div):
style = html.Style(min_height='99%', float='left', margin_top='1.2em',
overflow='auto', width='15em', white_space='nowrap')
class NavigationItem(html.div):
pass
class BaseDescription(html.a):
pass
class SourceDef(html.div):
pass
class NonPythonSource(html.pre):
style = html.Style(margin_left='15em')
class DirList(html.div):
style = html.Style(margin_left='15em')
class DirListItem(html.div):
pass
class ValueDescList(html.ul):
def __init__(self, *args, **kwargs):
super(H.ValueDescList, self).__init__(*args, **kwargs)
class ValueDescItem(html.li):
pass
class CallStackDescription(Description):
pass
class CallStackItem(html.div):
class_ = 'callstackitem'
def get_param_htmldesc(linker, func):
""" get the html for the parameters of a function """
import inspect
@ -174,18 +98,11 @@ def create_namespace_tree(dotted_names):
ret[ns].append(itempath)
return ret
def wrap_page(project, title, contentel, navel, outputpath, stylesheeturl,
scripturls):
def wrap_page(project, title, contentel, navel, relbase, basepath):
page = LayoutPage(project, title, nav=navel, encoding='UTF-8',
stylesheeturl=stylesheeturl, scripturls=scripturls)
relpath=relbase)
page.set_content(contentel)
here = py.magic.autopath().dirpath()
style = here.join(stylesheeturl.split('/')[-1]).read()
outputpath.join(stylesheeturl.split('/')[-1]).write(style)
for spath in scripturls:
sname = spath.split('/')[-1]
sdata = here.join(sname).read()
outputpath.join(sname).write(sdata)
page.setup_scripts_styles(basepath)
return page
# the PageBuilder classes take care of producing the docs (using the stuff
@ -193,12 +110,9 @@ def wrap_page(project, title, contentel, navel, outputpath, stylesheeturl,
class AbstractPageBuilder(object):
def write_page(self, title, reltargetpath, project, tag, nav):
targetpath = self.base.join(reltargetpath)
stylesheeturl = relpath('%s%s' % (targetpath.dirpath(), os.path.sep),
self.base.join('style.css').strpath)
scripturls = [relpath('%s%s' % (targetpath.dirpath(), os.path.sep),
self.base.join('api.js').strpath)]
page = wrap_page(project, title,
tag, nav, self.base, stylesheeturl, scripturls)
relbase= relpath('%s%s' % (targetpath.dirpath(), targetpath.sep),
self.base.strpath + '/')
page = wrap_page(project, title, tag, nav, relbase, self.base)
content = self.linker.call_withbase(reltargetpath, page.unicode)
targetpath.ensure()
targetpath.write(content.encode("utf8"))
@ -212,7 +126,7 @@ class SourcePageBuilder(AbstractPageBuilder):
self.capture = capture
def build_navigation(self, fspath):
nav = H.Navigation()
nav = H.Navigation(class_='sidebar')
relpath = fspath.relto(self.projroot)
path = relpath.split(os.path.sep)
indent = 0
@ -613,40 +527,7 @@ class ApiPageBuilder(AbstractPageBuilder):
return navitems
navitems += build_nav_level(dotted_name)
return H.Navigation(*navitems)
navitems = []
# top namespace, index.html
module_name = self.dsa.get_module_name().split('/')[-1]
navitems.append(build_navitem_html(self.linker, module_name, '', 0,
(selection == '')))
indent = 1
path = dotted_name.split('.')
if dotted_name != '':
# build html for each item in path to dotted_name item
for i in xrange(len(path)):
name = path[i]
item_dotted_name = '.'.join(path[:i+1])
selected = (selection == item_dotted_name)
navitems.append(build_navitem_html(self.linker, name,
item_dotted_name, indent,
selected))
indent += 1
# build sub items of dotted_name item
for item_dotted_name in py.builtin.sorted(item_dotted_names):
itemname = item_dotted_name.split('.')[-1]
if is_private(itemname):
continue
selected = (item_dotted_name == selection)
navitems.append(build_navitem_html(self.linker, itemname,
item_dotted_name, indent,
selected))
return H.Navigation(*navitems)
return H.Navigation(class_='sidebar', *navitems)
def build_callable_signature_description(self, dotted_name):
args, retval = self.dsa.get_function_signature(dotted_name)

View File

@ -4,14 +4,19 @@
"""
import py
from py.__.doc.confrest import Page
from py.__.doc import confrest
from py.__.apigen import linker
class LayoutPage(Page):
class LayoutPage(confrest.PyPage):
""" this provides the layout and style information """
stylesheets = [(py.path.local('../doc/style.css'), 'style.css'),
(py.path.local('style.css'), 'apigen_style.css')]
scripts = [(py.path.local('api.js'), 'api.js')]
def __init__(self, *args, **kwargs):
self.nav = kwargs.pop('nav')
self.scripturls = kwargs.pop('scripturls', [])
self.relpath = kwargs.pop('relpath')
super(LayoutPage, self).__init__(*args, **kwargs)
def set_content(self, contentel):
@ -19,9 +24,19 @@ class LayoutPage(Page):
def fill(self):
super(LayoutPage, self).fill()
self.menubar[:] = []
self.menubar.append(self.nav)
for scripturl in self.scripturls:
self.head.append(py.xml.html.script(type="text/javascript",
src=scripturl))
#self.menubar[:] = []
self.body.insert(0, self.nav)
def setup_scripts_styles(self, copyto=None):
for path, name in self.stylesheets:
if copyto:
copyto.join(name).write(path.read())
self.head.append(py.xml.html.link(type='text/css',
rel='stylesheet',
href=self.relpath + name))
for path, name in self.scripts:
if copyto:
copyto.join(name).write(path.read())
self.head.append(py.xml.html.script(type="text/javascript",
src=self.relpath + name))

View File

@ -1,12 +1,18 @@
#sidebar {
width: 9em;
float: left;
div.sidebar {
font-family: Verdana, Helvetica, Arial, sans-serif;
width: 155px;
vertical-align: top;
margin-top: 0.5em;
position: absolute;
top: 130px;
left: 4px;
bottom: 4px;
overflow: auto;
}
#main {
margin-left: 10em;
div.sidebar .selected a {
color: white;
background-color: #3ba6ec;
}
#content {
@ -15,47 +21,6 @@
width: 100%;
}
#breadcrumb {
height: 5%;
display: none;
}
#logo {
/* float: left; */
}
#logo img {
border-width: 0px;
}
#menubar a {
text-decoration: none;
color: blue;
}
#menubar div.selected a {
color: purple;
}
.project_title {
font-size: 2em;
font-weight: bold;
}
body {
background-color: #FFE;
color: black;
}
body, div, p, h1, h2, h3, h4 {
font-family: Trebuchet MS, Verdana, Arial;
}
a {
color: #006;
text-decoration: none;
}
ul {
padding-left: 0em;
margin-top: 0px;
@ -71,10 +36,6 @@ ul li {
text-decoration: none;
}
a:hover {
color: #005;
}
.lineno {
text-align: right;
color: #555;

View File

@ -204,6 +204,7 @@ class TestApiPageBuilder(AbstractBuilderTest):
print html
run_string_sequence_test(html, [
'href="../style.css"',
'href="../apigen_style.css"',
'src="../api.js"',
'href="index.html">pkg',
'href="main.html">main',