Skip to content

Commit a6b7d82

Browse files
ver: Bump version 0.14.1
1 parent c26e3ad commit a6b7d82

File tree

9 files changed

+211
-15
lines changed

9 files changed

+211
-15
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 23.1.0
3+
rev: 24.2.0
44
hooks:
55
- id: black
66

77
- repo: https://github.com/pycqa/isort
8-
rev: 5.12.0
8+
rev: 5.13.2
99
hooks:
1010
- id: isort
1111

1212
- repo: https://github.com/PyCQA/flake8
13-
rev: 6.0.0
13+
rev: 7.0.0
1414
hooks:
1515
- id: flake8
1616

1717
- repo: https://github.com/codespell-project/codespell
18-
rev: v2.2.2
18+
rev: v2.2.6
1919
hooks:
2020
- id: codespell
2121

@@ -26,34 +26,34 @@ repos:
2626
additional_dependencies: [toml]
2727

2828
- repo: https://github.com/pre-commit/mirrors-prettier
29-
rev: 'v3.0.0-alpha.9-for-vscode'
29+
rev: 'v4.0.0-alpha.8'
3030
hooks:
3131
- id: prettier
32-
types_or: [css, javascript, html]
32+
types_or: [css, javascript]
3333

3434
- repo: https://github.com/pre-commit/pre-commit-hooks
35-
rev: v4.4.0
35+
rev: v4.5.0
3636
hooks:
3737
- id: check-merge-conflict
3838
- id: debug-statements
3939
- id: requirements-txt-fixer
4040

4141
# this validates our github workflow files
4242
- repo: https://github.com/python-jsonschema/check-jsonschema
43-
rev: 0.21.0
43+
rev: 0.28.0
4444
hooks:
4545
- id: check-github-workflows
4646

4747

4848
- repo: https://github.com/adamchainz/blacken-docs
49-
rev: 1.15.0
49+
rev: 1.16.0
5050
hooks:
5151
- id: blacken-docs
5252
additional_dependencies: [black==23.7.0]
5353
exclude: 'src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/'
5454

5555
- repo: https://github.com/ansys/pre-commit-hooks
56-
rev: v0.2.8
56+
rev: v0.2.9
5757
hooks:
5858
- id: add-license-headers
5959
args:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2023 ANSYS, Inc. and/or its affiliates.
3+
Copyright (c) 2022-2024 ANSYS, Inc. and/or its affiliates.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

doc/source/user_guide/options.rst

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GitHub repository.
5959
in the *PyData Theme* documentation.
6060
- For comprehensive information on `Font Awesome <https://fontawesome.com/>`_, an icon
6161
library and toolkit, see its `documentation <https://fontawesome.com/v6/docs>`_,
62-
particularly `How To Add Icons <https://fontawesome.com/v6/docs/web/add-icons/how-to#contentHeader>`_.
62+
particularly `How To Add Icons <https://fontawesome.com/v6/docs/web/add-icons/how-to>`_.
6363

6464
The following sections explain how you can add icons and hide icons.
6565

@@ -188,3 +188,63 @@ to provide search functionality for your documentation.
188188
If you do not set the "use_meilisearch" option,
189189
``ansys-sphinx-theme`` uses the default search functionality
190190
inherited from the PyData Sphinx Theme.
191+
192+
Cheat sheets
193+
------------
194+
195+
The ``cheatsheet`` HTML theme option can be used to enable a cheat sheet in the Ansys Sphinx theme.
196+
197+
To enable a cheatsheet, in the ``conf.py`` file for your PyAnsys
198+
library, you can add a child dictionary named ``cheatsheet`` to
199+
the ``html_theme_options`` dictionary.
200+
201+
This dictionary should contain these keys, in the order given:
202+
203+
#. ``url``: URL of the cheat sheet for downloading.
204+
#. ``title``: Title of the cheat sheet.
205+
#. ``thumbnail``: Thumbnail image for the cheat sheet.
206+
#. ``needs_download``: Whether to download the cheat sheet locally during the build. The default is ``False``, in which case the cheat sheet is accessed directly from the provided URL. If ``True``, the cheat sheet is downloaded to the ``_build/html/_static/`` directory.
207+
#. ``pages``: List of pages to include in the cheat sheet (optional). If no list is provided, the cheat sheet includes the index page of the documentation.
208+
209+
.. code-block:: python
210+
211+
html_theme_options = (
212+
{
213+
"cheatsheet": {
214+
"url": "<your cheat sheet URL>",
215+
"title": "<title of your cheat sheet>",
216+
"thumbnail": "<image URL>",
217+
"needs_download": True, # True if you want to download the cheatsheet locally in the ``_build/html/_static/`` directory.
218+
"pages": "<list of pages to include the cheat sheet on>", # Optional
219+
},
220+
},
221+
)
222+
223+
Here is an example configuration of using cheatsheet in
224+
``conf.py`` file of ``PyMAPDL``:
225+
226+
.. code-block:: python
227+
228+
html_theme_options = (
229+
{
230+
"cheatsheet": {
231+
"url": "https://cheatsheets.docs.pyansys.com/pymapdl_cheat_sheet.pdf",
232+
"title": "PyMAPDL cheatsheet",
233+
"thumbnail": "https://cheatsheets.docs.pyansys.com/pymapdl_cheat_sheet.png",
234+
"needs_download": True,
235+
"pages": ["index", "getting_started/learning"],
236+
},
237+
},
238+
)
239+
240+
.. note::
241+
242+
if you set the "needs_download" option, you should provide the "html_static_path" option
243+
in the ``conf.py`` file to specify the location of the cheat sheet.
244+
245+
for example, if you need to download cheat sheet in the ``_build/html/_static/`` directory,
246+
you should add the following line in the ``conf.py`` file:
247+
248+
.. code-block:: pycon
249+
250+
html_static_path = ["_static"]

