-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove usage of cookiecutter with copier-template-extensions
- Loading branch information
1 parent
1ec2617
commit 3176d5c
Showing
5 changed files
with
55 additions
and
6 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
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,46 @@ | ||
# copied from https://github.com/pawamoy/copier-pdm/blob/main/extensions.py | ||
# Thanks to the original author | ||
|
||
import re | ||
import subprocess | ||
import unicodedata | ||
from datetime import date | ||
|
||
from jinja2.ext import Extension | ||
|
||
|
||
def git_user_name() -> str: | ||
return subprocess.getoutput("git config user.name").strip() | ||
|
||
|
||
def git_user_email() -> str: | ||
return subprocess.getoutput("git config user.email").strip() | ||
|
||
|
||
def slugify(value, separator="-"): | ||
value = ( | ||
unicodedata.normalize("NFKD", str(value)) | ||
.encode("ascii", "ignore") | ||
.decode("ascii") | ||
) | ||
value = re.sub(r"[^\w\s-]", "", value.lower()) | ||
return re.sub(r"[-_\s]+", separator, value).strip("-_") | ||
|
||
|
||
class GitExtension(Extension): | ||
def __init__(self, environment): | ||
super().__init__(environment) | ||
environment.globals["git_user_name"] = git_user_name | ||
environment.globals["git_user_email"] = git_user_email | ||
|
||
|
||
class SlugifyExtension(Extension): | ||
def __init__(self, environment): | ||
super().__init__(environment) | ||
environment.filters["slugify"] = slugify | ||
|
||
|
||
class CurrentYearExtension(Extension): | ||
def __init__(self, environment): | ||
super().__init__(environment) | ||
environment.globals["current_year"] = date.today().year |
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