Skip to content

Commit

Permalink
list-widgets : count all the macros and not only files
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Jul 12, 2024
1 parent dd2ed79 commit f2d61d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ For each command, the option `-h` give u some help.

`./manage.py list-widgets` to list all widgets found in content directories

`./manage.py make-widgets` to make a file that groups all jinja2 widgets macros for easier includes. It is called by `runserver` and `distill-local` commands. \
`./manage.py make-widgets` to make a file that groups all jinja2 widgets macros for easier includes. It is automatically called by `runserver` and `distill-local` commands. \
See an example in `EXAMPLE.md`


Expand Down
1 change: 1 addition & 0 deletions jssg/management/commands/distill-local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
DistilllocalCommand = importlib.import_module("django_distill.management.commands.distill-local").Command
from django.core.management import call_command

#Override the default distill-local command to call the make-widget before it execute
class Command(DistilllocalCommand):
def handle(self, *args, **options):
call_command('make-widgets')
Expand Down
11 changes: 8 additions & 3 deletions jssg/management/commands/list-widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 = "List all the widgets found in content templates."
Expand All @@ -27,9 +28,13 @@ def handle(self, *args, **options) :
n = 0
for template_dir in settings.JFME_TEMPLATES_DIRS :
for widget in (template_dir / options["engine"] / "widgets").rglob("*") :
if widget.is_file() :
self.stdout.write(str(widget.relative_to(settings.BASE_DIR)))
n += 1
with open(widget, "r") as w :
self.stdout.write("In %s : " % str(widget))
i = 0
for macro in findall(r"{%[\s]*macro[\s]*(.*)\(", w.read()) :
self.stdout.write("\tmacro '%s()'" % macro)
i += 1
n += i

if n > 1 :
self.stdout.write(
Expand Down
1 change: 1 addition & 0 deletions jssg/management/commands/runserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.management.commands.runserver import Command as RunserverCommand
from django.core.management import call_command

#Override the default runserver command to call the make-widget before it execute
class Command(RunserverCommand):
def inner_run(self, *args, **options):
call_command('make-widgets')
Expand Down

0 comments on commit f2d61d2

Please sign in to comment.