diff --git a/py/apigen/api.js b/py/apigen/api.js new file mode 100644 index 000000000..3ed872a06 --- /dev/null +++ b/py/apigen/api.js @@ -0,0 +1,7 @@ +function showhideel(el) { + if (el.style.display == 'none') { + el.style.display = 'block'; + } else { + el.style.display = 'none'; + }; +}; diff --git a/py/apigen/htmlgen.py b/py/apigen/htmlgen.py index 0e6b069bc..b9adbb288 100644 --- a/py/apigen/htmlgen.py +++ b/py/apigen/htmlgen.py @@ -130,13 +130,16 @@ def create_namespace_tree(dotted_names): ret[ns].append(itempath) return ret -def wrap_page(project, title, contentel, navel, outputpath, stylesheeturl): +def wrap_page(project, title, contentel, navel, outputpath, stylesheeturl, + scripturls): page = LayoutPage(project, title, nav=navel, encoding='UTF-8', - stylesheeturl=stylesheeturl) + stylesheeturl=stylesheeturl, scripturls=scripturls) page.set_content(contentel) here = py.magic.autopath().dirpath() style = here.join('style.css').read() outputpath.join('style.css').write(style) + apijs = here.join('api.js').read() + outputpath.join('api.js').write(apijs) return page # the PageBuilder classes take care of producing the docs (using the stuff @@ -146,8 +149,10 @@ class AbstractPageBuilder(object): targetpath = self.base.join(reltargetpath) stylesheeturl = relpath('%s/' % (targetpath.dirpath(),), self.base.join('style.css').strpath) + scripturls = [relpath('%s/' % (targetpath.dirpath(),), + self.base.join('api.js').strpath)] page = wrap_page(project, title, - tag, nav, self.base, stylesheeturl) + tag, nav, self.base, stylesheeturl, scripturls) content = self.linker.call_withbase(reltargetpath, page.unicode) targetpath.ensure() targetpath.write(content.encode("utf8")) @@ -315,9 +320,11 @@ class ApiPageBuilder(AbstractPageBuilder): snippet = H.FunctionDescription( H.FunctionDef(localname, argdesc), - valuedesc, H.Docstring(docstring or H.em('no docstring available')), - csource, + H.div(H.a('show/hide info', + onclick='showhideel(this.parentNode.lastChild);'), + H.div(valuedesc, csource, style='display: none', + class_='funcinfo')), ) return snippet @@ -532,7 +539,7 @@ class ApiPageBuilder(AbstractPageBuilder): valuedesc.append(self.build_sig_value_description(name, _type)) if retval: retval = self.process_type_link(retval) - ret = H.div(H.div('where:'), valuedesc, H.div('return value:'), + ret = H.div(H.div('arguments:'), valuedesc, H.div('return value:'), retval or 'None') return ret diff --git a/py/apigen/layout.py b/py/apigen/layout.py index d8bd4adce..dc1a705f1 100644 --- a/py/apigen/layout.py +++ b/py/apigen/layout.py @@ -11,6 +11,7 @@ class LayoutPage(Page): def __init__(self, *args, **kwargs): self.nav = kwargs.pop('nav') + self.scripturls = kwargs.pop('scripturls', []) super(LayoutPage, self).__init__(*args, **kwargs) def set_content(self, contentel): @@ -20,4 +21,7 @@ class LayoutPage(Page): 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)) diff --git a/py/apigen/style.css b/py/apigen/style.css index f78b5adeb..02e5ea0c8 100644 --- a/py/apigen/style.css +++ b/py/apigen/style.css @@ -63,43 +63,49 @@ ul li { } .code a { - color: blue; - font-weight: bold; - text-decoration: none; + color: blue; + font-weight: bold; + text-decoration: none; } a:hover { - color: #005; + color: #005; } - + .lineno { - text-align: right; - color: #555; - width: 3em; - padding-right: 1em; - border: 0px solid black; - border-right-width: 1px; + text-align: right; + color: #555; + width: 3em; + padding-right: 1em; + border: 0px solid black; + border-right-width: 1px; } .code { - padding-left: 1em; - white-space: pre; - font-family: monospace, Monaco; + padding-left: 1em; + white-space: pre; + font-family: monospace, Monaco; } .comment { - color: purple; + color: purple; } .string { - color: #777; + color: #777; } .keyword { - color: blue; + color: blue; } .alt_keyword { - color: green; + color: green; } - + +.funcinfo { + border: 1px solid black; + color: black; + padding: 1em; +} + diff --git a/py/apigen/testing/test_apigen_example.py b/py/apigen/testing/test_apigen_example.py index 4d8be2117..51ed352f7 100644 --- a/py/apigen/testing/test_apigen_example.py +++ b/py/apigen/testing/test_apigen_example.py @@ -200,6 +200,7 @@ class TestApiPageBuilder(AbstractBuilderTest): print html run_string_sequence_test(html, [ 'href="../style.css"', + 'src="../api.js"', 'href="index.html">pkg', 'href="main.html">main', 'href="main.SomeClass.html">SomeClass',