[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:
parent
24539c3797
commit
37a4bfd5ad
|
@ -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'
|
||||||
|
|
|
@ -8,6 +8,7 @@ from py.__.apigen.source import color as source_color
|
||||||
from py.__.apigen.tracer.description import is_private
|
from py.__.apigen.tracer.description import is_private
|
||||||
from py.__.apigen.rest.genrest import split_of_last_part
|
from py.__.apigen.rest.genrest import split_of_last_part
|
||||||
from py.__.apigen.linker import relpath
|
from py.__.apigen.linker import relpath
|
||||||
|
from py.__.apigen.html import H
|
||||||
|
|
||||||
sorted = py.builtin.sorted
|
sorted = py.builtin.sorted
|
||||||
html = py.xml.html
|
html = py.xml.html
|
||||||
|
@ -45,83 +46,6 @@ def deindent(str, linesep='\n'):
|
||||||
ret.append(line[deindent:])
|
ret.append(line[deindent:])
|
||||||
return '%s\n' % (linesep.join(ret),)
|
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):
|
def get_param_htmldesc(linker, func):
|
||||||
""" get the html for the parameters of a function """
|
""" get the html for the parameters of a function """
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -174,18 +98,11 @@ def create_namespace_tree(dotted_names):
|
||||||
ret[ns].append(itempath)
|
ret[ns].append(itempath)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def wrap_page(project, title, contentel, navel, outputpath, stylesheeturl,
|
def wrap_page(project, title, contentel, navel, relbase, basepath):
|
||||||
scripturls):
|
|
||||||
page = LayoutPage(project, title, nav=navel, encoding='UTF-8',
|
page = LayoutPage(project, title, nav=navel, encoding='UTF-8',
|
||||||
stylesheeturl=stylesheeturl, scripturls=scripturls)
|
relpath=relbase)
|
||||||
page.set_content(contentel)
|
page.set_content(contentel)
|
||||||
here = py.magic.autopath().dirpath()
|
page.setup_scripts_styles(basepath)
|
||||||
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)
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
# the PageBuilder classes take care of producing the docs (using the stuff
|
# 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):
|
class AbstractPageBuilder(object):
|
||||||
def write_page(self, title, reltargetpath, project, tag, nav):
|
def write_page(self, title, reltargetpath, project, tag, nav):
|
||||||
targetpath = self.base.join(reltargetpath)
|
targetpath = self.base.join(reltargetpath)
|
||||||
stylesheeturl = relpath('%s%s' % (targetpath.dirpath(), os.path.sep),
|
relbase= relpath('%s%s' % (targetpath.dirpath(), targetpath.sep),
|
||||||
self.base.join('style.css').strpath)
|
self.base.strpath + '/')
|
||||||
scripturls = [relpath('%s%s' % (targetpath.dirpath(), os.path.sep),
|
page = wrap_page(project, title, tag, nav, relbase, self.base)
|
||||||
self.base.join('api.js').strpath)]
|
|
||||||
page = wrap_page(project, title,
|
|
||||||
tag, nav, self.base, stylesheeturl, scripturls)
|
|
||||||
content = self.linker.call_withbase(reltargetpath, page.unicode)
|
content = self.linker.call_withbase(reltargetpath, page.unicode)
|
||||||
targetpath.ensure()
|
targetpath.ensure()
|
||||||
targetpath.write(content.encode("utf8"))
|
targetpath.write(content.encode("utf8"))
|
||||||
|
@ -212,7 +126,7 @@ class SourcePageBuilder(AbstractPageBuilder):
|
||||||
self.capture = capture
|
self.capture = capture
|
||||||
|
|
||||||
def build_navigation(self, fspath):
|
def build_navigation(self, fspath):
|
||||||
nav = H.Navigation()
|
nav = H.Navigation(class_='sidebar')
|
||||||
relpath = fspath.relto(self.projroot)
|
relpath = fspath.relto(self.projroot)
|
||||||
path = relpath.split(os.path.sep)
|
path = relpath.split(os.path.sep)
|
||||||
indent = 0
|
indent = 0
|
||||||
|
@ -613,40 +527,7 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
return navitems
|
return navitems
|
||||||
|
|
||||||
navitems += build_nav_level(dotted_name)
|
navitems += build_nav_level(dotted_name)
|
||||||
return H.Navigation(*navitems)
|
return H.Navigation(class_='sidebar', *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)
|
|
||||||
|
|
||||||
def build_callable_signature_description(self, dotted_name):
|
def build_callable_signature_description(self, dotted_name):
|
||||||
args, retval = self.dsa.get_function_signature(dotted_name)
|
args, retval = self.dsa.get_function_signature(dotted_name)
|
||||||
|
|
|
@ -4,14 +4,19 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import py
|
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 """
|
""" 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):
|
def __init__(self, *args, **kwargs):
|
||||||
self.nav = kwargs.pop('nav')
|
self.nav = kwargs.pop('nav')
|
||||||
self.scripturls = kwargs.pop('scripturls', [])
|
self.relpath = kwargs.pop('relpath')
|
||||||
super(LayoutPage, self).__init__(*args, **kwargs)
|
super(LayoutPage, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def set_content(self, contentel):
|
def set_content(self, contentel):
|
||||||
|
@ -19,9 +24,19 @@ class LayoutPage(Page):
|
||||||
|
|
||||||
def fill(self):
|
def fill(self):
|
||||||
super(LayoutPage, self).fill()
|
super(LayoutPage, self).fill()
|
||||||
self.menubar[:] = []
|
#self.menubar[:] = []
|
||||||
self.menubar.append(self.nav)
|
self.body.insert(0, self.nav)
|
||||||
for scripturl in self.scripturls:
|
|
||||||
self.head.append(py.xml.html.script(type="text/javascript",
|
def setup_scripts_styles(self, copyto=None):
|
||||||
src=scripturl))
|
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))
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
#sidebar {
|
div.sidebar {
|
||||||
width: 9em;
|
font-family: Verdana, Helvetica, Arial, sans-serif;
|
||||||
float: left;
|
width: 155px;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
|
position: absolute;
|
||||||
|
top: 130px;
|
||||||
|
left: 4px;
|
||||||
|
bottom: 4px;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#main {
|
div.sidebar .selected a {
|
||||||
margin-left: 10em;
|
color: white;
|
||||||
|
background-color: #3ba6ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
#content {
|
#content {
|
||||||
|
@ -15,47 +21,6 @@
|
||||||
width: 100%;
|
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 {
|
ul {
|
||||||
padding-left: 0em;
|
padding-left: 0em;
|
||||||
margin-top: 0px;
|
margin-top: 0px;
|
||||||
|
@ -71,10 +36,6 @@ ul li {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
|
||||||
color: #005;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lineno {
|
.lineno {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
color: #555;
|
color: #555;
|
||||||
|
|
|
@ -204,6 +204,7 @@ class TestApiPageBuilder(AbstractBuilderTest):
|
||||||
print html
|
print html
|
||||||
run_string_sequence_test(html, [
|
run_string_sequence_test(html, [
|
||||||
'href="../style.css"',
|
'href="../style.css"',
|
||||||
|
'href="../apigen_style.css"',
|
||||||
'src="../api.js"',
|
'src="../api.js"',
|
||||||
'href="index.html">pkg',
|
'href="index.html">pkg',
|
||||||
'href="main.html">main',
|
'href="main.html">main',
|
||||||
|
|
Loading…
Reference in New Issue