From d95a8fcc18e4cb6e1250a034e53835e79bbc48a1 Mon Sep 17 00:00:00 2001 From: object-Object Date: Sat, 26 Aug 2023 21:31:46 -0400 Subject: [PATCH] Move templates to hexdoc_templates and restructure props a bit --- doc/properties.toml | 49 ++++++++--------- doc/pyproject.toml | 18 +++---- doc/src/hexdoc/hexdoc.py | 8 +-- doc/src/hexdoc/minecraft/i18n.py | 8 +-- doc/src/hexdoc/utils/properties.py | 52 ++++++++----------- doc/src/hexdoc/utils/resource_loader.py | 2 +- .../__init__.py | 0 .../book.html.jinja | 0 .../category.html.jinja | 0 .../common/macros.html.jinja | 0 .../components/table_of_contents.html.jinja | 0 .../components/welcome.html.jinja | 0 .../entry.html.jinja | 0 .../main.css.jinja | 0 .../main.html.jinja | 0 .../_templates => hexdoc_templates}/main.js | 0 .../pages/hexcasting/brainsweep.html.jinja | 0 .../hexcasting/crafting_multi.html.jinja | 0 .../hexcasting/manual_pattern.html.jinja | 0 .../pages/hexcasting/pattern.html.jinja | 0 .../pages/patchouli/crafting.html.jinja | 0 .../pages/patchouli/image.html.jinja | 0 .../pages/patchouli/link.html.jinja | 0 .../pages/patchouli/page.html.jinja | 0 .../pages/patchouli/spotlight.html.jinja | 0 .../pages/patchouli/text.html.jinja | 0 26 files changed, 61 insertions(+), 76 deletions(-) rename doc/src/{hexdoc/_templates => hexdoc_templates}/__init__.py (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/book.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/category.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/common/macros.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/components/table_of_contents.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/components/welcome.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/entry.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/main.css.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/main.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/main.js (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/hexcasting/brainsweep.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/hexcasting/crafting_multi.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/hexcasting/manual_pattern.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/hexcasting/pattern.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/crafting.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/image.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/link.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/page.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/spotlight.html.jinja (100%) rename doc/src/{hexdoc/_templates => hexdoc_templates}/pages/patchouli/text.html.jinja (100%) diff --git a/doc/properties.toml b/doc/properties.toml index be01b395..dd5f1a98 100644 --- a/doc/properties.toml +++ b/doc/properties.toml @@ -3,6 +3,7 @@ modid = "hexcasting" book = "hexcasting:thehexbook" url = "https://gamma-delta.github.io/HexMod" +default_lang = "en_us" # top takes priority resource_dirs = [ @@ -19,34 +20,6 @@ export_dir = "src/hexdoc/_export/generated" # NOTE: "!Raw" means "don't apply variable interpolation to this value" _pattern_regex = { "!Raw" = 'make\(\s*"(?P[a-zA-Z0-9_\/]+)",\s*(?:new )?(?:ActionRegistryEntry|OperationAction)\(\s*HexPattern\.fromAngles\(\s*"(?P[aqweds]+)",\s*HexDir.(?P\w+)\)' } -entry_id_blacklist = [] - -template = "main.html.jinja" -template_dirs = [] -template_packages = [ - ["hexdoc", "_templates"], -] - -is_0_black = false - - -[template_args] -title = "Hex Book" -mod_name = "Hex Casting" -author = "petrak@, Alwinfy" -description = "The Hex Book, all in one place." -icon_href = "logo.png" -is_bleeding_edge = true -show_landing_text = true - - -[base_asset_urls] -hexcasting = "https://raw.githubusercontent.com/gamma-delta/HexMod/main/Common/src/main/resources" - - -[i18n] -default_lang = "en_us" - [[pattern_stubs]] path = "{^_common.package}/common/lib/hex/HexActions.java" @@ -57,6 +30,26 @@ path = "{^_fabric.package}/FabricHexInitializer.kt" regex = "{^_pattern_regex}" +[base_asset_urls] +hexcasting = "https://raw.githubusercontent.com/gamma-delta/HexMod/main/Common/src/main/resources" + + +[template] +main = "main.html.jinja" +packages = [ + "hexdoc_templates", +] + +[template.args] +title = "Hex Book" +mod_name = "Hex Casting" +author = "petrak@, Alwinfy" +description = "The Hex Book, all in one place." +icon_href = "logo.png" +is_bleeding_edge = true +show_landing_text = true + + # platforms [_common] diff --git a/doc/pyproject.toml b/doc/pyproject.toml index 9d25f91e..c6b2f15b 100644 --- a/doc/pyproject.toml +++ b/doc/pyproject.toml @@ -5,10 +5,10 @@ build-backend = "hatchling.build" [project] name = "hexdoc" -version = "0.1.0+0.11.1-7" # TODO: make a Hatch plugin to auto-set the mod version after the + +version = "0.11.0.1.0" # TODO: make a Hatch plugin to auto-set the mod version after the + authors = [ - { name="Alwinfy" }, { name="object-Object", email="object@objectobject.ca" }, + { name="Alwinfy" }, ] readme = "README.md" requires-python = ">=3.11" @@ -29,9 +29,16 @@ dev = [ "hatchling", ] +[tool.hatch.build] +packages = [ + "src/hexdoc", + "src/hexdoc_templates", +] + [project.scripts] hexdoc = "hexdoc.hexdoc:main" + [project.entry-points."hexdoc.export"] hexcasting = "hexdoc._export:__resources__" @@ -51,23 +58,16 @@ hexcasting = "hexdoc.hexcasting.hex_recipes" hexcasting = "hexdoc.hexcasting.hex_recipes" -[tool.hatch.build] -packages = ["src/hexdoc"] - - [tool.pytest.ini_options] addopts = ["--import-mode=importlib"] - [tool.coverage.report] include_namespace_packages = true - [tool.isort] profile = "black" combine_as_imports = true - [tool.pyright] pythonVersion = "3.11" pythonPlatform = "All" diff --git a/doc/src/hexdoc/hexdoc.py b/doc/src/hexdoc/hexdoc.py index 941fd4e9..9daa6425 100644 --- a/doc/src/hexdoc/hexdoc.py +++ b/doc/src/hexdoc/hexdoc.py @@ -98,10 +98,10 @@ def main(args: Args | None = None) -> None: env = SandboxedEnvironment( # search order: template_dirs, template_packages loader=ChoiceLoader( - [FileSystemLoader(props.template_dirs)] + [FileSystemLoader(props.template.dirs)] + [ PackageLoader(name, str(path)) - for name, path in props.template_packages + for name, path in props.template.packages ] ), undefined=StrictUndefined, @@ -118,10 +118,10 @@ def main(args: Args | None = None) -> None: } # load and render template - template = env.get_template(props.template) + template = env.get_template(props.template.main) docs = strip_empty_lines( template.render( - **props.template_args, + **props.template.args, book=book, props=props, ) diff --git a/doc/src/hexdoc/minecraft/i18n.py b/doc/src/hexdoc/minecraft/i18n.py index 39ede665..73b60ccd 100644 --- a/doc/src/hexdoc/minecraft/i18n.py +++ b/doc/src/hexdoc/minecraft/i18n.py @@ -121,10 +121,10 @@ class I18n: folder="lang", namespace="*", glob=[ - f"{props.i18n.default_lang}.json", - f"{props.i18n.default_lang}.json5", - f"{props.i18n.default_lang}.flatten.json", - f"{props.i18n.default_lang}.flatten.json5", + f"{props.default_lang}.json", + f"{props.default_lang}.json5", + f"{props.default_lang}.flatten.json", + f"{props.default_lang}.flatten.json5", ], decode=decode_and_flatten_json_dict, export=self._export, diff --git a/doc/src/hexdoc/utils/properties.py b/doc/src/hexdoc/utils/properties.py index 09e0b8c6..dc457c54 100644 --- a/doc/src/hexdoc/utils/properties.py +++ b/doc/src/hexdoc/utils/properties.py @@ -4,9 +4,9 @@ import re from pathlib import Path from typing import Annotated, Any, Self -from pydantic import AfterValidator, HttpUrl +from pydantic import AfterValidator, Field, HttpUrl, field_validator -from .model import HexDocModel, StripHiddenModel +from .model import StripHiddenModel from .resource import ResourceDir, ResourceLocation from .toml_placeholders import load_toml_with_placeholders @@ -17,56 +17,48 @@ NoTrailingSlashHttpUrl = Annotated[ ] -class HexDocMeta(HexDocModel): - book_url: NoTrailingSlashHttpUrl - - class PatternStubProps(StripHiddenModel): path: Path regex: re.Pattern[str] -class XplatProps(StripHiddenModel): - src: Path - pattern_stubs: list[PatternStubProps] | None = None - resources: Path +class TemplateProps(StripHiddenModel): + main: str + dirs: list[Path] = Field(default_factory=list) + packages: list[tuple[str, Path]] + args: dict[str, Any] + @field_validator("packages", mode="before") + def _check_packages(cls, values: Any | list[Any]): + if not isinstance(values, list): + return values -class PlatformProps(XplatProps): - recipes: Path - tags: Path - - -class I18nProps(StripHiddenModel): - default_lang: str + for i, value in enumerate(values): + if isinstance(value, str): + values[i] = (value, Path()) + return values class Properties(StripHiddenModel): modid: str book: ResourceLocation url: NoTrailingSlashHttpUrl + default_lang: str + is_0_black: bool = Field(default=False) + """If true, the style `$(0)` changes the text color to black; otherwise it resets + the text color to the default.""" resource_dirs: list[ResourceDir] export_dir: Path - entry_id_blacklist: set[ResourceLocation] + entry_id_blacklist: set[ResourceLocation] = Field(default_factory=set) - template: str - template_dirs: list[Path] - template_packages: list[tuple[str, Path]] - - is_0_black: bool - """If true, the style `$(0)` changes the text color to black; otherwise it resets - the text color to the default.""" - - template_args: dict[str, Any] + pattern_stubs: list[PatternStubProps] base_asset_urls: dict[str, NoTrailingSlashHttpUrl] """Mapping from modid to the url of that mod's `resources` directory on GitHub.""" - i18n: I18nProps - - pattern_stubs: list[PatternStubProps] + template: TemplateProps @classmethod def load(cls, path: Path) -> Self: diff --git a/doc/src/hexdoc/utils/resource_loader.py b/doc/src/hexdoc/utils/resource_loader.py index 291577bf..19611832 100644 --- a/doc/src/hexdoc/utils/resource_loader.py +++ b/doc/src/hexdoc/utils/resource_loader.py @@ -101,7 +101,7 @@ class ModResourceLoader: type="assets", folder=Path("patchouli_books") / self.props.book.path - / self.props.i18n.default_lang + / self.props.default_lang / folder, namespace=self.props.book.namespace, ) diff --git a/doc/src/hexdoc/_templates/__init__.py b/doc/src/hexdoc_templates/__init__.py similarity index 100% rename from doc/src/hexdoc/_templates/__init__.py rename to doc/src/hexdoc_templates/__init__.py diff --git a/doc/src/hexdoc/_templates/book.html.jinja b/doc/src/hexdoc_templates/book.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/book.html.jinja rename to doc/src/hexdoc_templates/book.html.jinja diff --git a/doc/src/hexdoc/_templates/category.html.jinja b/doc/src/hexdoc_templates/category.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/category.html.jinja rename to doc/src/hexdoc_templates/category.html.jinja diff --git a/doc/src/hexdoc/_templates/common/macros.html.jinja b/doc/src/hexdoc_templates/common/macros.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/common/macros.html.jinja rename to doc/src/hexdoc_templates/common/macros.html.jinja diff --git a/doc/src/hexdoc/_templates/components/table_of_contents.html.jinja b/doc/src/hexdoc_templates/components/table_of_contents.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/components/table_of_contents.html.jinja rename to doc/src/hexdoc_templates/components/table_of_contents.html.jinja diff --git a/doc/src/hexdoc/_templates/components/welcome.html.jinja b/doc/src/hexdoc_templates/components/welcome.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/components/welcome.html.jinja rename to doc/src/hexdoc_templates/components/welcome.html.jinja diff --git a/doc/src/hexdoc/_templates/entry.html.jinja b/doc/src/hexdoc_templates/entry.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/entry.html.jinja rename to doc/src/hexdoc_templates/entry.html.jinja diff --git a/doc/src/hexdoc/_templates/main.css.jinja b/doc/src/hexdoc_templates/main.css.jinja similarity index 100% rename from doc/src/hexdoc/_templates/main.css.jinja rename to doc/src/hexdoc_templates/main.css.jinja diff --git a/doc/src/hexdoc/_templates/main.html.jinja b/doc/src/hexdoc_templates/main.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/main.html.jinja rename to doc/src/hexdoc_templates/main.html.jinja diff --git a/doc/src/hexdoc/_templates/main.js b/doc/src/hexdoc_templates/main.js similarity index 100% rename from doc/src/hexdoc/_templates/main.js rename to doc/src/hexdoc_templates/main.js diff --git a/doc/src/hexdoc/_templates/pages/hexcasting/brainsweep.html.jinja b/doc/src/hexdoc_templates/pages/hexcasting/brainsweep.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/hexcasting/brainsweep.html.jinja rename to doc/src/hexdoc_templates/pages/hexcasting/brainsweep.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/hexcasting/crafting_multi.html.jinja b/doc/src/hexdoc_templates/pages/hexcasting/crafting_multi.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/hexcasting/crafting_multi.html.jinja rename to doc/src/hexdoc_templates/pages/hexcasting/crafting_multi.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/hexcasting/manual_pattern.html.jinja b/doc/src/hexdoc_templates/pages/hexcasting/manual_pattern.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/hexcasting/manual_pattern.html.jinja rename to doc/src/hexdoc_templates/pages/hexcasting/manual_pattern.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/hexcasting/pattern.html.jinja b/doc/src/hexdoc_templates/pages/hexcasting/pattern.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/hexcasting/pattern.html.jinja rename to doc/src/hexdoc_templates/pages/hexcasting/pattern.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/crafting.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/crafting.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/crafting.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/crafting.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/image.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/image.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/image.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/image.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/link.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/link.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/link.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/link.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/page.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/page.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/page.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/page.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/spotlight.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/spotlight.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/spotlight.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/spotlight.html.jinja diff --git a/doc/src/hexdoc/_templates/pages/patchouli/text.html.jinja b/doc/src/hexdoc_templates/pages/patchouli/text.html.jinja similarity index 100% rename from doc/src/hexdoc/_templates/pages/patchouli/text.html.jinja rename to doc/src/hexdoc_templates/pages/patchouli/text.html.jinja