Skip to content

Commit

Permalink
DOC: Fold TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock authored and josef-pkt committed Oct 6, 2012
1 parent cea1a5f commit 4b7278b
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 18 deletions.
3 changes: 3 additions & 0 deletions docs/Makefile
Expand Up @@ -8,6 +8,7 @@ PAPER =
BUILDDIR = build
TOOLSPATH = ../tools/
EXAMPLEBUILD = examples_rst.py
FOLDTOC = fold_toc.py

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
Expand Down Expand Up @@ -46,6 +47,8 @@ html:
@echo "Generating reST from examples folder"
$(TOOLSPATH)$(EXAMPLEBUILD)
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
$(TOOLSPATH)$(EXAMPLEBUILD)
$(TOOLSPATH)$(FOLDTOC) $(BUILDDIR)/html/index.html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

Expand Down
Binary file added docs/source/_static/bullet.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/minus.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions docs/source/_static/mktree.css
@@ -0,0 +1,23 @@
/* Put this inside a @media qualifier so Netscape 4 ignores it */
@media screen, print {
/* Turn off list bullets */
ul.mktree li { list-style: none; }
/* Control how "spaced out" the tree is */
ul.mktree, ul.mktree ul , ul.mktree li { margin-left:10px; padding:0px; }
/* Provide space for our own "bullet" inside the LI */
ul.mktree li .bullet { padding-left: 15px; }
/* Show "bullets" in the links, depending on the class of the LI that the link's in */
ul.mktree li.liOpen .bullet { cursor: pointer; background: url(minus.gif) center left no-repeat; }
ul.mktree li.liClosed .bullet { cursor: pointer; background: url(plus.gif) center left no-repeat; }
ul.mktree li.liBullet .bullet { cursor: default; background: url(bullet.gif) center left no-repeat; }
/* Sublists are visible or not based on class of parent LI */
ul.mktree li.liOpen ul { display: block; }
ul.mktree li.liClosed ul { display: none; }

/* Format menu items differently depending on what level of the tree they are in */
/* Uncomment this if you want your fonts to decrease in size the deeper they are in the tree */
/*
ul.mktree li ul li { font-size: 90% }
*/

}
168 changes: 168 additions & 0 deletions docs/source/_static/mktree.js
@@ -0,0 +1,168 @@
/**
* Copyright (c)2005-2009 Matt Kruse (javascripttoolbox.com)
*
* Dual licensed under the MIT and GPL licenses.
* This basically means you can use this code however you want for
* free, but don't claim to have written it yourself!
* Donations always accepted: http://www.JavascriptToolbox.com/donate/
*
* Please do not link to the .js files on javascripttoolbox.com from
* your site. Copy the files locally to your server instead.
*
*/
/*
This code is inspired by and extended from Stuart Langridge's aqlist code:
http://www.kryogenix.org/code/browser/aqlists/
Stuart Langridge, November 2002
sil@kryogenix.org
Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/)
and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)
*/

// Automatically attach a listener to the window onload, to convert the trees
addEvent(window,"load",convertTrees);

// Utility function to add an event listener
function addEvent(o,e,f){
if (o.addEventListener){ o.addEventListener(e,f,false); return true; }
else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
else { return false; }
}

// utility function to set a global variable if it is not already set
function setDefault(name,val) {
if (typeof(window[name])=="undefined" || window[name]==null) {
window[name]=val;
}
}

// Full expands a tree with a given ID
function expandTree(treeId) {
var ul = document.getElementById(treeId);
if (ul == null) { return false; }
expandCollapseList(ul,nodeOpenClass);
}

// Fully collapses a tree with a given ID
function collapseTree(treeId) {
var ul = document.getElementById(treeId);
if (ul == null) { return false; }
expandCollapseList(ul,nodeClosedClass);
}

// Expands enough nodes to expose an LI with a given ID
function expandToItem(treeId,itemId) {
var ul = document.getElementById(treeId);
if (ul == null) { return false; }
var ret = expandCollapseList(ul,nodeOpenClass,itemId);
if (ret) {
var o = document.getElementById(itemId);
if (o.scrollIntoView) {
o.scrollIntoView(false);
}
}
}

// Performs 3 functions:
// a) Expand all nodes
// b) Collapse all nodes
// c) Expand all nodes to reach a certain ID
function expandCollapseList(ul,cName,itemId) {
if (!ul.childNodes || ul.childNodes.length==0) { return false; }
// Iterate LIs
for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
var item = ul.childNodes[itemi];
if (itemId!=null && item.id==itemId) { return true; }
if (item.nodeName == "LI") {
// Iterate things in this LI
var subLists = false;
for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
var sitem = item.childNodes[sitemi];
if (sitem.nodeName=="UL") {
subLists = true;
var ret = expandCollapseList(sitem,cName,itemId);
if (itemId!=null && ret) {
item.className=cName;
return true;
}
}
}
if (subLists && itemId==null) {
item.className = cName;
}
}
}
}

// Search the document for UL elements with the correct CLASS name, then process them
function convertTrees() {
setDefault("treeClass","mktree");
setDefault("nodeClosedClass","liClosed");
setDefault("nodeOpenClass","liOpen");
setDefault("nodeBulletClass","liBullet");
setDefault("nodeLinkClass","bullet");
setDefault("preProcessTrees",true);
if (preProcessTrees) {
if (!document.createElement) { return; } // Without createElement, we can't do anything
var uls = document.getElementsByTagName("ul");
if (uls==null) { return; }
var uls_length = uls.length;
for (var uli=0;uli<uls_length;uli++) {
var ul=uls[uli];
if (ul.nodeName=="UL" && ul.className==treeClass) {
processList(ul);
}
}
}
}

function treeNodeOnclick() {
this.parentNode.className = (this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;
return false;
}
function retFalse() {
return false;
}
// Process a UL tag and all its children, to convert to a tree
function processList(ul) {
if (!ul.childNodes || ul.childNodes.length==0) { return; }
// Iterate LIs
var childNodesLength = ul.childNodes.length;
for (var itemi=0;itemi<childNodesLength;itemi++) {
var item = ul.childNodes[itemi];
if (item.nodeName == "LI") {
// Iterate things in this LI
var subLists = false;
var itemChildNodesLength = item.childNodes.length;
for (var sitemi=0;sitemi<itemChildNodesLength;sitemi++) {
var sitem = item.childNodes[sitemi];
if (sitem.nodeName=="UL") {
subLists = true;
processList(sitem);
}
}
var s= document.createElement("SPAN");
var t= '\u00A0'; // &nbsp;
s.className = nodeLinkClass;
if (subLists) {
// This LI has UL's in it, so it's a +/- node
if (item.className==null || item.className=="") {
item.className = nodeClosedClass;
}
// If it's just text, make the text work as the link also
if (item.firstChild.nodeName=="#text") {
t = t+item.firstChild.nodeValue;
item.removeChild(item.firstChild);
}
s.onclick = treeNodeOnclick;
}
else {
// No sublists, so it's just a bullet node
item.className = nodeBulletClass;
s.onclick = retFalse;
}
s.appendChild(document.createTextNode(t));
item.insertBefore(s,item.firstChild);
}
}
}
Binary file added docs/source/_static/plus.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 10 additions & 18 deletions docs/source/index.rst
Expand Up @@ -41,32 +41,24 @@ described in `results.__doc__` and results methods have their own docstrings.
Basic Documentation
-------------------

.. toctree::
:maxdepth: 1

introduction
gettingstarted
install
related
+ `Introduction <introduction.html>`_
+ `Getting Started <gettingstarted.html>`_
+ `Installation <install.html>`_
+ `Related Projects <related.html>`_

The following provide more information about the structure and development of
Information about the structure and development of
statsmodels:

.. toctree::
:maxdepth: 1

importpaths
pitfalls
dev/index
dev/internal


+ `Import paths and structure <importpaths.html>`_
+ `Pitfalls <pitfalls.html>`_
+ `Developer page <dev/index.html>`_
+ `Internal classes <dev/internal.html>`_

Table of Contents
-----------------

.. toctree::
:maxdepth: 2
:maxdepth: 3

regression
glm
Expand Down
50 changes: 50 additions & 0 deletions tools/fold_toc.py
@@ -0,0 +1,50 @@
#!/usr/bin/env python
import sys
import re

# Read doc to string
filename = sys.argv[1]
doc = open(filename).read()

# Add mktree to head
pre = '<head>'
post = '''<head>
<script type="text/javascript" src="_static/mktree.js"></script>
<link rel="stylesheet" href="_static/mktree.css" type="text/css">
'''
doc = re.sub(pre, post, doc)

# TOC class
pre = '''<div class="toctree-wrapper compound">
<ul>'''
post = '''<div class="toctree-wrapper compound">
Click <tt>+</tt> to expand and <tt>-</tt> to collapse.
<a onclick="collapseTree('toctree')" href="javascript:void(0);">Collapse all. </a>
<a onclick="expandTree('toctree')" href="javascript:void(0);">Expand all. </a>
<ul class="mktree" id="toctree">'''
doc = re.sub(pre, post, doc)

## TOC entries
pre = '<li class="toctree-l1">'
post = '<li class="liClosed"> '
doc = re.sub(pre, post, doc)

# TOC entries 2nd level
pre = '<li class="toctree-l2">'
post = '<li class="liClosed"> '
doc = re.sub(pre, post, doc)

# TOC entries 3rd level
pre = '<li class="toctree-l3">'
post = '<li class="liClosed"> '
doc = re.sub(pre, post, doc)

# TOC entries 4th level
pre = '<li class="toctree-l4">'
post = '<li class="liClosed"> '
doc = re.sub(pre, post, doc)

# Write to file
f = open(filename, 'w')
f.write(doc)
f.close()

0 comments on commit 4b7278b

Please sign in to comment.