Main documentation class
| 382 | |
| 383 | |
| 384 | class Documentation: |
| 385 | """Main documentation class""" |
| 386 | |
| 387 | def __init__(self, path): |
| 388 | self._path = path |
| 389 | self._files = [f for f in os.listdir(path) if f.endswith('.yml')] |
| 390 | self._yamls = list() |
| 391 | for yaml_file in self._files: |
| 392 | self._yamls.append(YamlFile(os.path.join(path, yaml_file))) |
| 393 | # Merge same modules of different files |
| 394 | self.master_dict = dict() |
| 395 | for yaml_file in self._yamls: |
| 396 | for module in yaml_file.get_modules(): |
| 397 | module_name = module['module_name'] |
| 398 | if module_name not in self.master_dict: |
| 399 | self.master_dict[module_name] = module |
| 400 | elif valid_dic_val(module, 'classes'): |
| 401 | for new_module in module['classes']: |
| 402 | # Create the 'classes' key if does not exist already |
| 403 | if not valid_dic_val(self.master_dict[module_name], 'classes'): |
| 404 | self.master_dict[module_name]['classes'] = [] |
| 405 | self.master_dict[module_name]['classes'].append(new_module) |
| 406 | |
| 407 | def gen_overview(self): |
| 408 | """Generates a referenced index for markdown file""" |
| 409 | md = MarkdownFile() |
| 410 | md.title(3, 'Overview') |
| 411 | for module_name in sorted(self.master_dict): |
| 412 | module = self.master_dict[module_name] |
| 413 | module_key = '#' + module_name |
| 414 | md.list_pushn( |
| 415 | brackets(bold(module_key[1:])) + |
| 416 | parentheses(module_key) + ' ' + |
| 417 | sub(italic('Module'))) |
| 418 | # Generate class overview (if any) |
| 419 | if 'classes' in module and module['classes']: |
| 420 | for cl in sorted(module['classes']): |
| 421 | class_name = cl['class_name'] |
| 422 | class_key = join([module_key, class_name], '.') |
| 423 | md.list_pushn(join([ |
| 424 | brackets(bold(class_name)), |
| 425 | parentheses(class_key), ' ', |
| 426 | sub(italic('Class'))])) |
| 427 | # Generate class instance variables overview (if any) |
| 428 | if 'instance_variables' in cl and cl['instance_variables']: |
| 429 | for inst_var in cl['instance_variables']: |
| 430 | md.list_push(gen_inst_var_indx(inst_var, class_key)) |
| 431 | md.list_popn() |
| 432 | # Generate class methods overview (if any) |
| 433 | if 'methods' in cl and cl['methods']: |
| 434 | for method in cl['methods']: |
| 435 | md.list_push(gen_method_indx(method, class_key)) |
| 436 | md.list_popn() |
| 437 | md.list_pop() |
| 438 | md.list_pop() |
| 439 | return md.data() |
| 440 | |
| 441 | def gen_body(self): |