"""Laravel Blade template extractor. Moved verbatim from graphify/extract.py.""" from __future__ import annotations from pathlib import Path from graphify.extractors.base import _make_id def extract_blade(path: Path) -> dict: """Extract @include, components, and wire:click bindings from Blade templates.""" import re try: src = path.read_text(encoding="utf-8", errors="replace") except OSError: return {"error": f"cannot read {path}"} file_nid = _make_id(str(path)) nodes = [{"id": file_nid, "label": path.name, "file_type": "code", "source_file": str(path), "source_location": None}] edges = [] # @include('path.to.partial') or @include("path.to.partial") for m in re.finditer(r"@include\(['\"]([^'\"]+)['\"]", src): tgt = m.group(1).replace(".", "/") tgt_nid = _make_id(tgt) if tgt_nid not in {n["id"] for n in nodes}: nodes.append({"id": tgt_nid, "label": m.group(1), "file_type": "code", "source_file": str(path), "source_location": None}) edges.append({"source": file_nid, "target": tgt_nid, "relation": "includes", "confidence": "EXTRACTED", "confidence_score": 1.0, "source_file": str(path), "source_location": None, "weight": 1.0}) # or for m in re.finditer(r"