Skip to content

Commit

Permalink
new js file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AakashGfude committed May 2, 2021
1 parent b51dbb1 commit 5460efb
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 382 deletions.
92 changes: 23 additions & 69 deletions quantecon_book_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""A lightweight book theme based on the pydata sphinx theme."""
from pathlib import Path

from docutils.parsers.rst import directives
from docutils import nodes
from sphinx.util import logging
from bs4 import BeautifulSoup as bs
from sphinx.util.fileutil import copy_asset
from sphinx.util.osutil import ensuredir

from .launch import add_hub_urls

Expand Down Expand Up @@ -43,6 +44,26 @@ def find_url_relative_to_root(pagename, relative_page, path_docs_source):
return page_rel_root


def add_static_path(app):
"""Ensure CSS/JS is loaded."""
static_path = Path(__file__).parent.joinpath("static").absolute()
app.config.html_static_path.append(str(static_path))

# copying plugins
if "plugins_list" in app.config.html_theme_options:
outdir = app.outdir + "/plugins"
ensuredir(outdir)
for i, asset in enumerate(app.config.html_theme_options["plugins_list"]):
assetname = Path(asset).name
copy_asset(app.confdir + "/" + asset, outdir)
app.config.html_theme_options["plugins_list"][i] = "plugins/" + assetname

# Javascript
for fname in static_path.iterdir():
if ".js" in fname.suffix:
app.add_js_file(fname.name)


def add_to_context(app, pagename, templatename, context, doctree):
def sbt_generate_nav_html(
level=1,
Expand Down Expand Up @@ -239,52 +260,6 @@ def get_github_src_folder(app):
context[key] = _string_or_bool(context[key])


def update_thebe_config(app, env, docnames):
"""Update thebe configuration with SBT-specific values"""
theme_options = env.config.html_theme_options
if theme_options.get("launch_buttons", {}).get("thebe") is True:
if not hasattr(env.config, "thebe_config"):
SPHINX_LOGGER.warning(
(
"Thebe is activated but not added to extensions list. "
"Add `sphinx_thebe` to your site's extensions list."
)
)
return
# Will be empty if it doesn't exist
thebe_config = env.config.thebe_config
else:
return

if not theme_options.get("launch_buttons", {}).get("thebe"):
return

# Update the repository branch and URL
# Assume that if there's already a thebe_config, then we don't want to over-ride
if "repository_url" not in thebe_config:
thebe_config["repository_url"] = theme_options.get("repository_url")
if "repository_branch" not in thebe_config:
branch = theme_options.get("repository_branch")
if not branch:
# Explicitly check in case branch is ""
branch = "master"
thebe_config["repository_branch"] = branch

# Update the selectors to find thebe-enabled cells
selector = thebe_config.get("selector", "") + ",.cell"
thebe_config["selector"] = selector.lstrip(",")

selector_input = (
thebe_config.get("selector_input", "") + ",.cell_input div.highlight"
)
thebe_config["selector_input"] = selector_input.lstrip(",")

selector_output = thebe_config.get("selector_output", "") + ",.cell_output"
thebe_config["selector_output"] = selector_output.lstrip(",")

env.config.thebe_config = thebe_config


def _string_or_bool(var):
if isinstance(var, str):
return var.lower() == "true"
Expand All @@ -294,35 +269,14 @@ def _string_or_bool(var):
return var is None


class Margin(directives.body.Sidebar):
"""Goes in the margin to the right of the page."""

optional_arguments = 1
required_arguments = 0

def run(self):
"""Run the directive."""
if not self.arguments:
self.arguments = [""]
nodes = super().run()
nodes[0].attributes["classes"].append("margin")

# Remove the "title" node if it is empty
if not self.arguments:
nodes[0].children.pop(0)
return nodes


def setup(app):
# Configuration for Juypter Book
app.setup_extension("sphinx_book_theme")
app.connect("html-page-context", add_hub_urls)
app.connect("builder-inited", add_static_path)

app.add_html_theme("quantecon_book_theme", get_html_theme_path())
app.connect("html-page-context", add_to_context)

app.add_js_file("quantecon-book-theme.js")

return {
"parallel_read_safe": True,
"parallel_write_safe": True,
Expand Down
35 changes: 26 additions & 9 deletions quantecon_book_theme/layout.html

Large diffs are not rendered by default.

39 changes: 0 additions & 39 deletions quantecon_book_theme/static/plugins.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion quantecon_book_theme/static/quantecon-book-theme.css

This file was deleted.

223 changes: 0 additions & 223 deletions quantecon_book_theme/static/scripts.js

This file was deleted.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"libsass",
"pydata-sphinx-theme~=0.6.1",
"beautifulsoup4",
'importlib-resources>=3.0,<3.5; python_version < "3.7"',
],
extras_require={
"code_style": ["flake8<3.8.0,>=3.7.0", "black", "pre-commit~=2.7.0"],
Expand Down
Loading

1 comment on commit 5460efb

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.