@@ -98,28 +98,43 @@ def _generate_markdown(self, directory: str):
9898 f .write (formatted_all_tables )
9999
100100 for table in self ._tables :
101- table_template = env .from_string (TABLE )
102- table_md = table_template .render (table = table )
103- formatted_table_md = self ._format_markdown (table_md )
104- with open (os .path .join (directory , table .name + ".md" ), "w" ) as f :
105- f .write (formatted_table_md )
101+ self ._render_table (directory , env , table )
102+
103+ def _render_table (self , directory : str , env : jinja2 .Environment , table : Table ):
104+ table_template = env .from_string (TABLE )
105+ table_md = table_template .render (table = table )
106+ formatted_table_md = self ._format_markdown (table_md )
107+ with open (os .path .join (directory , table .name + ".md" ), "w" ) as f :
108+ f .write (formatted_table_md )
109+ for relation in table .relations :
110+ self ._render_table (directory , env , relation )
106111
107112 def _all_tables_entry (self , table : Table ):
108113 env = jinja2 .Environment ()
109114 env .globals ['indent_to_depth' ] = self ._indent_to_depth
110115 env .globals ['all_tables_entry' ] = self ._all_tables_entry
116+ env .globals ['indent_table_to_depth' ] = self ._indent_table_to_depth
111117 entry_template = env .from_string (ALL_TABLES_ENTRY )
112118 return entry_template .render (table = table )
113119
114120 @staticmethod
115- def _indent_to_depth (text : str , depth : int ):
121+ def _indent_table_to_depth (table : Table ) -> str :
122+ s = ""
123+ t = table
124+ while t .parent is not None :
125+ s += " "
126+ t = t .parent
127+ return s
128+
129+ @staticmethod
130+ def _indent_to_depth (text : str , depth : int ) -> str :
116131 indentation = depth * 4 # You can adjust the number of spaces as needed
117132 lines = text .split ('\n ' )
118133 indented_lines = [(' ' * indentation ) + line for line in lines ]
119134 return '\n ' .join (indented_lines )
120135
121136 @staticmethod
122- def _format_markdown (text : str ):
137+ def _format_markdown (text : str ) -> str :
123138 re_match_newlines = re .compile (r'\n{3,}' )
124139 re_match_headers = re .compile (r'(#{1,6}.+)\n+' )
125140
0 commit comments