Skip to content

Major revamp #3

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

Merged
merged 16 commits into from
May 4, 2020
Merged

Major revamp #3

merged 16 commits into from
May 4, 2020

Conversation

chrisjsewell
Copy link
Member

No description provided.

@chrisjsewell chrisjsewell changed the title Update docs Major revamp May 2, 2020
@chrisjsewell chrisjsewell requested a review from choldgraf May 2, 2020 23:40
@chrisjsewell
Copy link
Member Author

chrisjsewell commented May 2, 2020

@choldgraf I've done a major revamp of this, to more closely follow the bootstrap 4 system(s). Have a look at the docs and see what you think.

Note I'm using the RTD (non-bootstrap) theme here, because I wanted to check that it works for the AiiDA docs (the initial use case). But ideally we could make the docs for both this theme (non-bootstrap) and the pydata one (bootstrap), like nbsphinx does with their docs and multiple theme builds: https://nbsphinx.readthedocs.io

Comment on lines 187 to 189
# TODO only load these is using a non-boostrap theme
app.add_css_file("bs-grids.css")
app.add_css_file("bs-cards.css")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'd like to find a way to only load these CSS if bootstrap.min.css is not already being loaded (they just contain copied CSS from that, specific to each element)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any easy way to automate bootstrap theme discovery so, in e67f3ac, I have added a sphinx option to disable loading the bootstrap CSS

Copy link
Member

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think this looks really nice - see a few comments and questions in there


.. code-block:: rst

.. panels::
:container: container-lg pad-bottom-20
:container: container-lg pb-3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't always need :container: though, right? I feel like it should have reasonable defaults so users don't have to start writing their own bootstrap classes off the bat

Copy link
Member Author

@chrisjsewell chrisjsewell May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the defaults are described in the lines above this, and are defined in the code here:

DEFAULT_CONTAINER = "container pb-4"
DEFAULT_COLUMN = "col-lg-6 col-md-6 col-sm-6 col-xs-12"
DEFAULT_CARD = "shadow"

Note that all classes I use in the documentation are built-in boostrap classes, which are included in the CSS loaded in this extension

but it is advised you use the built-in bootstrap classes:

- `Card colouring <https://getbootstrap.com/docs/4.0/utilities/colors/>`_ contextual classes: `bg-primary`, `bg-success`, `bg-info`, `bg-warning`, `bg-danger`, `bg-secondary`, `bg-dark` and `bg-light`.
- `Padding and margins <https://getbootstrap.com/docs/4.0/utilities/spacing/>`_: `border-0`, `p-2`, `m-2`, ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if there'd be value in having something like "sphinx-bootstrap" that is just an easy way to define a few useful bootstrap elements with sphinx directives. You could imagine instructions like these being applied to a number of UI elements. (as opposed to having one sphinx extension per element type, such as "sphinx-panels", "sphinx-togglebutton", etc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, if this existed it would be easy to add the dependency to this package. If you look at the CSS I have added, you'll see that I have divided into approximately the classes required for each aspect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so there'd be something like a bootstrap meta-package that would make it possible for extension to depend on it and then those extensions don't have to worry about loading any bootstrap JS/CSS themselves?

That might be nice, then we could look into re-working sphinx-togglebutton so that it uses bootstrap, but without requiring users to use a theme that has bootstrap

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing that could benefit from bootstrap would be "question and answer" blocks: https://getbootstrap.com/docs/4.1/components/forms/

:footer: text-right

---
column += p-1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear what's happening here - are you running your own python code inside of the panel content?

Copy link
Member Author

@chrisjsewell chrisjsewell May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just using regexes to identify <column><+=><p-1>, then deciding whether to add to the existing classes, or reset them based on if = or +=. See:

if opt_match.group(2) == "+=":
classes[opt_match.group(1)] = (
classes.get(opt_match.group(1), []) + opt_match.group(3).split()
)
else:
classes[opt_match.group(1)] = opt_match.group(3).split()

