Skip to content

Commit

Permalink
feat: Move static resource to share themes
Browse files Browse the repository at this point in the history
- Refs: #25, #149
  • Loading branch information
attakei committed Jan 27, 2024
1 parent 59c11d0 commit a21d8e6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from urllib.parse import urljoin

from sphinx_revealjs.themes import get_revealjs_path
from sphinx_revealjs.utils import get_revealjs_path

# -- Project information -----------------------------------------------------
project = "sphinx-revealjs"
Expand Down
4 changes: 2 additions & 2 deletions doc/tips/create-custom-theme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Compile source.
from pathlib import Path
import sass
from sphinx_revealjs.themes import get_revealjs_path
from sphinx_revealjs.utils import get_revealjs_path
source = Path("_sass/custom.scss").read_text()
css = sass.compile(
Expand Down Expand Up @@ -77,7 +77,7 @@ You can use `sphinxcontrib-sass`_ to simplify.
.. code-block:: python
# conf.py
from sphinx_revealjs.themes import get_revealjs_path
from sphinx_revealjs.utils import get_revealjs_path
extensions = [
# .. Your extensions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ name = "sphinx_revealjs"
include = [
"demo",
"doc",
"sphinx_revealjs/themes/sphinx_revealjs/static/revealjs/",
"sphinx_revealjs/_static/revealjs/",
"tests",
"tools",
]
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion sphinx_revealjs/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sphinx_revealjs.writers import RevealjsSlideTranslator

from .contexts import RevealjsPlugin, RevealjsProjectContext
from .utils import static_resource_uri
from .utils import get_internal_static_path, static_resource_uri

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,6 +61,7 @@ def init(self): # noqa
for plugin in getattr(self.config, "revealjs_script_plugins", [])
],
)
self.config.revealjs_static_path.append(str(get_internal_static_path()))
# Hand over builder configs to html builder.
setattr(self.config, "html_static_path", self.config.revealjs_static_path)
super().init()
Expand Down
5 changes: 0 additions & 5 deletions sphinx_revealjs/themes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ def get_theme_path(name: str = DEFAULT_THEME) -> Path:
"""Return directory real path of itself."""
here = Path(__file__).parent
return here / name


def get_revealjs_path(theme_name: str = DEFAULT_THEME) -> Path:
"""Return path-object of bundled Reveal.js files."""
return get_theme_path(theme_name) / "static" / "revealjs"
10 changes: 10 additions & 0 deletions sphinx_revealjs/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""Util as functions for some modules."""
from pathlib import Path
from typing import Optional


def get_internal_static_path() -> Path: # noqa: D103
return Path(__file__).parent / "_static"


def get_revealjs_path() -> Path:
"""Return path-object of bundled Reveal.js files."""
return get_internal_static_path() / "revealjs"


def static_resource_uri(src: str, prefix: Optional[str] = None) -> str:
"""Build static path of resource."""
local_prefix = "_static" if prefix is None else prefix
Expand Down
2 changes: 1 addition & 1 deletion tools/fetch_revealjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"package/plugin": "plugin",
"package/LICENSE": "LICENSE",
},
"dest": "sphinx_revealjs/themes/sphinx_revealjs/static/revealjs",
"dest": "sphinx_revealjs/_static/revealjs",
}


Expand Down

0 comments on commit a21d8e6

Please sign in to comment.