| 751 | |
| 752 | |
| 753 | class CombineTutorial(Node): |
| 754 | def prep(self, shared): |
| 755 | project_name = shared["project_name"] |
| 756 | output_base_dir = shared.get("output_dir", "output") # Default output dir |
| 757 | output_path = os.path.join(output_base_dir, project_name) |
| 758 | repo_url = shared.get("repo_url") # Get the repository URL |
| 759 | # language = shared.get("language", "english") # No longer needed for fixed strings |
| 760 | |
| 761 | # Get potentially translated data |
| 762 | relationships_data = shared[ |
| 763 | "relationships" |
| 764 | ] # {"summary": str, "details": [{"from": int, "to": int, "label": str}]} -> summary/label potentially translated |
| 765 | chapter_order = shared["chapter_order"] # indices |
| 766 | abstractions = shared[ |
| 767 | "abstractions" |
| 768 | ] # list of dicts -> name/description potentially translated |
| 769 | chapters_content = shared[ |
| 770 | "chapters" |
| 771 | ] # list of strings -> content potentially translated |
| 772 | |
| 773 | # --- Generate Mermaid Diagram --- |
| 774 | mermaid_lines = ["flowchart TD"] |
| 775 | # Add nodes for each abstraction using potentially translated names |
| 776 | for i, abstr in enumerate(abstractions): |
| 777 | node_id = f"A{i}" |
| 778 | # Use potentially translated name, sanitize for Mermaid ID and label |
| 779 | sanitized_name = abstr["name"].replace('"', "") |
| 780 | node_label = sanitized_name # Using sanitized name only |
| 781 | mermaid_lines.append( |
| 782 | f' {node_id}["{node_label}"]' |
| 783 | ) # Node label uses potentially translated name |
| 784 | # Add edges for relationships using potentially translated labels |
| 785 | for rel in relationships_data["details"]: |
| 786 | from_node_id = f"A{rel['from']}" |
| 787 | to_node_id = f"A{rel['to']}" |
| 788 | # Use potentially translated label, sanitize |
| 789 | edge_label = ( |
| 790 | rel["label"].replace('"', "").replace("\n", " ") |
| 791 | ) # Basic sanitization |
| 792 | max_label_len = 30 |
| 793 | if len(edge_label) > max_label_len: |
| 794 | edge_label = edge_label[: max_label_len - 3] + "..." |
| 795 | mermaid_lines.append( |
| 796 | f' {from_node_id} -- "{edge_label}" --> {to_node_id}' |
| 797 | ) # Edge label uses potentially translated label |
| 798 | |
| 799 | mermaid_diagram = "\n".join(mermaid_lines) |
| 800 | # --- End Mermaid --- |
| 801 | |
| 802 | # --- Prepare index.md content --- |
| 803 | index_content = f"# Tutorial: {project_name}\n\n" |
| 804 | index_content += f"{relationships_data['summary']}\n\n" # Use the potentially translated summary directly |
| 805 | # Keep fixed strings in English |
| 806 | index_content += f"**Source Repository:** [{repo_url}]({repo_url})\n\n" |
| 807 | |
| 808 | # Add Mermaid diagram for relationships (diagram itself uses potentially translated names/labels) |
| 809 | index_content += "```mermaid\n" |
| 810 | index_content += mermaid_diagram + "\n" |
no outgoing calls
no test coverage detected