|
15 | 15 | from dataclasses import dataclass |
16 | 16 | from pathlib import Path |
17 | 17 |
|
| 18 | +from dacli.asciidoc_parser import AsciidocDocument |
18 | 19 | from dacli.models import Document, Element, Section |
19 | 20 |
|
20 | 21 | logger = logging.getLogger(__name__) |
@@ -517,6 +518,41 @@ def stats(self) -> dict: |
517 | 518 | }, |
518 | 519 | } |
519 | 520 |
|
| 521 | + def get_dependencies(self) -> dict: |
| 522 | + """Get include dependencies across all documents. |
| 523 | +
|
| 524 | + Builds an include tree showing which files include which other files. |
| 525 | + Only AsciiDoc documents contribute (Markdown has no includes). |
| 526 | +
|
| 527 | + Returns: |
| 528 | + Dictionary with 'include_tree' (file → list of included files, |
| 529 | + paths relative to docs root) and 'cross_references' (empty list, |
| 530 | + reserved for future use). |
| 531 | + """ |
| 532 | + include_tree: dict[str, list[str]] = {} |
| 533 | + |
| 534 | + for doc in self._documents: |
| 535 | + if not isinstance(doc, AsciidocDocument) or not doc.includes: |
| 536 | + continue |
| 537 | + |
| 538 | + # Use the document's parent directory as base for relative paths |
| 539 | + docs_root = doc.file_path.parent |
| 540 | + source_key = doc.file_path.name |
| 541 | + |
| 542 | + targets = [] |
| 543 | + for inc in doc.includes: |
| 544 | + try: |
| 545 | + rel_target = inc.target_path.relative_to(docs_root) |
| 546 | + except ValueError: |
| 547 | + # Target outside docs_root — use filename only |
| 548 | + rel_target = inc.target_path.name |
| 549 | + targets.append(str(rel_target)) |
| 550 | + |
| 551 | + if targets: |
| 552 | + include_tree[source_key] = targets |
| 553 | + |
| 554 | + return {"include_tree": include_tree, "cross_references": []} |
| 555 | + |
520 | 556 | def _index_section(self, section: Section) -> list[str]: |
521 | 557 | """Index a section and its children recursively. |
522 | 558 |
|
|
0 commit comments