doc/styles/Vocab/ANSYS/accept.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ link_code_library
1010
link_code_source
1111
link_code_branch
1212
html_context
13-
HTML
13+
(?!)HTML
1414
CSS
1515
PDF

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
77
name = "ansys-sphinx-theme"
8-
version = "0.14.0"
8+
version = "0.14.1"
99
description = "A theme devised by ANSYS, Inc. for Sphinx documentation."
1010
readme = "README.rst"
1111
requires-python = ">=3.9,<4"

src/ansys_sphinx_theme/__init__.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from typing import Any, Dict
2828

2929
from docutils.nodes import document
30+
import requests
3031
from sphinx import addnodes
3132
from sphinx.application import Sphinx
3233

@@ -285,8 +286,94 @@ def update_footer_theme(
285286
context["ansys_sphinx_theme_version"] = __version__
286287

287288

289+
def add_cheat_sheet(
290+
app: Sphinx, pagename: str, templatename: str, context: Dict[str, Any], doctree: document
291+
) -> None:
292+
"""Add a cheat sheet to the left navigation sidebar.
293+
294+
Parameters
295+
----------
296+
app : ~sphinx.application.Sphinx
297+
Application instance for rendering the documentation.
298+
pagename : str
299+
Name of the current page.
300+
templatename : str
301+
Name of the template being used.
302+
context : dict
303+
Context dictionary for the page.
304+
doctree : ~docutils.nodes.document
305+
The doctree.
306+
"""
307+
cheatsheet_options = app.config.html_theme_options.get("cheatsheet", {})
308+
pages = cheatsheet_options.get("pages", ["index"])
309+
pages = [pages] if isinstance(pages, str) else pages
310+
if cheatsheet_options and any(pagename == page for page in pages):
311+
if cheatsheet_options.get("needs_download"):
312+
static_folder = app.config.html_static_path or ["static"]
313+
download_cheatsheet_to_static(app, cheatsheet_options, static_folder, context)
314+
sidebar = context.get("sidebars", [])
315+
sidebar.append("cheatsheet_sidebar.html")
316+
context["sidebars"] = sidebar
317+
318+
319+
def download_cheatsheet_to_static(
320+
app: Sphinx,
321+
cheatsheet_options: Dict[str, Any],
322+
static_folder: pathlib.Path,
323+
context: Dict[str, Any],
324+
) -> None:
325+
"""Download the cheatsheet to the static directory.
326+
327+
Parameters
328+
----------
329+
app : ~sphinx.application.Sphinx
330+
Application instance for rendering the documentation.
331+
cheatsheet_options : dict
332+
Dictionary containing the cheat sheet options.
333+
static_folder : pathlib.Path
334+
Path containing the static folder.
335+
context : dict
336+
Dictionary containing the context for the page.
337+
"""
338+
cheatsheet_url = cheatsheet_options.get("url", "")
339+
cheatsheet_thumbnail = cheatsheet_options.get("thumbnail", "")
340+
static_path = pathlib.Path(app.outdir) / static_folder[0]
341+
context["cheatsheet_static_path"] = str(static_folder[0])
342+
343+
# Download cheat sheet file if URL is provided
344+
if cheatsheet_url:
345+
download_file(cheatsheet_url, static_path)
346+
347+
# Download cheat sheet image if thumbnail URL is provided
348+
if cheatsheet_thumbnail:
349+
download_file(cheatsheet_thumbnail, static_path)
350+
351+
352+
def download_file(url: str, directory: pathlib.Path) -> None:
353+
"""
354+
Download a file from the given URL and save it to a given directory.
355+
356+
Parameters
357+
----------
358+
url : str
359+
URL of the file to download.
360+
directory : pathlib.Path
361+
Directory to save the file to.
362+
"""
363+
filename = url.split("/")[-1]
364+
if not directory.exists():
365+
directory.mkdir(parents=True, exist_ok=True)
366+
if not (directory / filename).exists():
367+
file_path = directory / filename
368+
with open(file_path, "wb") as file:
369+
response = requests.get(url)
370+
if response.status_code != 200:
371+
raise FileNotFoundError(f"Failed to download file from {url}.")
372+
file.write(response.content)
373+
374+
288375
def setup(app: Sphinx) -> Dict:
289-
"""Connect to the sphinx theme app.
376+
"""Connect to the Sphinx theme app.
290377
291378
Parameters
292379
----------
@@ -316,6 +403,7 @@ def setup(app: Sphinx) -> Dict:
316403
app.add_css_file("https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css")
317404
app.connect("html-page-context", update_footer_theme)
318405
app.connect("html-page-context", fix_edit_html_page_context)
406+
app.connect("html-page-context", add_cheat_sheet)
319407
app.config.templates_path.append(str(TEMPLATES_PATH))
320408
return {
321409
"version": __version__,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% if theme_cheatsheet %}
2+
{% set theme_cheatsheet_title = theme_cheatsheet.get('title', 'Cheatsheet') %}
3+
<div class="sidebar-cheatsheets">
4+
<h4>{{ theme_cheatsheet_title }}</h4>
5+
{% if theme_cheatsheet.get('needs_download') == true %}
6+
{% set static_path = cheatsheet_static_path + '/' | default('') %}
7+
{% set theme_cheatsheet_url = theme_cheatsheet.get('url').split('/')[-1] %}
8+
{% set theme_cheatsheet_thumbnail = theme_cheatsheet.get('thumbnail').split('/')[-1] %}
9+
{% set theme_cheatsheet_thumbnail = pathto(static_path ~ theme_cheatsheet_thumbnail, 1) %}
10+
{% set theme_cheatsheet_url = pathto(static_path ~ theme_cheatsheet_url, 1) %}
11+
{% else %}
12+
{% set theme_cheatsheet_url = theme_cheatsheet.get('url') %}
13+
{% set theme_cheatsheet_thumbnail = theme_cheatsheet.get('thumbnail') %}
14+
{% endif %}
15+
<a href="{{ theme_cheatsheet_url }}">
16+
<img src="{{ theme_cheatsheet_thumbnail }}" alt="{{ theme_cheatsheet_title }}" />
17+
</a>
18+
</div>
19+
{% endif %}

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/ansys_sphinx_theme.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,31 @@ a:visited,
11331133
a:visited:hover {
11341134
color: var(--pst-color-link-visted);
11351135
}
1136+
1137+
/* Cheat sheet sidebar */
1138+
1139+
.sidebar-cheatsheets h4 {
1140+
font-weight: var(--pst-sidebar-header-font-weight) !important;
1141+
font-size: var(--pst-sidebar-header-font-size) !important;
1142+
margin-bottom: 0.5rem;
1143+
}
1144+
1145+
.sidebar-cheatsheets a {
1146+
display: inline-flex;
1147+
border: 0.5px solid var(--pst-color-border);
1148+
padding: 0.25rem;
1149+
max-width: 80%;
1150+
}
1151+
1152+
.sidebar-cheatsheets a:hover {
1153+
background-color: var(--pst-color-border);
1154+
color: var(--pst-color-text-base);
1155+
}
1156+
1157+
.sidebar-cheatsheets img {
1158+
padding: 0rem;
1159+
}
1160+
1161+
.bd-sidebar-primary {
1162+
padding: 0.5rem;
1163+
}

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/theme.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ article_header_start = breadcrumbs.html
1616
footer_end = theme-version.html
1717
pygment_light_style = friendly
1818
pygment_dark_style = monokai
19+
cheatsheet =

0 commit comments

Comments
 (0)