mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-13 15:40:05 +00:00
The Blade extractor recognised @include, <livewire:> components, and
wire:click bindings, but not @extends. Template inheritance is the primary
structural relationship in a Blade view — most page templates render inside
a layout via @extends('layouts.app') — so the child was left with no edge
to its parent layout in the graph.
Emit an 'extends' edge from the view to the named layout, mirroring the
existing @include handling (dotted view name -> path). Adds the first test
coverage for the Blade extractor.
(cherry picked from commit efeeeefa53)
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
"""Extraction coverage for Laravel Blade templates."""
|
|
from __future__ import annotations
|
|
|
|
from graphify.extract import extract
|
|
|
|
|
|
def _edge_labels(result: dict, relation: str) -> set[tuple[str, str]]:
|
|
labels = {node["id"]: node["label"] for node in result["nodes"]}
|
|
return {
|
|
(labels.get(edge["source"], edge["source"]), labels.get(edge["target"], edge["target"]))
|
|
for edge in result["edges"]
|
|
if edge["relation"] == relation
|
|
}
|
|
|
|
|
|
def test_blade_extends_links_view_to_its_layout(tmp_path):
|
|
# @extends is template inheritance — the primary structural relationship in a
|
|
# Blade view. Before the fix only @include was recognised, so a page that
|
|
# extends a layout produced no edge to that layout at all.
|
|
page = tmp_path / "page.blade.php"
|
|
page.write_text(
|
|
"@extends('layouts.app')\n"
|
|
"@section('content')\n"
|
|
" @include('partials.nav')\n"
|
|
"@endsection\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
result = extract([page], cache_root=tmp_path)
|
|
|
|
assert ("page.blade.php", "layouts.app") in _edge_labels(result, "extends")
|
|
# existing @include behaviour is preserved
|
|
assert ("page.blade.php", "partials.nav") in _edge_labels(result, "includes")
|