Skip to content

Commit

Permalink
updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Oct 25, 2020
1 parent 91755a5 commit d95c656
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 74 deletions.
51 changes: 4 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

Expand All @@ -38,39 +21,12 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["jupyter_sphinx", "sphinx_conditional_asset", "myst_parser", "sphinx_panels"]

thebe_config = {
"repository_url": "https://github.com/binder-examples/jupyter-stacks-datascience",
"path_to_docs": "docs",
# "repository_branch": "master",
# "selector": ".thebe",
# "selector_input": ,
# "selector_output": ,
# "codemirror-theme": "blackboard" # Doesn't currently work
}

myst_admonition_enable = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
extensions = ["sphinx_conditional_asset", "myst_parser"]
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
Expand All @@ -96,7 +52,7 @@
"path_to_docs": "docs",
"use_repository_button": True,
"use_issues_button": True,
"single_page": True
"single_page": True,
}


Expand Down Expand Up @@ -169,6 +125,7 @@ def check_pages(app, pagename, templatename, context, doctree):
if pagename not in ["contribute"]:
return True


def setup(app):
app.add_js_file("https://google.js", condition=check_pages)
app.add_js_file("hi.js")
app.add_js_file("hi.js")
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
classifiers=["License :: OSI Approved :: MIT License"],
install_requires=["sphinx>=2"],
extras_require={
"sphinx": [
"myst-parser[sphinx]",
"sphinx-book-theme",
],
"sphinx": ["myst-parser[sphinx]", "sphinx-book-theme",],
"testing": ["pytest", "beautifulsoup4"],
},
)
12 changes: 9 additions & 3 deletions sphinx_conditional_asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
__version__ = "0.0.1"


def add_js_file_conditional(self, filename: str, condition: [Callable, None], **kwargs) -> None:
def add_js_file_conditional(
self, filename: str, condition: [Callable, None], **kwargs
) -> None:
"""Conditionally add a js file if `condition` returns True for a page.
Overrides the Sphinx `add_js_file` and adds an extra `condition` kwarg.
Expand All @@ -17,7 +19,9 @@ def add_js_file_conditional(self, filename: str, condition: [Callable, None], **
self.config.conditional_script_files[filename] = condition


def add_css_file_conditional(self, filename: str, condition: [Callable, None], **kwargs) -> None:
def add_css_file_conditional(
self, filename: str, condition: [Callable, None], **kwargs
) -> None:
"""Conditionally add a css file if `condition` returns True for a page.
Overrides the Sphinx `add_css_file` and adds an extra `condition` kwarg.
Expand All @@ -30,7 +34,9 @@ def check_conditional_assets(app, pagename, templatename, context, doctree):
"""Loop through any conditional assets and exclude if needed."""
for path, condition in app.config.conditional_script_files.items():
if not condition(app, pagename, templatename, context, doctree):
context["script_files"] = [ii for ii in context["script_files"] if path not in ii]
context["script_files"] = [
ii for ii in context["script_files"] if path not in ii
]

for path, condition in app.config.conditional_css_files.items():
if not condition(app, pagename, templatename, context, doctree):
Expand Down
26 changes: 7 additions & 19 deletions tests/sites/base/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,10 @@ def only_on_some_pages(app, pagename, templatename, context, doctree):


def setup(app):
app.add_js_file_conditional(
"only_index.js",
only_with_bullet_list
)

app.add_js_file_conditional(
"only_page.js",
only_on_some_pages
)

app.add_css_file_conditional(
"only_index.css",
only_with_bullet_list
)

app.add_css_file_conditional(
"only_page.css",
only_on_some_pages
)
app.add_js_file_conditional("only_index.js", only_with_bullet_list)

app.add_js_file_conditional("only_page.js", only_on_some_pages)

app.add_css_file_conditional("only_index.css", only_with_bullet_list)

app.add_css_file_conditional("only_page.css", only_on_some_pages)
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def test_build_book(sphinx_build_factory, file_regression):

for asset in ["only_index.js", "only_index.css"]:
assert asset in str(index)
assert asset not in str(page1)
assert asset not in str(page1)

0 comments on commit d95c656

Please sign in to comment.