Skip to main content

Template

Template data models for spec-kit

Overview​

These models define the structure for granular template management, supporting Jinja2 template processing with state transitions and validation.

Classes​

GranularTemplate​

Represents individual Jinja2 templates with one-to-one file mapping

Dataclass

Purpose: Manages individual templates through their processing lifecycle from discovery to final file creation with validation and state tracking.

Methods​

from_dict​
from_dict(data: Dict[str, Any]) -> 'GranularTemplate'

Create instance from dictionary

Parameters:

  • data (Dict, required)

Returns: GranularTemplate

is_ai_specific_for​
is_ai_specific_for(self, ai_assistant: str) -> bool

Check if template is compatible with given AI assistant

Parameters:

  • ai_assistant (str, required)

Returns: bool

mark_error​
mark_error(self, error_message: str) -> None

Mark template as having an error, preserving current state

Parameters:

  • error_message (str, required)
to_dict​
to_dict(self) -> Dict[str, Any]

Convert to dictionary for serialization/logging

Returns: Dict

transition_to_loaded​
transition_to_loaded(self, template_object: Any) -> None

Transition to LOADED state with Jinja2 template object

Parameters:

  • template_object (Any, required)
transition_to_rendered​
transition_to_rendered(self, content: str) -> None

Transition to RENDERED state with generated content

Parameters:

  • content (str, required)
transition_to_written​
transition_to_written(self) -> None

Transition to WRITTEN state after file creation

TemplatePackage​

Collection of templates for a specific initialization

Dataclass

Purpose: Organizes and manages the complete set of templates needed for project initialization with dependency management.

Methods​

from_dict​
from_dict(data: Dict[str, Any]) -> 'TemplatePackage'

Create instance from dictionary

Parameters:

  • data (Dict, required)

Returns: TemplatePackage

get_processing_order​
get_processing_order(self) -> List[specify_cli.models.template.GranularTemplate]

Get templates in dependency-resolved processing order

Returns: List

get_templates_by_category​
get_templates_by_category(self, category: specify_cli.models.template.TemplateCategory) -> List[specify_cli.models.template.GranularTemplate]

Get all templates in a specific category

Parameters:

  • category (TemplateCategory, required)

Returns: List

to_dict​
to_dict(self) -> Dict[str, Any]

Convert to dictionary for serialization

Returns: Dict