title = nodes.container(
in_panel=True, classes=["card-title"] + classes["title"]
if "header" in data:
header = nodes.container(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one "gotcha" that we should make sure isn't an issue here is the word container. the pydata them realized that weird things were happening because container is a very common and specific bootstrap class, while Sphinx appends container to lots of things as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically account for this in:

def visit_container(self, node):
classes = "docutils container"
if node.get("in_panel", False):
# we don't want the CSS for container for these nodes
classes = "docutils"
self.body.append(self.starttag(node, "div", CLASS=classes))

@chrisjsewell
Copy link
Member Author

Thanks for the comments @choldgraf, I'll look now. Note in 16794f4 I have just changed the default delimiters (see docs), so that they are less likely to clash with rST header underlines, but also added a config value to change them. Open to suggestions on what the defaults should be though.

Co-authored-by: Chris Holdgraf <choldgraf@berkeley.edu>
@choldgraf
Copy link
Member

re: the delimiters, I'm guessing you've already considered and decided against just having another directive for these? E.g. following what sphinx-tabs does:

.. tabs::
   :tabs: config

   .. tab::
      :singletab: config

      tab1 content
   
   .. tab::
      :singletab: config

      tab2 content

   .. tab::
      :singletab: config

      tab3 content

?

@chrisjsewell
Copy link
Member Author

chrisjsewell commented May 4, 2020

re: the delimiters, I'm guessing you've already considered and decided against just having another directive for these?

Well yeh, I feel that (a) it adds the need for extra indentation (in rST at least), which I don't think is ideal and (b) it implies, assuming a panel directive, that it can be used outside the panels directive, and/or that there can be content in-between the panel directives, neither of which really make sense.

@choldgraf
Copy link
Member

Yeah that makes sense - I think that the pros and cons of parsing panel structure/config with a single directive basically comes down to complexity of the panels. The more complex you want your panel structure to be (or, the more you want it to deviate from the default), the more clunky it'll feel to configure with special syntax that only applies to the sphinx-panels directive. The less-complex you want it to be, the more it'll be straightforward to just use --- delimiters or whatever.

@chrisjsewell
Copy link
Member Author

chrisjsewell commented May 4, 2020

The more complex you want your panel structure to be

But then you can just use the nested container directive approach that pandas-dev/pandas#32065 uses. In some respect, this is meant to be a short-hand for that, which is simpler to type and doesn't leave you with large amounts of nested directives in your source document.

@choldgraf
Copy link
Member

@chrisjsewell that's a good point...at that point you're a "power user" so it's probably fine to expect folks to build their own containers etc

@chrisjsewell
Copy link
Member Author

chrisjsewell commented May 4, 2020

at that point you're a "power user"

Personally, as a "power user", I would still use this and feel it's a lot less clunky than having to use multiple directives. But yep, different strokes for different folks 😄

Ok cool well I think this is good to merge and release as v0.2.0. Unless you want to discuss anything else?

@choldgraf choldgraf merged commit b8d6b36 into master May 4, 2020
@choldgraf choldgraf deleted the testing2 branch May 4, 2020 17:40
@choldgraf
Copy link
Member

let's do it 🚀 - let's keep this "meta bootstrap" repository idea on the backburner and see if it could be useful in the future. I really like the idea of finding a way to expose bootstrap functionality to sphinx users without requiring them to use a particular theme

@choldgraf
Copy link
Member

choldgraf commented May 4, 2020

You know right after I pressed merge I had one other thought - rather than using a delimiter that's also got meaning in markdown/rST, what if we just used {panel} as a delimiter?

e.g.:

.. panels::

    Content of the top-left panel

    {panel}

    Content of the top-right panel

    {panel}

    Content of the bottom-left panel

    {panel}

    Content of the bottom-right panel

I feel like it is more likely somebody would want to write a line that starts with ... than a line that starts with {panel}, and in a way it is more verbose what that line means...

@chrisjsewell
Copy link
Member Author

eurgh, dunno I prefer being able to use variable length delimiters. I think it's easier to see the delimiters quickly, if you had a lot of content in the panels, with:

.. panels::

    Content of the top-left panel

    ...................................................

    Content of the top-right panel

    ...................................................

    Content of the bottom-left panel

Happy to put it out for poll or something though lol

@choldgraf
Copy link
Member

nah I think it's fine - I hadn't thought about variable-length. was just an idea to explore if you immediately jumped on it, but if your first thought is hesitation I think we should just go w/ the current approach and see if it raises problems over time

@choldgraf
Copy link
Member

choldgraf commented May 4, 2020

One other thought, then - the way that sphinx-gallery does this is to use two options for people. One is delimiters with #. e.g.:

Block 1

###################

Block 2

Which has the added benefit that it doesn't overlap with rST and also won't clash with ATX headers in markdown

Or another option which is to use Hydrogen and Pycharm-style delimiters like so:

Block 1

# %%

Blocks 2

I wonder if it would be good to piggy-back on one of those since there is already some prior art in the community for using those as delimiters?

Apologies for thinking of all this after hitting the big green button :-)

@chrisjsewell
Copy link
Member Author

Using # as a delimiter would just be a matter of changing the default in:

app.add_config_value("panels_delimiters", (".", "^", "+"), "env")

What is the link where you can do this in sphinx-gallery I can't actually find it

@choldgraf
Copy link
Member

Here's where they describe how to structure sphinx-gallery python files:

https://sphinx-gallery.github.io/stable/syntax.html#embed-rst-in-your-example-python-files

They have a different use-case, which is to break up blocks of python into content blocks and code blocks, but perhaps the same idea could be used here?

@chrisjsewell
Copy link
Member Author

ok right but (to state the obvious) thats for using rST in python files, which is not really the same use case. TBH I think there is enough flexibility in making the delimiters configurable. The only thing I would think of adding, is to allow the header and footer to be None to "switch them off", then you would only have one potential piece of syntax to clash with any existing syntax

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

Successfully merging this pull request may close these issues.

vertically center all content document arguments Allow for different numbers of columns
2 participants