Ejemplo n.º 1
0
    def function_to_pdf(self, fnc_info, cls_name, mod_name):
        """PDF-representation of functions' docstrings"""
        global CURRENT_SHIFT

        fnc_name = fnc_info.name
        cls_name = cls_name
        mod_name = mod_name

        pdf = ''

        signature = '(' + ', '.join(fnc_info.signature) + ')'
        pdf += pdfformater.to_head(fnc_name + signature, CURRENT_SHIFT)
        CURRENT_SHIFT = pdfformater.HORIZONTAL_SHIFT

        description = fnc_info.docstrings
        if description:
            pdf += pdfformater.to_text(description, CURRENT_SHIFT)
            CURRENT_SHIFT += pdfformater.HORIZONTAL_SHIFT

        pdf = pdfformater.to_page_description(
            'Docstrings to {} method{}of {} module'.format(
                fnc_name, ' of {} class '.format(cls_name)
                if cls_name is not None else ' ', mod_name),
            pdfformater.get_page_height(pdf)) + pdf

        return self.make_pdf(pdf)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 def test_get_page_height(self):
     text = '''hello
     world
     and
     person
     who
     is
     reading
     it
     just
     at
     this
     particular
     moment'''
     result = pdfformater.get_page_height(text)
     self.assertEqual(result, 95)
Ejemplo n.º 5
0
    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)