Skip to content

Improve support for external theme packages#3

Closed
jdillard wants to merge 3 commits intomainfrom
external-theme
Closed

Improve support for external theme packages#3
jdillard wants to merge 3 commits intomainfrom
external-theme

Conversation

@jdillard
Copy link
Copy Markdown
Owner

@jdillard jdillard commented Mar 7, 2026

Summary

The SimplePdfBuilder resolves the SCSS sources folder via a hardcoded relative path to the bundled simplepdf_theme. This means anyone using the simplepdf_theme config to point at an external theme still gets SCSS compiled from the bundled theme rather than their own.

This PR adds a _resolve_scss_folder() method that dynamically imports the theme module specified by simplepdf_theme and calls its get_scss_sources_path() function to locate the SCSS sources. If the configured theme cannot be imported or doesn't define get_scss_sources_path(), the builder falls back to the bundled simplepdf_theme and emits a Sphinx typed warning (simplepdf.theme) that users can suppress via suppress_warnings.

Changes

  • Replace hardcoded SCSS path with _resolve_scss_folder() method using import-based theme discovery
  • Add get_scss_sources_path() to the bundled simplepdf_theme so it follows the same contract as external themes
  • Emit typed warnings (type="simplepdf", subtype="theme") instead of silently falling back when an external theme can't be loaded

Comparison with useblocks#91

PR #91 took a different approach: it moved SCSS compilation out of the builder and into the theme via the builder-inited event, with the goal of fully decoupling theme from builder. That approach had several issues raised in review, most notably:

  • It assumed all external themes would have a static/styles/sources/ directory with SCSS, breaking themes that only use app.add_css_file() to override styles
  • It required moving simplepdf_vars and simplepdf_theme_options registration into the theme, fragmenting configuration

This PR takes a simpler approach: keep SCSS compilation in the builder where it already lives, but make the SCSS source path resolution dynamic. Theme authors explicitly opt in by defining get_scss_sources_path() — there's no assumed directory structure and no restructuring of responsibilities. Themes that don't define it get a clear warning rather than silent breakage. I think this is the better approach since theme's with the purpose of creating PDFs are more likely to be tightly coupled with the simplePDF extension.

Backward Compatibility

This change is fully backward-compatible. When simplepdf_theme is set to the default "simplepdf_theme", the bundled theme's get_scss_sources_path() is called and resolves to the same path as before.

Refactor SCSS folder resolution to use a method that imports the theme module and retrieves the SCSS sources path, with a fallback to the bundled theme.
@jdillard jdillard mentioned this pull request Mar 9, 2026
@jdillard jdillard changed the title Support external theme packages for SCSS compilation Improve support for external theme packages Mar 10, 2026
@jdillard jdillard closed this Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant