Skip to content

Commit

Permalink
FEAT: apply theme structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgepiloto committed Feb 1, 2023
1 parent 814caf1 commit ef7cfb1
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 37 deletions.
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
# specify the location of your github repo
html_theme_options = {
"github_url": "https://github.com/ansys/ansys-sphinx-theme",
"use_edit_page_button": True,
"contact_mail": "pyansys.support@ansys.com",
"additional_breadcrumbs": [
("Ansys Internal Developer Portal", "https://dev.docs.ansys.com"),
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ name = "ansys_sphinx_theme"

[tool.flit.sdist]
include = [
"src/ansys_sphinx_theme/layout.html",
"src/ansys_sphinx_theme/breadcrumbs.html",
"src/ansys_sphinx_theme/docs-navbar.html",
"src/ansys_sphinx_theme/theme.conf",
"src/ansys_sphinx_theme/_templates/",
"src/ansys_sphinx_theme/static/",
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/layout.html",
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/components/breadcrumbs.html",
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/theme.conf",
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/",
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/",
]

[project.urls]
Expand Down
99 changes: 69 additions & 30 deletions src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
"""This is the ansys-sphinx-theme module."""
import os
from pathlib import Path
import pathlib
from typing import Dict

import sphinx

from ansys_sphinx_theme.latex import generate_404 # noqa: F401


__version__ = "0.9.dev0"

# get location of this directory
_this_path = os.path.dirname(os.path.realpath(__file__))

# Declare the fundamental paths of the theme
THIS_PATH = pathlib.Path(__file__).parent.resolve()
THEME_PATH = THIS_PATH / "theme" / "ansys_sphinx_theme"
STATIC_PATH = THEME_PATH / "static"
STYLE_PATH = STATIC_PATH / "css"
CSS_PATH = STYLE_PATH / "ansys_sphinx_theme.css"
TEMPLATES_PATH = THEME_PATH / "_templates"

# make logo paths available
pyansys_logo_black = os.path.join(_this_path, "static", "pyansys-logo-black-cropped.png")
pyansys_logo_white = os.path.join(_this_path, "static", "pyansys-logo-white-cropped.png")
ansys_favicon = os.path.join(_this_path, "static", "ansys-favicon.png")
ansys_logo_white = os.path.join(_this_path, "static", "ansys_logo_white.pdf")
ansys_logo_white_cropped = os.path.join(_this_path, "static", "ansys_logo_white_cropped.pdf")
watermark = os.path.join(_this_path, "static", "watermark.pdf")
ansys_logo_black = os.path.join(_this_path, "static", "ansys_logo_black_cropped.jpg")
ansys_favicon = str((STATIC_PATH / "ansys-favicon.png").absolute())
ansys_logo_black = str((STATIC_PATH / "ansys_logo_black_cropped.jpg").absolute())
ansys_logo_white = str((STATIC_PATH / "ansys_logo_white.pdf").absolute())
ansys_logo_white_cropped = str((STATIC_PATH / "ansys_logo_white_cropped.pdf").absolute())
html_logo = ansys_logo_black
page_404 = str((STATIC_PATH / "404.rst").absolute())
pyansys_logo_black = str((STATIC_PATH / "pyansys-logo-black-cropped.png").absolute())
pyansys_logo_white = str((STATIC_PATH / "pyansys-logo-white-cropped.png").absolute())
watermark = str((STATIC_PATH / "watermark.pdf").absolute())



def get_html_theme_path() -> pathlib.Path:
"""Return list of HTML theme paths.
# Enable default 404 page
page_404 = os.path.join(_this_path, "static", "404.rst")
Returns
-------
pathlib.Path
Path pointing to the installation directory of the theme.
html_logo = pyansys_logo_black
CSS_FILENAME = "ansys_sphinx_theme.css"
"""
return THEME_PATH.resolve()


def get_html_theme_path():
"""Return list of HTML theme paths."""
return Path(__file__).parents[0].absolute()
def get_version_match(semver: str) -> str:
"""Evaluate the version match for the multi-documentation.
Parameters
----------
semver : str
Semantic version number in the form of a string.
def get_version_match(semver):
"""Evaluate the version match for the multi-documentation."""
Returns
-------
str
Matching version number in the form of a string.
"""
if semver.endswith("dev0"):
return "dev"
major, minor, _ = semver.split(".")
return ".".join([major, minor])


def setup(app):
"""Connect to the sphinx theme app."""
def setup(app: sphinx.application.Sphinx) -> Dict:
"""Connect to the sphinx theme app.
Parameters
----------
app : sphinx.application.Sphinx
Application instance for rendering the documentation.
Returns
-------
Dict
Dictionary containig application status.
"""
# Add the theme configuration
theme_path = get_html_theme_path()
app.add_html_theme("ansys_sphinx_theme", theme_path)
theme_css_path = theme_path / "static" / "css" / CSS_FILENAME
if not theme_css_path.exists():
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {theme_css_path}")
app.add_css_file(str(theme_css_path.relative_to(theme_path / "static")))

# add templates for autosummary
path_templates = os.path.join(_this_path, "_templates")
app.config.templates_path.append(path_templates)
app.config.templates_path.append(str(THEME_PATH / "components"))

# Verify that the main CSS file exists
if not CSS_PATH.exists():
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {CSS_PATH.absolute()}")
app.add_css_file(str(CSS_PATH.relative_to(STATIC_PATH)))

# Add templates for autosummary
app.config.templates_path.append(str(TEMPLATES_PATH))

return {
"version": __version__,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ show_breadcrumbs = True
show_icons = True
hidden_icons =
additional_breadcrumbs =

use_edit_page_button = True
switcher =

0 comments on commit ef7cfb1

Please sign in to comment.