-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get only macros in widgets and remove allwidgets for Django (no macro…
…s in Django templates)
- Loading branch information
Clément
committed
Jul 10, 2024
1 parent
3e8c153
commit aefb850
Showing
7 changed files
with
47 additions
and
67 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
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,39 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.management import call_command | ||
from django.conf import settings | ||
from re import findall | ||
|
||
class Command(BaseCommand): | ||
help = "Make a file which contains all widgets macros for easier import in templates and pages." | ||
|
||
def handle(self, *args, **options): | ||
|
||
path = settings.BASE_DIR / "content" / "templates" / "jinja2" / "allwidgets.html" | ||
buf = "" | ||
n = 0 | ||
for template_dir in settings.JFME_TEMPLATES_DIRS : | ||
for widget in (template_dir / "jinja2" / "widgets").rglob("*") : | ||
if widget.is_file() : | ||
with open(widget, "r") as w : | ||
for macro in findall(r"{%[\s]*macro[\s\S]*%}[\s\S]*{%[\s]*endmacro[\s]*%}", w.read()) : | ||
buf += macro + "\n" | ||
n += 1 | ||
|
||
if n == 0 : | ||
self.stdout.write( | ||
"0 widget macro written" | ||
) | ||
else : | ||
path.parent.mkdir(exist_ok=True, parents=True) | ||
with open(path, "w+") as f : | ||
f.write(buf) | ||
if n == 1 : | ||
self.stdout.write( | ||
"1 widget macro written in %s" % | ||
(path.relative_to(settings.BASE_DIR)) | ||
) | ||
else : | ||
self.stdout.write( | ||
"%d widget macros written in %s" % | ||
(n, path.relative_to(settings.BASE_DIR)) | ||
) |
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