|
2 | 2 | from django.core.management import call_command |
3 | 3 | from django.core.management.base import BaseCommand |
4 | 4 | from jinja2.nodes import Macro |
5 | | - |
6 | | -from jssg.jinja2 import Environment |
| 5 | +from django.template import engines |
7 | 6 |
|
8 | 7 |
|
9 | 8 | class Command(BaseCommand): |
@@ -46,31 +45,36 @@ def handle(self, *args, **options): |
46 | 45 | nb_file_found = 0 |
47 | 46 | nb_macro_found = 0 |
48 | 47 | visited = [] |
| 48 | + |
| 49 | + jinja_engine = engines['jinja2'] |
| 50 | + jinja2_env = jinja_engine.env |
| 51 | + |
49 | 52 | for template_dir in settings.JFME_TEMPLATES_DIRS: |
50 | 53 | for widget in (template_dir / "jinja2" / "widgets").rglob("*"): |
51 | 54 | rel_widget_path = widget.relative_to(template_dir.parent.parent) |
52 | 55 | if widget.is_file(): |
53 | 56 | with open(widget, "r") as w: |
54 | 57 | self.stdout.write("%s" % str(rel_widget_path)) |
55 | 58 | nb_file_found += 1 |
56 | | - for macro in Environment().parse(w.read()).find_all(Macro): |
| 59 | + |
| 60 | + for macro in jinja2_env.parse(w.read()).find_all(Macro): |
57 | 61 | visited.append( |
58 | 62 | (widget.stem, macro.name, rel_widget_path) |
59 | 63 | ) |
60 | 64 | self.stdout.write("\t%s()" % macro.name) |
61 | 65 | nb_macro_found += 1 |
62 | | - |
63 | 66 | self.stdout.write( |
64 | 67 | self.style.HTTP_INFO( |
65 | | - "%d jinja2 widget %s found (%d %s)" |
| 68 | + "%d jinja2 %s found in %d %s." |
66 | 69 | % ( |
67 | | - nb_file_found, |
68 | | - "file" if nb_file_found <= 1 else "files", |
69 | 70 | nb_macro_found, |
70 | 71 | "macro" if nb_file_found <= 1 else "macros", |
| 72 | + nb_file_found, |
| 73 | + "file" if nb_file_found <= 1 else "files", |
71 | 74 | ) |
72 | 75 | ) |
73 | 76 | ) |
| 77 | + |
74 | 78 | couple_visited = [(x[0], x[1]) for x in visited] |
75 | 79 | duplicates = set( |
76 | 80 | [t for t in couple_visited if couple_visited.count(t) > 1] |
|
0 commit comments