Skip to content

Commit 58508f9

Browse files
committed
Add first draft render_patterns management command
1 parent 1512c97 commit 58508f9

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

pattern_library/management/__init__.py

Whitespace-only changes.

pattern_library/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pathlib import Path
2+
3+
from django.core.management.base import BaseCommand
4+
from django.test.client import RequestFactory
5+
6+
from pattern_library.utils import (
7+
get_pattern_templates, render_pattern
8+
)
9+
10+
11+
class Command(BaseCommand):
12+
help = "Renders all patterns."
13+
14+
def handle(self, **options):
15+
templates = get_pattern_templates()
16+
factory = RequestFactory()
17+
request = factory.get('/')
18+
parent_dir = Path.cwd().joinpath('dpl-static')
19+
parent_dir.mkdir(exist_ok=True)
20+
self.render_group(request, parent_dir, templates)
21+
22+
def render_group(self, request, parent_dir: Path, pattern_templates):
23+
for template in pattern_templates['templates_stored']:
24+
print(template.origin.template_name)
25+
print('-------------------')
26+
render_path = parent_dir.joinpath(template.pattern_name)
27+
render_path.write_text(render_pattern(request, template.origin.template_name))
28+
29+
if not pattern_templates['template_groups']:
30+
return
31+
32+
for pattern_type_group, pattern_templates in pattern_templates['template_groups'].items():
33+
print(pattern_type_group)
34+
group_parent = parent_dir.joinpath(pattern_type_group)
35+
group_parent.mkdir(exist_ok=True)
36+
self.render_group(request, group_parent, pattern_templates)

0 commit comments

Comments
 (0)