-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: enhance custom code & remove cli options
- Loading branch information
Showing
8 changed files
with
99 additions
and
77 deletions.
There are no files selected for viewing
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,6 @@ | ||
from .cli import main as main | ||
from .types import Data as Data | ||
from .types import ExportsTemplate as ExportsTemplate | ||
from .types import Extensions as Extensions | ||
from .types import Filters as Filters | ||
from .types import Globals as Globals |
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
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
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 @@ | ||
import typing as t | ||
from abc import ABC, abstractmethod | ||
|
||
from jinja2 import Environment | ||
from jinja2.ext import Extension | ||
|
||
ExtensionType = t.Union[Extension, str] | ||
Extensions = t.Sequence[ExtensionType] | ||
Filter = t.Callable[[t.Any], t.Any] | ||
Filters = t.Sequence[Filter] | ||
Global = t.Callable[..., t.Any] | ||
Globals = t.Sequence[Global] | ||
Data = t.Mapping[str, t.Any] | ||
|
||
|
||
class ExportsTemplate(ABC): | ||
def filters(self) -> Filters: | ||
return [] | ||
|
||
def globals(self) -> Globals: | ||
return [] | ||
|
||
def data(self) -> Data: | ||
return {} | ||
|
||
def extensions(self) -> Extensions: | ||
return [] | ||
|
||
def setup_env(self, env: Environment) -> None: | ||
pass |
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
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,25 @@ | ||
import typing as t | ||
from urllib.parse import quote as urlparse | ||
|
||
from makejinja import Filters, Globals | ||
|
||
|
||
def hassurl(value: str) -> str: | ||
return urlparse(value).replace("_", "-") | ||
|
||
|
||
def getlang( | ||
value: t.Union[str, t.Mapping[str, t.Any]], lang: str, default_lang: str = "en" | ||
): | ||
if isinstance(value, str): | ||
return value | ||
else: | ||
return value.get(lang, value.get(default_lang, "")) | ||
|
||
|
||
class Exports: | ||
def filters(self) -> Filters: | ||
return [hassurl] | ||
|
||
def globals(self) -> Globals: | ||
return [getlang] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.