Skip to content

Commit

Permalink
feat: add nerd fonts for autoapi templates icon (#362)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
Co-authored-by: Jorge Martínez <[email protected]>
  • Loading branch information
3 people authored May 14, 2024
1 parent f7574dc commit 5963f20
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/362.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: add nerd fonts for ``autoapi`` templates icon
4 changes: 3 additions & 1 deletion doc/source/user_guide/autoapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you are using a ``pyproject.toml`` file, you would define your dependency as
"ansys-sphinx-theme[autoapi]==X.Y.Z",
]
Configuring our Sphinx project
Configuring the Sphinx project
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To use ``sphinx-autoapi`` with the ``ansys-sphinx-theme``, and benefit from the shipped
Expand Down Expand Up @@ -71,3 +71,5 @@ do so by modifying the configuration above. The line of code declaring the desir
.. code:: python
autoapi_template_dir = get_autoapi_templates_dir_relative_path(Path(__file__))
3 changes: 2 additions & 1 deletion doc/styles/config/vocabularies/ANSYS/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ html_context
autoapi
(?i)HTML
CSS
PDF
PDF
namespaces
36 changes: 33 additions & 3 deletions src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ def get_autoapi_templates_dir_relative_path(path: pathlib.Path) -> str:
----------
path : pathlib.Path
Path to the desired file.
Returns
-------
str
A string rerpesenting the relative path to the autoapi templates.
"""
return os.path.relpath(
str(AUTOAPI_TEMPLATES_PATH.absolute()), start=str(path.parent.absolute())
Expand Down Expand Up @@ -372,6 +370,36 @@ def download_file(url: str, directory: pathlib.Path) -> None:
file.write(response.content)


def replace_html_tag(app, exception):
"""Replace HTML tags in the generated HTML files.
Parameters
----------
app : ~sphinx.application.Sphinx
Application instance for rendering the documentation.
exception : Exception
Exception that occurred during the build process.
"""
if exception is not None:
return

build_dir = pathlib.Path(app.builder.outdir).resolve()
if app.config["extensions"] and "autoapi.extension" not in app.config["extensions"]:
return
api_dir = app.config["autoapi_root"]
api_path = build_dir / api_dir
if not api_path.exists():
return

file_names = list(api_path.rglob("*.html"))
for file_name in file_names:
with open(api_dir / file_name, "r", encoding="utf-8") as file:
content = file.read()
with open(api_dir / file_name, "w", encoding="utf-8") as file:
modified_content = content.replace("&lt;", "<").replace("&gt;", ">")
file.write(modified_content)


def setup(app: Sphinx) -> Dict:
"""Connect to the Sphinx theme app.
Expand Down Expand Up @@ -399,12 +427,14 @@ def setup(app: Sphinx) -> Dict:
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {CSS_PATH.absolute()}")
app.add_css_file(str(CSS_PATH.relative_to(STATIC_PATH)))
app.add_js_file(str(JS_FILE.relative_to(STATIC_PATH)))
app.config.templates_path.append(str(TEMPLATES_PATH))
app.add_js_file("https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js")
app.add_css_file("https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css")
app.connect("html-page-context", update_footer_theme)
app.connect("html-page-context", fix_edit_html_page_context)
app.connect("html-page-context", add_cheat_sheet)
app.config.templates_path.append(str(TEMPLATES_PATH))
app.add_css_file("https://www.nerdfonts.com/assets/css/webfont.css")
app.connect("build-finished", replace_html_tag)
return {
"version": __version__,
"parallel_read_safe": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ to interact with them programmatically.

{% for page in pages %}
{% if (page.top_level_object or page.name.split('.') | length == 3) and page.display %}
🖿 {{ page.name }}<{{ page.include_path }}>
<span class="nf nf-md-package"></span> {{ page.name }}<{{ page.include_path }}>
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:hidden:

{% for obj in objects_list %}
{{ icon }} {{ obj.short_name }}<{{ obj.include_path }}>
<span class="{{ icon }}"></span> {{ obj.short_name }}<{{ obj.include_path }}>
{% endfor %}
{%- endmacro %}

Expand Down Expand Up @@ -165,45 +165,45 @@ Summary

{% block subpackages %}
{% if visible_subpackages %}
{{ toctree_from_objects_list(visible_subpackages, "🖿") }}
{{ toctree_from_objects_list(visible_subpackages, "nf nf-md-package") }}
{% endif %}
{% endblock %}

{% block submodules %}
{% if visible_submodules %}
{{ toctree_from_objects_list(visible_submodules, "🗎") }}
{{ toctree_from_objects_list(visible_submodules, "nf nf-fa-file") }}
{% endif %}
{% endblock %}

{% block class %}
{% if own_page_types and "class" in own_page_types %}
{% if visible_interfaces %}
{{ toctree_from_objects_list(visible_interfaces, "🝆") }}
{{ toctree_from_objects_list(visible_interfaces, "nf nf-cod-symbol_interface") }}
{% endif %}

{% if visible_classes %}
{{ toctree_from_objects_list(visible_classes, "🝆") }}
{{ toctree_from_objects_list(visible_classes, "nf nf-cod-symbol_class") }}
{% endif %}

{% if visible_enums %}
{{ toctree_from_objects_list(visible_enums, "") }}
{{ toctree_from_objects_list(visible_enums, "nf nf-cod-symbol_enum") }}
{% endif %}

{% if visible_exceptions %}
{{ toctree_from_objects_list(visible_exceptions, "🗲") }}
{{ toctree_from_objects_list(visible_exceptions, "nf nf-md-lightning_bolt") }}
{% endif %}
{% endif %}
{% endblock %}

{% block functions %}
{% if own_page_types and visible_functions and "function" in own_page_types %}
{{ toctree_from_objects_list(visible_functions, "𝑓(x)") }}
{{ toctree_from_objects_list(visible_functions, "nf nf-md-function_variant") }}
{% endif %}
{% endblock %}

{% block constants %}
{% if own_page_types and visible_constants and "constant" in own_page_types %}
{{ toctree_from_objects_list(visible_constants, "π") }}
{{ toctree_from_objects_list(visible_constants, "nf nf-cod-symbol_constant") }}
{% endif %}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion src/ansys_sphinx_theme/theme/ansys_sphinx_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ article_header_start = breadcrumbs.html
footer_end = theme-version.html
pygment_light_style = friendly
pygment_dark_style = monokai
cheatsheet =
cheatsheet =

0 comments on commit 5963f20

Please sign in to comment.