Toc / list with all classes generated by the module in sphinx documents

I have a python Im package about to upgrade to sphinx from epydoc. The package itself is documented by the sphinx auto-module function. Now I would like to get a summary of all the classes in my module in a simple list / table at the beginning of my document module or even better (?) In toc-tree.

My part of the car module (in pymunk.rst) looks like

.. automodule:: pymunk
    :members:
    :undoc-members:
    :show-inheritance:
    :inherited-members:

then at pymunk.constraint.rst

.. automodule:: pymunk.constraint
    :members:
    :undoc-members:
    :show-inheritance:
    :inherited-members:

etc. In each file I need a list of all classes, so it’s easy to get an overview of the available ones without scrolling through all the documentation or the monstrous index. Final result:

pymunk
    pymunk.Space
    pymunk.Circle
    ...

My main goal is to create html.

Im thinking right now about doing something clever with javascript to extract and insert a list, but should there be a better way?

( : http://pymunk.readthedocs.org/en/latest/pymunk.html)

+5
1

jQuery .

, :

.. container:: custom-index

    .. raw:: html

        <script type="text/javascript" src='_static/pymunk.js'></script> 

, div html, script , , .

pymunk.js , .

javascript , TOC, , . , , .

js :

$(function (){
var createList = function(selector){

    var ul = $('<ul>');
    var selected = $(selector);

    if (selected.length === 0){
        return;
    }

    selected.clone().each(function (i,e){

        var p = $(e).children('.descclassname');
        var n = $(e).children('.descname');
        var l = $(e).children('.headerlink');

        var a = $('<a>');
        a.attr('href',l.attr('href')).attr('title', 'Link to this definition');

        a.append(p).append(n);

        var entry = $('<li>').append(a);
        ul.append(entry);
    });
    return ul;
}


var c = $('<div style="float:left; min-width: 300px;">');

var ul0 = c.clone().append($('.submodule-index'))

customIndex = $('.custom-index');
customIndex.empty();
customIndex.append(ul0);

var x = [];
x.push(['Classes','dl.class > dt']);
x.push(['Functions','dl.function > dt']);
x.push(['Variables','dl.data > dt']);

x.forEach(function (e){
    var l = createList(e[1]);
    if (l) {        
        var ul = c.clone()
            .append('<p class="rubric">'+e[0]+'</p>')
            .append(l);
    }
    customIndex.append(ul);
});

});
+2

All Articles