Skip to content
Closed
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
49 changes: 0 additions & 49 deletions sphinx_simplepdf/builders/simplepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import subprocess
import weasyprint

import sass

from bs4 import BeautifulSoup

from sphinx import __version__
Expand Down Expand Up @@ -52,53 +50,6 @@ def __init__(self, *args, **kwargs):
}
self.app.config.html_context["spd"] = debug_sphinx

# Generate main.css
logger.info("Generating css files from scss-templates")
css_folder = os.path.join(self.app.outdir, f"_static")
scss_folder = os.path.join(
os.path.dirname(__file__), "..", "themes", "simplepdf_theme", "static", "styles", "sources"
)
sass.compile(
dirname=(scss_folder, css_folder),
output_style="nested",
custom_functions={
sass.SassFunction("config", ("$a", "$b"), self.get_config_var),
sass.SassFunction("theme_option", ("$a", "$b"), self.get_theme_option_var),
},
)

def get_config_var(self, name, default):
"""
Gets a config variables for scss out of the Sphinx configuration.
If name is not found in config, the specified default var is returned.

Args:
name: Name of the config var to use
default: Default value, if name can not be found in config

Returns: Value
"""
simplepdf_vars = self.app.config.simplepdf_vars
if name not in simplepdf_vars:
return default
return simplepdf_vars[name]

def get_theme_option_var(self, name, default):
"""
Gets a option variables for scss out of the Sphinx theme options.
If name is not found in theme options, the specified default var is returned.

Args:
name: Name of the option var to use
default: Default value, if name can not be found in config

Returns: Value
"""
simplepdf_theme_options = self.app.config.simplepdf_theme_options
if name not in simplepdf_theme_options:
return default
return simplepdf_theme_options[name]

def finish(self) -> None:
super().finish()

Expand Down
41 changes: 34 additions & 7 deletions sphinx_simplepdf/themes/simplepdf_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
"""Sphinx ReadTheDocs theme.
From https://github.com/ryan-roemer/sphinx-bootstrap-theme.
"""
import logging
from os import path

import sass
from sphinx.application import Sphinx

__version__ = '0.1.0'
__version_full__ = __version__

logger = logging.getLogger(__name__)

def get_html_theme_path():
"""Return list of HTML theme paths."""
cur_dir = path.abspath(path.dirname(path.dirname(__file__)))
return cur_dir

def get_html_theme_path() -> str:
return path.abspath(path.dirname(__file__))


def compile_css(app: Sphinx):
# Generate main.css
logger.info("Generating css files from scss-templates")
css_folder = path.join(app.outdir, f"_static")
scss_folder = path.join(get_html_theme_path(), "static", "styles", "sources")

sass.compile(
dirname=(scss_folder, css_folder),
output_style="nested",
custom_functions={
sass.SassFunction(
"config",
("$a", "$b"),
app.config.simplepdf_vars.get
),
sass.SassFunction(
"theme_option",
("$a", "$b"),
app.config.simplepdf_theme_options.get
),
},
)


# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
app.add_html_theme('simplepdf_theme', path.abspath(path.dirname(__file__)))
# app.add_css_file('styles/main.css')
def setup(app: Sphinx):
app.add_html_theme('simplepdf_theme', get_html_theme_path())
app.connect('builder-inited', compile_css)

return {
"parallel_read_safe": True,
Expand Down