models.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. Data models and structures for the CLI application.
  3. Contains classes that represent boilerplate information and other data structures.
  4. """
  5. from pathlib import Path
  6. from typing import Any, Dict, List
  7. class Boilerplate:
  8. """Data class for boilerplate information extracted from frontmatter."""
  9. def __init__(self, file_path: Path, frontmatter_data: Dict[str, Any], content: str):
  10. self.file_path = file_path
  11. self.content = content
  12. # Extract frontmatter fields with defaults
  13. self.name = frontmatter_data.get('name', file_path.stem)
  14. self.description = frontmatter_data.get('description', 'No description available')
  15. self.author = frontmatter_data.get('author', '')
  16. self.date = frontmatter_data.get('date', '')
  17. self.version = frontmatter_data.get('version', '')
  18. self.module = frontmatter_data.get('module', '')
  19. self.tags = frontmatter_data.get('tags', [])
  20. self.files = frontmatter_data.get('files', [])
  21. # Additional computed properties
  22. self.relative_path = file_path.name
  23. self.size = file_path.stat().st_size if file_path.exists() else 0
  24. def to_dict(self) -> Dict[str, Any]:
  25. """Convert to dictionary for display."""
  26. return {
  27. 'name': self.name,
  28. 'description': self.description,
  29. 'author': self.author,
  30. 'date': self.date,
  31. 'version': self.version,
  32. 'module': self.module,
  33. 'tags': self.tags,
  34. 'files': self.files,
  35. 'path': str(self.relative_path),
  36. 'size': f"{self.size:,} bytes"
  37. }