Skip to content

Commit

Permalink
feat: create a new instance of material theme to keep default options
Browse files Browse the repository at this point in the history
  • Loading branch information
aladjadj committed May 22, 2022
1 parent e5a8cdc commit 106f891
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
"""

import tempfile
import logging
import os
from mkdocs.plugins import BasePlugin
from mkdocs.theme import Theme
from mkdocs.utils import warning_filter
from mkdocs.contrib.search import SearchPlugin
from mkdocs_monorepo_plugin.plugin import MonorepoPlugin
from pymdownx.emoji import to_svg

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


class TechDocsCore(BasePlugin):
def __init__(self):
Expand All @@ -44,7 +49,12 @@ def on_config(self, config):
mdx_configs_override = config["mdx_configs"].copy()

# Theme
config["theme"].name = "material"
if config["theme"].name != "material":
log.info("[mkdocs-techdocs-core] The theme has been replaced by 'material'")
log.info(
"[mkdocs-techdocs-core] Set theme.name to 'material' to override theme options"
)
config["theme"] = Theme(name="material")
config["theme"].static_templates.update({"techdocs_metadata.json"})
config["theme"].dirs.append(self.tmp_dir_techdocs_theme.name)

Expand Down
14 changes: 12 additions & 2 deletions src/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ def test_merge_default_config_and_user_config(self):
self.mkdocs_yaml_config["mdx_configs"] = {}
self.mkdocs_yaml_config["markdown_extension"].append(["toc"])
self.mkdocs_yaml_config["mdx_configs"]["toc"] = {"toc_depth": 3}
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertTrue("toc" in final_config["mdx_configs"])
self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
self.assertTrue("toc_depth" in final_config["mdx_configs"]["toc"])
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
self.assertTrue("navigation.sections" in final_config["theme"]["features"])

def test_override_default_config_with_user_config(self):
self.mkdocs_yaml_config["markdown_extension"] = []
Expand All @@ -53,6 +51,18 @@ def test_override_default_config_with_user_config(self):
self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])

def test_remove_theme_config_with_user_options(self):
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertFalse("navigation.sections" in final_config["theme"]["features"])

def test_override_theme_config_with_user_config(self):
self.mkdocs_yaml_config["theme"] = Theme(name="material")
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertTrue("navigation.sections" in final_config["theme"]["features"])


def test_template_renders__multiline_value_as_valid_json(self):
self.techdocscore.on_config(self.mkdocs_yaml_config)
env = Environment(
Expand Down

0 comments on commit 106f891

Please sign in to comment.