MCPcopy Create free account
hub / github.com/HzaCode/OneCite / load_template

Method load_template

onecite/core.py:79–103  ·  view source on GitHub ↗

Load a YAML template by name, falling back to defaults. Args: template_name: The stem name of the template file (without the ``.yaml`` extension), e.g. ``"journal_article_full"``. Returns: A dictionary describing the template with keys ``name

(self, template_name: str)

Source from the content-addressed store, hash-verified

77 self.templates_dir = templates_dir
78
79 def load_template(self, template_name: str) -> Dict[str, Any]:
80 """Load a YAML template by name, falling back to defaults.
81
82 Args:
83 template_name: The stem name of the template file (without
84 the ``.yaml`` extension), e.g. ``"journal_article_full"``.
85
86 Returns:
87 A dictionary describing the template with keys ``name``,
88 ``entry_type``, and ``fields``. The template provides a
89 fallback entry type when auto-detection is inconclusive.
90 """
91 template_path = os.path.join(self.templates_dir, f"{template_name}.yaml")
92
93 if not os.path.exists(template_path):
94 return self._get_default_template()
95
96 try:
97 with open(template_path, 'r', encoding='utf-8') as f:
98 template = yaml.safe_load(f)
99 self.logger.info(f"Successfully loaded template: {template_name}")
100 return template
101 except Exception as e:
102 self.logger.error(f"Failed to load template {template_name}: {str(e)}")
103 return self._get_default_template()
104
105 def _get_default_template(self) -> Dict[str, Any]:
106 """Return default journal_article template"""

Calls 1

_get_default_templateMethod · 0.95