Figma-to-HTML 에이전트 초기 커밋
- 10단계 변환 프로세스 (PROCESS.md) - 수학 공식 레퍼런스 (MATH.md, gradient_math.py) - CSS 보정 규칙 R1~R16 (RULES.md) - 작업 규율 7개 규칙 (PROCESS-CONTROL.md) - 8개 Figma 프레임 1:1 HTML 변환물 (block-tests/) - 8개 Jinja2 템플릿 staging (templates_staging/) - 변환 완료 도서관 + 디자인 인사이트 (blocks_index.md) - 사용법 가이드 (README.md) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
71
templates_staging/render.py
Normal file
71
templates_staging/render.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
Jinja2 템플릿 렌더러 — templates_staging/ 검증용.
|
||||
|
||||
사용법:
|
||||
python render.py {pattern_id} {example_suffix}
|
||||
|
||||
예:
|
||||
python render.py cards-3col-persona example
|
||||
→ templates_staging/cards-3col-persona.example.yaml 데이터로
|
||||
templates_staging/cards-3col-persona.html.j2 템플릿 렌더
|
||||
→ 결과: templates_staging/_renders/cards-3col-persona.example.html
|
||||
|
||||
python render.py cards-3col-persona example-no-photos
|
||||
→ 사진 없는 케이스 검증
|
||||
|
||||
작업 디렉토리: figma_to_html_agent/templates_staging/
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
print("yaml 미설치. pip install pyyaml")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
from jinja2 import Template
|
||||
except ImportError:
|
||||
print("jinja2 미설치. pip install jinja2")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def render(pattern_id: str, example_suffix: str = "example") -> str:
|
||||
base = Path(__file__).parent
|
||||
|
||||
template_path = base / f"{pattern_id}.html.j2"
|
||||
data_path = base / f"{pattern_id}.{example_suffix}.yaml"
|
||||
output_dir = base / "_renders"
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
output_path = output_dir / f"{pattern_id}.{example_suffix}.html"
|
||||
|
||||
if not template_path.exists():
|
||||
raise FileNotFoundError(f"템플릿 없음: {template_path}")
|
||||
if not data_path.exists():
|
||||
raise FileNotFoundError(f"데이터 없음: {data_path}")
|
||||
|
||||
with open(template_path, "r", encoding="utf-8") as f:
|
||||
template = Template(f.read())
|
||||
|
||||
with open(data_path, "r", encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
|
||||
html = template.render(**data)
|
||||
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
print(f"✓ 렌더 완료: {output_path}")
|
||||
return str(output_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
pattern_id = sys.argv[1]
|
||||
suffix = sys.argv[2] if len(sys.argv) > 2 else "example"
|
||||
render(pattern_id, suffix)
|
||||
Reference in New Issue
Block a user