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

Fix current version breaking side menu (remove bootstrap, custom css, custom js, custom template) #88

Merged
merged 10 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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_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:"))

Check warning on line 229 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L229

Added line #L229 was not covered by tests
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 @@
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 "")))

Check warning on line 243 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L243

Added line #L243 was not covered by tests
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:"))

Check warning on line 250 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L250

Added line #L250 was not covered by tests
node_list.append(self._process_properties(items, top=True, path=path))
return node_list

Expand All @@ -260,21 +260,21 @@
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))

Check warning on line 263 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L263

Added line #L263 was not covered by tests
if "maxLength" in schema:
text = f"Maximum length: {schema['maxLength']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))

Check warning on line 266 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L266

Added line #L266 was not covered by tests
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:"))

Check warning on line 268 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L268

Added line #L268 was not covered by tests
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))

Check warning on line 274 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L274

Added line #L274 was not covered by tests
if "maxItems" in schema:
text = f"Maximum length: {schema['maxItems']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))

Check warning on line 277 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L277

Added line #L277 was not covered by tests
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 @@
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))

Check warning on line 291 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L291

Added line #L291 was not covered by tests
if "maximum" in schema:
text = f"Maximum value: {schema['maximum']}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))

Check warning on line 294 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L294

Added line #L294 was not covered by tests

if "enum" in schema:
node_list.append(self._create_enum_node(schema["enum"]))
Expand All @@ -303,10 +303,10 @@
else:
default = schema["default"]
text = f"Default value: {default}"
node_list.append(nodes.line(text=text))
node_list.append(nodes.paragraph(text=text))

Check warning on line 306 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L306

Added line #L306 was not covered by tests
else:
default_node = nodes.compound()
default_node.append(nodes.line(text="Default value:"))
default_node.append(nodes.paragraph(text="Default value:"))

Check warning on line 309 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L309

Added line #L309 was not covered by tests
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 @@
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:")

Check warning on line 341 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L341

Added line #L341 was not covered by tests
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 @@

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">')

Check warning on line 20 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L20

Added line #L20 was not covered by tests

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"]}')

Check warning on line 28 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L28

Added line #L28 was not covered by tests

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

Check warning on line 31 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L31

Added line #L31 was not covered by tests


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

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">')

Check warning on line 44 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L44

Added line #L44 was not covered by tests

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>")

Check warning on line 52 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L52

Added line #L52 was not covered by tests

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

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")))

Check warning on line 61 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L61

Added line #L61 was not covered by tests

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")))

Check warning on line 69 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L69

Added line #L69 was not covered by tests

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>')

Check warning on line 77 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L77

Added line #L77 was not covered by tests

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

Check warning on line 80 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L80

Added line #L80 was not covered by tests


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

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">')

Check warning on line 101 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L101

Added line #L101 was not covered by tests

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")}">')

Check warning on line 109 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L109

Added line #L109 was not covered by tests

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

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">')

Check warning on line 125 in sphinx_asdf/nodes.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/nodes.py#L125

Added line #L125 was not covered by tests

def depart_html(self, node):
self.body.append(r"</div>")
Expand All @@ -140,14 +139,9 @@
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.

Loading