-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Properties into several files for better maintainability
- Loading branch information
1 parent
02f4f9e
commit dd54f03
Showing
7 changed files
with
373 additions
and
302 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
__all__ = [ | ||
"JINJA_NAMESPACE_ALIASES", | ||
"AnimatedTexturesProps", | ||
"AnimationFormat", | ||
"BaseProperties", | ||
"EnvironmentVariableProps", | ||
"LangProps", | ||
"PNGTextureOverride", | ||
"Properties", | ||
"TemplateProps", | ||
"TextureTextureOverride", | ||
"TexturesProps", | ||
"env", | ||
"lang", | ||
"properties", | ||
"template", | ||
"textures", | ||
] | ||
|
||
from .env import EnvironmentVariableProps | ||
from .lang import LangProps | ||
from .properties import BaseProperties, Properties | ||
from .template import JINJA_NAMESPACE_ALIASES, TemplateProps | ||
from .textures import ( | ||
AnimatedTexturesProps, | ||
AnimationFormat, | ||
PNGTextureOverride, | ||
TexturesProps, | ||
TextureTextureOverride, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Self | ||
|
||
from pydantic import model_validator | ||
from yarl import URL | ||
|
||
from hexdoc.model.base import HexdocSettings | ||
from hexdoc.utils.types import PydanticURL | ||
|
||
|
||
class EnvironmentVariableProps(HexdocSettings): | ||
# default Actions environment variables | ||
github_repository: str | ||
github_sha: str | ||
|
||
# set by CI | ||
github_pages_url: PydanticURL | ||
|
||
# for putting books somewhere other than the site root | ||
hexdoc_subdirectory: str | None = None | ||
|
||
# optional for debugging | ||
debug_githubusercontent: PydanticURL | None = None | ||
|
||
@property | ||
def asset_url(self) -> URL: | ||
if self.debug_githubusercontent is not None: | ||
return URL(str(self.debug_githubusercontent)) | ||
|
||
return ( | ||
URL("https://raw.githubusercontent.com") | ||
/ self.repo_owner | ||
/ self.repo_name | ||
/ self.github_sha | ||
) | ||
|
||
@property | ||
def repo_owner(self): | ||
return self._github_repository_parts[0] | ||
|
||
@property | ||
def repo_name(self): | ||
return self._github_repository_parts[1] | ||
|
||
@property | ||
def _github_repository_parts(self): | ||
owner, repo_name = self.github_repository.split("/", maxsplit=1) | ||
return owner, repo_name | ||
|
||
@model_validator(mode="after") | ||
def _append_subdirectory(self) -> Self: | ||
if self.hexdoc_subdirectory: | ||
self.github_pages_url /= self.hexdoc_subdirectory | ||
return self |
Oops, something went wrong.