Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indention of class methods #89

Open
Harper04 opened this issue Feb 6, 2014 · 2 comments
Open

Indention of class methods #89

Harper04 opened this issue Feb 6, 2014 · 2 comments

Comments

@Harper04
Copy link

Harper04 commented Feb 6, 2014

I really would like to see a visual hint that a method belongs to a class like in the default theme (it uses indentation).

In my usecase i have 'module' functions right after class methods and multiple classes which makes it hard to see the hierachy.

The current behaviour can be seen here (BoolSetting class):
http://ryan-roemer.github.io/django-cloud-browser/cloud_browser/app_settings.html#cloud_browser.app_settings.BoolSetting

and the code:
https://github.com/ryan-roemer/django-cloud-browser/blob/master/cloud_browser/app_settings.py

@veegee
Copy link

veegee commented Sep 10, 2014

Same issue. Easy fix: set up a custom CSS file like the README says. Here's mine:

dt {
    font-weight: normal;
}

dl.class > dt {
    font-size: 1.5em;
}

dl.class > dd {
    padding-left: 40px;
}

dl.method > dd {
    padding-left: 40px;
}

@svenevs
Copy link
Collaborator

svenevs commented Apr 26, 2017

Thought I'd add my two cents here. I suspect the reason this has never been explicitly a part of the library is because there are two conflicting cases:

  1. A user has written a definition list in their reStructuredText.
  2. The definition list being documented is coming from something like a class or function being documented.

To solve (1), the bootstrap class dl-horizontal can be used to render the desired effect. This produces the definition lists one would expect. The problem, though, is that the way bootstrap handles this means that when sphinx generates the definition lists for a class or function, if dl-horizontal is applied to every dl, then you will have horrific renderings. The name of the function / class will be truncated. Basically, dl-horizontal does something like this:

+----------------+---------------------+
|                | The dd (data)       |
| The dt (title) | function 1 of class |
|                | function 2 of class |
+----------------+---------------------+

So the result is that the class / function definitions get cut off and things are way worse than just not having any indentation. I don't know if the below is appropriate, and I don't know how easy it would be to actually bring this in, but there is one clue that makes this easy to circumvent: if a user is writing their own definition list in the restructured text document (or even documentation of a method), sphinx will not apply a class to this dl. On the other hand, sphinx will apply a class to all documentation related dl elements. E.g. as @veegee pointed out, dl.class or dl.method are things coming from the sphinx generated definition lists.

Reiterating that I don't know if this follows the standards, the following hack seems to be working quite reliably for me and thought I'd share since this indentation issue was the only thing disincentivizing me from using this theme!

  1. In your _static directory for the documentation, create the file indent.js (or whatever you want to call it), with the following contents:

    $(function(){
        /* If a user-produced definition list, apply dl-horizontal. */
        if($("dl").attr("class") == "") {
            $("dl").addClass("dl-horizontal");
        }
        /* Otherwise, this is a `sphinx` definition list for class /
         * function / etc documentation.  Apply some padding instead. */
        else {
            $("dl").children("dd").css({"padding-left": "4%"});
        }
    });

    Note: this is jQuery, which necessarily is already available for bootstrap.

    P.S. I don't know "formal" javascript, please suggest better versions if they exist!

  2. Now that we have the javascript ready, at the bottom of your conf.py, let sphinx know to use it. Emphasis: this is a path to the _static directory!

    def setup(app):
        # This has indent.js run on **every** page
        app.add_javascript("indent.js")

Like I said, this is definitely not the "right" approach, may not be mobile friendly and/or could be a resource hog, but it is working really well for me and thought somebody else could benefit 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants