Skip to content

Commit

Permalink
Merge pull request #88 from braingram/no_bootstrap
Browse files Browse the repository at this point in the history
Fix current version breaking side menu (remove bootstrap, custom css, custom js, custom template)
  • Loading branch information
braingram authored Jan 25, 2024
2 parents fd4417e + 23433fc commit 4da23f2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 124 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies = [
"packaging",
"sphinx",
"sphinx-astropy",
"sphinx_bootstrap_theme",
"sphinx-rtd-theme",
"toml",

Expand Down
4 changes: 0 additions & 4 deletions sphinx_asdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from .connections import (
add_labels_to_nodes,
autogenerate_schema_docs,
handle_page_context,
on_build_finished,
update_app_config,
)
from .directives import AsdfAutoschemas, AsdfSchema
Expand All @@ -27,9 +25,7 @@ def setup(app):

app.connect("builder-inited", autogenerate_schema_docs)
app.connect("config-inited", update_app_config)
app.connect("html-page-context", handle_page_context)
app.connect("doctree-read", add_labels_to_nodes)
app.connect("build-finished", on_build_finished)

static_dir = os.path.join(os.path.dirname(__file__), "static")

Expand Down
19 changes: 0 additions & 19 deletions sphinx_asdf/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
from docutils import nodes
from sphinx.util import rst
from sphinx.util.docutils import sphinx_domains
from sphinx.util.fileutil import copy_asset

from .directives import schema_def
from .nodes import schema_doc

TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "templates")

# docutils 0.19.0 fixed a bug in traverse/findall
# https://sourceforge.net/p/docutils/bugs/448/
Expand Down Expand Up @@ -119,13 +115,6 @@ def update_app_config(app, config):
config.html_context["sphinx_asdf_version"] = dist.version


def handle_page_context(app, pagename, templatename, ctx, doctree):
# Use custom template when rendering pages containing schema documentation.
# This allows us to selectively include bootstrap
if doctree is not None and traverse(doctree, schema_doc):
return os.path.join(TEMPLATE_PATH, "schema.html")


def normalize_name(name):
for char in [".", "_", "/"]:
name = name.replace(char, "-")
Expand Down Expand Up @@ -154,11 +143,3 @@ def add_labels_to_nodes(app, document):
anonlabels[name] = docname, labelid
# labelname -> docname, labelid, sectionname
labels[name] = docname, labelid, ""


def on_build_finished(app, exc):
if exc is None:
for asset in ["sphinx_asdf.css", "sphinx_asdf.js"]:
src = posixpath.join(posixpath.dirname(__file__), "static", asset)
dst = posixpath.join(app.outdir, "_static")
copy_asset(src, dst)
28 changes: 14 additions & 14 deletions sphinx_asdf/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run(self):
return [docnodes]

def _create_toc(self, schema):
toc = nodes.compound()
toc = nodes.bullet_list()
toc.append(toc_link(text=SCHEMA_DEF_SECTION_TITLE))
if "examples" in schema:
toc.append(toc_link(text=EXAMPLE_SECTION_TITLE))
Expand Down Expand Up @@ -226,7 +226,7 @@ def _create_ref_node(self, ref):

def _create_enum_node(self, enum_values):
enum_nodes = nodes.compound()
enum_nodes.append(nodes.line(text="Only the following values are valid for this node:"))
enum_nodes.append(nodes.paragraph(text="Only the following values are valid for this node:"))
markdown = "\n".join([f"* **{val}**" for val in enum_values])
enum_nodes.extend(self._markdown_to_nodes(markdown, ""))
return enum_nodes
Expand All @@ -240,14 +240,14 @@ def _create_array_items_node(self, items, path):
node_list = nodes.compound()
if isinstance(items, list):
text = "The first {} item{} in the list must be the following types:"
node_list.append(nodes.line(text=text.format(len(items), "s" if len(items) > 1 else "")))
node_list.append(nodes.paragraph(text=text.format(len(items), "s" if len(items) > 1 else "")))
item_list = nodes.bullet_list()
for i, it in enumerate(items):
item_path = self._append_to_path(path, i)
item_list.append(self._process_properties(it, top=True, path=item_path))
node_list.append(item_list)
else:
node_list.append(nodes.line(text="Items in the array are restricted to the following types:"))
node_list.append(nodes.paragraph(text="Items in the array are restricted to the following types:"))
node_list.append(self._process_properties(items, top=True, path=path))
return node_list

Expand All @@ -260,21 +260,21 @@ def _process_validation_keywords(self, schema, typename=None, path=""):
node_list.append(nodes.emphasis(text="No length restriction"))
if schema.get("minLength", 0):
text = f"Minimum length: {schema['minLength']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
if "maxLength" in schema:
text = f"Maximum length: {schema['maxLength']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
if "pattern" in schema:
node_list.append(nodes.line(text="Must match the following pattern:"))
node_list.append(nodes.paragraph(text="Must match the following pattern:"))
node_list.append(nodes.literal_block(text=schema["pattern"], language="none"))

elif typename == "array":
if schema.get("minItems", 0):
text = f"Minimum length: {schema['minItems']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
if "maxItems" in schema:
text = f"Maximum length: {schema['maxItems']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
if "additionalItems" in schema and "items" in schema:
if isinstance(schema["items"], list) and schema["additionalItems"] is False:
node_list.append(nodes.emphasis(text="Additional items not permitted"))
Expand All @@ -288,10 +288,10 @@ def _process_validation_keywords(self, schema, typename=None, path=""):
elif typename in ["integer", "number"]:
if "minimum" in schema:
text = f"Minimum value: {schema['minimum']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
if "maximum" in schema:
text = f"Maximum value: {schema['maximum']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))

if "enum" in schema:
node_list.append(self._create_enum_node(schema["enum"]))
Expand All @@ -303,10 +303,10 @@ def _process_validation_keywords(self, schema, typename=None, path=""):
else:
default = schema["default"]
text = f"Default value: {default}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))
else:
default_node = nodes.compound()
default_node.append(nodes.line(text="Default value:"))
default_node.append(nodes.paragraph(text="Default value:"))
default_node.append(nodes.literal_block(text=pformat(schema["default"]), language="none"))
node_list.append(default_node)

Expand Down Expand Up @@ -338,7 +338,7 @@ def _process_properties(self, schema, top=False, path=""):
for key, node in schema["properties"].items():
new_path = self._append_to_path(path, key)
treenodes.append(self._create_property_node(key, node, key in required, path=new_path))
comment = nodes.line(text="This type is an object with the following properties:")
comment = nodes.paragraph(text="This type is an object with the following properties:")
return schema_properties(None, *[comment, treenodes], id=path)
elif "type" in schema:
details = self._process_top_type(schema, path=path)
Expand Down
38 changes: 16 additions & 22 deletions sphinx_asdf/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ def depart_html(self, node):

class schema_title(nodes.compound):
def visit_html(self, node):
self.body.append(r'<div class="schema_title">')
self.body.append(r'<div class="schema-title">')

def depart_html(self, node):
self.body.append(r"</div>")


class toc_link(nodes.line):
class toc_link(nodes.bullet_list):
def visit_html(self, node):
text = node[0].title()
self.body.append(f'<a class="toc-link" href="#{text}">')
self.body.append(f'<li><a class="toc-link" href="#{node["text"]}">{node["text"]}')

def depart_html(self, node):
self.body.append("</a>")
self.body.append("</a></li>")


class schema_header_title(nodes.line):
Expand All @@ -42,15 +41,15 @@ def depart_html(self, node):

class schema_description(nodes.compound):
def visit_html(self, node):
self.body.append(r'<div class="property_description"')
self.body.append(r'<div class="property-description">')

def depart_html(self, node):
self.body.append(r"</div>")


class section_header(nodes.line):
def visit_html(self, node):
self.body.append(r'<h3 class="section-header">')
self.body.append(r"<h3>")

def depart_html(self, node):
self.body.append(headerlink_template.format(name=node[0].title(), title=""))
Expand All @@ -59,26 +58,26 @@ def depart_html(self, node):

class schema_properties(nodes.compound):
def visit_html(self, node):
self.body.append(r'<div class="schema_properties" id="{}">'.format(node.get("id")))
self.body.append(r'<div class="schema-properties" id="{}">'.format(node.get("id")))

def depart_html(self, node):
self.body.append(r"</div>")


class schema_property(nodes.compound):
def visit_html(self, node):
self.body.append(r'<li class="list-group-item" id="{}">'.format(node.get("id")))
self.body.append(r'<li class="schema-property" id="{}">'.format(node.get("id")))

def depart_html(self, node):
self.body.append(r"</li>")


class schema_property_name(nodes.line):
def visit_html(self, node):
self.body.append(r'<div class="schema_property_name">')
self.body.append(r'<div class="schema-property-name"><h4>')

def depart_html(self, node):
self.body.append(r"</div>")
self.body.append(r"</h4></div>")


class schema_property_details(nodes.compound):
Expand All @@ -99,15 +98,15 @@ def depart_html(self, node):

class asdf_tree(nodes.bullet_list):
def visit_html(self, node):
self.body.append(r'<ul class="list-group">')
self.body.append(r'<ul class="asdf-tree">')

def depart_html(self, node):
self.body.append(r"</ul>")


class asdf_ref(nodes.line):
def visit_html(self, node):
self.body.append(f"<a class=\"asdf_ref\" href=\"{node.get('href')}\">")
self.body.append(f'<a class="asdf-ref" href="{node.get("href")}">')

def depart_html(self, node):
self.body.append(r"</a>")
Expand All @@ -123,7 +122,7 @@ def depart_html(self, node):

class example_item(nodes.compound):
def visit_html(self, node):
self.body.append(r'<div class="item example-item">')
self.body.append(r'<div class="example-item">')

def depart_html(self, node):
self.body.append(r"</div>")
Expand All @@ -140,14 +139,9 @@ def depart_html(self, node):
class schema_combiner_body(nodes.compound):
def visit_html(self, node):
self.body.append(
"""
<button class="btn btn-primary" data-toggle="collapse" href="#{0}" aria-expanded="false">
<span class="hidden">Hide </span>Details
</button>
<div class="collapse" id="{0}">
""".format(
node.get("path")
)
f"""
<div class="combiner-body" id="{node.get('path')}">
"""
)

def depart_html(self, node):
Expand Down
48 changes: 0 additions & 48 deletions sphinx_asdf/static/sphinx_asdf.css

This file was deleted.

Empty file removed sphinx_asdf/static/sphinx_asdf.js
Empty file.
16 changes: 0 additions & 16 deletions sphinx_asdf/templates/schema.html

This file was deleted.

0 comments on commit 4da23f2

Please sign in to comment.