Coverage for website/builder/templates.py: 100%
14 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:03 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:03 +0000
1"""
2Template Operations - Template Loading and Processing.
4This module handles template loading, placeholder replacement,
5and template-related operations for the website builder.
6"""
8from pathlib import Path
11class TemplateProcessor:
12 """Handles template loading and processing operations."""
14 def __init__(self, templates_dir: str = "website/templates"):
15 """Initialize template processor."""
16 self.templates_dir = Path(templates_dir)
18 def load_template(self, template_name: str) -> str:
19 """Load a template file."""
20 template_path = self.templates_dir / template_name
21 if not template_path.exists():
22 raise FileNotFoundError(f"Template not found: {template_path}")
24 with open(template_path, encoding="utf-8") as f:
25 return f.read()
27 def replace_placeholders(self, content: str, replacements: dict[str, str]) -> str:
28 """Replace placeholders in content with actual values."""
29 for placeholder, value in replacements.items():
30 content = content.replace(f"{{{{ {placeholder} }}}}", str(value))
31 return content