def module_to_pdf(self, module_info): """Creating of Docstrings for multiple classes module""" global CURRENT_SHIFT mod_name = module_info.name description = module_info.docstrings classes = module_info.classes functions = module_info.functions if _is_all_private(functions): functions = None pdf = '' pdf += pdfformater.to_head('NAME', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf += pdfformater.to_subhead(mod_name, CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT if description: pdf += pdfformater.to_head('DESCRIPTION', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf += pdfformater.to_text(description, CURRENT_SHIFT) CURRENT_SHIFT += pdfformater.HORIZONTAL_SHIFT if classes: pdf += pdfformater.to_head('CLASSES', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT - 40 for cls in classes: cls_name = cls.name mod_name = mod_name description = cls.docstrings functions = cls.functions if _is_all_private(functions): functions = None pdf += pdfformater.to_class('class {}'.format(cls_name),CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT if description: pdf += pdfformater.to_text(description, CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT if functions: pdf += pdfformater.to_subhead('METHODS:', CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT pdf = self._members_to_pdf(functions, pdf) if functions: if not classes: pdf += pdfformater.to_head('FUNCTIONS', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf = self._members_to_pdf(functions, pdf) pdf = pdfformater.to_page_description('Docstrings to {} module'.format(mod_name), pdfformater.get_page_height(pdf)) + pdf return self.make_pdf(pdf)
def class_to_pdf(self, class_info, module_name): """PDF-representation of class' docstrings""" global CURRENT_SHIFT cls_name = class_info.name mod_name = module_name description = class_info.docstrings functions = class_info.functions if _is_all_private(functions): functions = None pdf = '' pdf += pdfformater.to_head('class {}'.format(cls_name), CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT if description: pdf += pdfformater.to_text(description, CURRENT_SHIFT) CURRENT_SHIFT += pdfformater.HORIZONTAL_SHIFT if functions: pdf += pdfformater.to_subhead('METHODS:', CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT pdf = self._members_to_pdf(functions, pdf) pdf = pdfformater.to_page_description( 'Docstrings to {} class of {} module'.format(cls_name, mod_name), pdfformater.get_page_height(pdf)) + pdf return self.make_pdf(pdf)
def _members_to_pdf(members, pdf): global CURRENT_SHIFT for member in members: if _is_private_name(member.name): continue if isinstance(member, ast_visitor.ClassInfo): pdf += pdfformater.to_subhead(member.name, CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT if isinstance(member, ast_visitor.FuncInfo): signature = '(' + ', '.join(member.signature) + ')' pdf += pdfformater.to_subhead(member.name + signature, CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT docs = member.docstrings if docs: pdf += pdfformater.to_text(docs, CURRENT_SHIFT) CURRENT_SHIFT += pdfformater.HORIZONTAL_SHIFT return pdf
def module_to_pdf(self, module_info): """PDF-representation of module's docstrings""" global CURRENT_SHIFT mod_name = module_info.name description = module_info.docstrings classes = module_info.classes functions = module_info.functions if _is_all_private(functions): functions = None pdf = '' pdf += pdfformater.to_head('NAME', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf += pdfformater.to_subhead(mod_name, CURRENT_SHIFT) CURRENT_SHIFT = 2 * pdfformater.HORIZONTAL_SHIFT if description: pdf += pdfformater.to_head('DESCRIPTION', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf += pdfformater.to_text(description, CURRENT_SHIFT) CURRENT_SHIFT += pdfformater.HORIZONTAL_SHIFT if classes: pdf += pdfformater.to_head('CLASSES', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf = self._members_to_pdf(classes, pdf) if functions: pdf += pdfformater.to_head('FUNCTIONS', CURRENT_SHIFT) CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT pdf = self._members_to_pdf(functions, pdf) pdf = pdfformater.to_page_description( 'Docstrings to {} module'.format(mod_name), pdfformater.get_page_height(pdf)) + pdf return self.make_pdf(pdf)
def test_to_subhead(self): result = pdfformater.to_subhead('Some text to subhead', 40) self.assertEqual( result, '\n/Helv-Bold 12 Tf\n0.6 0.4588 0.7882 rg\n40 -25 Td\n(Some text to subhead) Tj\n' )