コード例 #1
0
ファイル: generate_java_doc.py プロジェクト: pfuxs/generators
    def get_java_formatted_doc(self, shift_right):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_java_doc_function_links(text)

        text = text.replace('Callback ', 'Listener ')
        text = text.replace(' Callback', ' Listener')
        text = text.replace('callback ', 'listener ')
        text = text.replace(' callback', ' listener')

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_java_class_name() + '.'

        def format_element_name(element, index):
            if index == None:
                return element.get_name().headless

            return '{0}[{1}]'.format(element.get_name().headless, index)

        text += common.format_constants(prefix, self, format_element_name)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, shift_right)
コード例 #2
0
ファイル: generate_tvpl_doc.py プロジェクト: pfuxs/generators
    def get_tvpl_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        constants = {'en': 'symbols', 'de': 'Symbole'}

        text = self.get_device().replace_tvpl_function_links(text)

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        def format_element_name(element, index):
            if index == None:
                return element.get_name().space

            return '{0} [{1}]'.format(element.get_name().space, index)

        text += common.format_constants('',
                                        self,
                                        format_element_name,
                                        constants_name=constants)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #3
0
    def get_mathematica_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_mathematica_doc_function_links(
            text)

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_mathematica_class_name() + '`'

        def format_element_name(element, index):
            if index == None:
                return element.get_name().headless

            return '{0}[[{1}]]'.format(element.get_name().headless, index)

        def format_constant(prefix, constant_group, constant, value):
            return '* {0}\\ **{1}**\\ U{2} = {3}\n'.format(
                prefix,
                constant_group.get_name().upper.replace('_', 'U'),
                constant.get_name().upper.replace('_', 'U'), value)

        text += common.format_constants(prefix,
                                        self,
                                        format_element_name,
                                        constant_format_func=format_constant)

        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #4
0
    def get_rust_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_rust_doc_function_links(text)

        callback_parameter = {'en': 'received variable', 'de': 'empfangene Variable'}
        callback_parameters = {'en': 'members of the received struct', 'de': 'Felder der empfangenen Struktur'}

        def format_parameter(name):
            return '``{0}``'.format(name) # FIXME

        text = common.handle_rst_param(text, format_parameter)

        if self.get_type() == 'callback':
            text = common.handle_rst_word(text, parameter=callback_parameter, parameters=callback_parameters)
        else:
            text = common.handle_rst_word(text)

        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_rust_module_name().upper() + '_'

        def format_element_name(element, index):
            if index == None:
                return element.get_name().under

            return '{0}[{1}]'.format(element.get_name().under, index)

        text += common.format_constants(prefix, self, format_element_name)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #5
0
    def get_tcpip_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        constants = {'en': 'meanings', 'de': 'Bedeutungen'}
        constants_intro = {
            'en':
            """
The following **{0}** are defined for the elements of this function:

""",
            'de':
            """
Die folgenden **{0}** sind für die Elemente dieser Funktion definiert:

"""
        }
        parameter = {'en': 'response value', 'de': 'Rückgabewert'}
        parameters = {'en': 'response values', 'de': 'Rückgabewerte'}

        text = self.get_device().specialize_tcpip_doc_function_links(text)

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text, parameter, parameters)
        text = common.handle_rst_substitutions(text, self)

        def format_element_name(element, index):
            if index == None:
                return element.get_name().under

            return '{0}[{1}]'.format(element.get_name().under, index)

        def format_constant(prefix, constant_group, constant, value):
            text = ''

            for word in constant.get_name().space.split(' '):
                if len(text) > 0:
                    if word[0] in '0123456789' and text[-1] in '0123456789':
                        text += common.select_lang({'en': '.', 'de': ','})
                    else:
                        text += ' '

                text += word

            return '* {0} = {1}\n'.format(value, text)

        text += common.format_constants('',
                                        self,
                                        format_element_name,
                                        constants_intro=constants_intro,
                                        constants_name=constants,
                                        constant_format_func=format_constant)

        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #6
0
    def get_go_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())

        # handle links
        text = text.replace(":ref:", "")
        text = re.sub("`([^<]+) <([^>]+)>`__", r"\g<2>", text)

        # handle tables
        lines = text.split('\n')
        replaced_lines = []
        in_table_head = False
        in_table_body = False
        col_count = 0

        for line in lines:
            line = line.replace('"', '')

            if line.strip() == '.. csv-table::':
                in_table_head = True
            elif line.strip().startswith(':header: ') and in_table_head:
                line = line[len(':header: '):]
                col_count = line.count(",") + 1
                line = line.replace(",", "|")
                replaced_lines.append(line)
            elif line.strip().startswith(':widths:') and in_table_head:
                pass
            elif len(line.strip()) == 0 and in_table_head:
                in_table_head = False
                in_table_body = True

                replaced_lines.append("|".join([" --- "] * col_count))
            elif in_table_head:
                replaced_lines.append(line.replace(",", "|"))
            elif len(line.strip()) == 0 and in_table_body:
                in_table_body = False
                replaced_lines.append('')
            elif in_table_body:
                replaced_lines.append(line.replace(",", "|"))
            else:
                replaced_lines.append(line)

        text = '\n'.join(replaced_lines)
        text = self.get_device().specialize_go_doc_function_links(text)

        text = text.replace('.. note::', 'Note')
        text = text.replace('.. warning::', 'Warning')

        def format_parameter(name):
            return '\\c {0}'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return '// ' + '\n// '.join(text.strip().split('\n'))
コード例 #7
0
    def get_python_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return '\n        '.join(text.strip().split('\n'))
コード例 #8
0
    def get_perl_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())

        def format_parameter(name):
            return name # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return text.strip()
コード例 #9
0
ファイル: generate_mqtt_doc.py プロジェクト: pfuxs/generators
    def get_mqtt_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_mqtt_doc_function_links(text)

        constants = {'en': 'symbols', 'de': 'Symbole'}

        callback_parameter = {
            'en': 'callback payload',
            'de': 'Payload des Callbacks'
        }
        callback_parameters = {
            'en': 'callback payload members',
            'de': 'Payload-Member des Callbacks'
        }

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)

        if self.get_type() == 'callback':
            text = common.handle_rst_word(text,
                                          parameter=callback_parameter,
                                          parameters=callback_parameters,
                                          constants=constants)
        else:
            text = common.handle_rst_word(text, constants=constants)

        text = common.handle_rst_substitutions(text, self)

        def format_element_name(element, index):
            if index == None:
                return element.get_name().under

            return '{0}[{1}]'.format(element.get_name().under, index)

        def format_constant(prefix, constant_group, constant, value):
            return '* "{0}" = {1}\n'.format(constant.get_name().under, value)

        text += common.format_constants('',
                                        self,
                                        format_element_name,
                                        constants_name=constants,
                                        constant_format_func=format_constant)

        text += common.format_since_firmware(self.get_device(), self)
        text = text.replace('|device_identifier_constant|\n', '')

        return common.shift_right(text, 1)
コード例 #10
0
    def get_go_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_go_doc_function_links(text)

        callback_parameter = {
            'en': 'callback parameter',
            'de': 'Parameter des Callbacks'
        }
        callback_parameters = {
            'en': 'callback parameters',
            'de': 'Parameter des Callbacks'
        }

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)

        if self.get_type() == 'callback':
            text = common.handle_rst_word(text,
                                          parameter=callback_parameter,
                                          parameters=callback_parameters)
        else:
            text = common.handle_rst_word(text)

        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_go_package() + '.'

        def format_element_name(element, index):
            if index == None:
                return element.get_name().headless

            return '{0}[{1}]'.format(element.get_name().headless, index)

        def format_constant(prefix, constant_group, constant, value):
            return '* {0}\\ **{1}**\\ {2} = {3}\n'.format(
                prefix,
                constant_group.get_name().camel,
                constant.get_name().camel_constant_safe, value)

        text += common.format_constants(prefix,
                                        self,
                                        format_element_name,
                                        constant_format_func=format_constant)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #11
0
    def get_ruby_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())

        # handle tables
        lines = text.split('\n')
        replaced_lines = []
        in_table_head = False
        in_table_body = False

        for line in lines:
            if line.strip() == '.. csv-table::':
                in_table_head = True
            elif line.strip().startswith(':header: ') and in_table_head:
                replaced_lines.append(line[len(':header: '):])
            elif line.strip().startswith(':widths:') and in_table_head:
                pass
            elif len(line.strip()) == 0 and in_table_head:
                in_table_head = False
                in_table_body = True

                replaced_lines.append('')
            elif len(line.strip()) == 0 and in_table_body:
                in_table_body = False
                replaced_lines.append('')
            else:
                replaced_lines.append(line)

        text = '\n'.join(replaced_lines)
        text = self.get_device().specialize_ruby_doc_function_links(text)

        def format_parameter(name):
            return name # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return '\n    # '.join(text.strip().split('\n'))
コード例 #12
0
    def get_shell_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_shell_doc_function_links(text)

        constants = {'en': 'symbols', 'de': 'Symbole'}

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        def format_element_name(element, index):
            if element.get_direction() == 'in':
                template = '<{0}>'
            else:
                template = '{0}'

            if index == None:
                return template.format(element.get_name().dash)

            return template.format(
                element.get_name().dash) + '[{0}]'.format(index)

        def format_constant(prefix, constant_group, constant, value):
            return '* **{0}**-{1} = {2}\n'.format(
                constant_group.get_name().dash,
                constant.get_name().dash, value)

        text += common.format_constants('',
                                        self,
                                        format_element_name,
                                        constants_name=constants,
                                        constant_format_func=format_constant)

        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #13
0
    def get_php_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_php_doc_function_links(text)

        def format_parameter(name):
            return '``${0}``'.format(name)

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_php_class_name() + '::'

        def format_element_name(element, index):
            if index == None:
                return '$' + element.get_name().under

            return '${0}[{1}]'.format(element.get_name().under, index)

        text += common.format_constants(prefix, self, format_element_name)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #14
0
    def get_c_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_c_doc_function_links(text)

        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        prefix = 'TF_' + self.get_device().get_name().upper + '_'

        def format_element_name(element, index):
            if index == None:
                return element.get_c_name()

            return '{0}[{1}]'.format(element.get_c_name(), index)

        text += common.format_constants(prefix, self, format_element_name)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #15
0
    def get_vbnet_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())
        text = self.get_device().specialize_vbnet_doc_function_links(text)

        # FIXME: add something similar for :char:`c`
        def format_parameter(name):
            return '``{0}``'.format(name)  # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)

        prefix = self.get_device().get_vbnet_class_name() + '.'

        def format_element_name(element, index):
            if index == None:
                return element.get_name().headless

            return '{0}({1})'.format(element.get_name().headless, index)

        text += common.format_constants(prefix, self, format_element_name)
        text += common.format_since_firmware(self.get_device(), self)

        return common.shift_right(text, 1)
コード例 #16
0
    def get_php_formatted_doc(self, suffix):
        text = common.select_lang(self.get_doc_text())

        # handle notes and warnings
        lines = text.split('\n')
        replaced_lines = []
        in_note = False
        in_warning = False
        in_table_head = False
        in_table_body = False

        for line in lines:
            if line.strip() == '.. note::':
                in_note = True
                replaced_lines.append('<note>')
            elif line.strip() == '.. warning::':
                in_warning = True
                replaced_lines.append('<warning>')
            elif len(line.strip()) == 0 and in_note:
                in_note = False
                replaced_lines.append('</note>')
                replaced_lines.append('')
            elif len(line.strip()) == 0 and in_warning:
                in_warning = False
                replaced_lines.append('</warning>')
                replaced_lines.append('')
            elif line.strip() == '.. csv-table::':
                in_table_head = True
                replaced_lines.append('<code>')
            elif line.strip().startswith(':header: ') and in_table_head:
                replaced_lines.append(line[len(':header: '):])
            elif line.strip().startswith(':widths:') and in_table_head:
                pass
            elif len(line.strip()) == 0 and in_table_head:
                in_table_head = False
                in_table_body = True

                replaced_lines.append('')
            elif len(line.strip()) == 0 and in_table_body:
                in_table_body = False

                replaced_lines.append('</code>')
                replaced_lines.append('')
            else:
                replaced_lines.append(line)

        text = '\n'.join(replaced_lines)
        text = self.get_device().specialize_php_doc_function_links(text)

        text = text.replace('.. note::', '\\note')
        text = text.replace('.. warning::', '\\warning')

        def format_parameter(name):
            return name # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return '\n     * '.join(text.strip().split('\n') + suffix)
コード例 #17
0
    def get_rust_formatted_doc(self):
        text = common.select_lang(self.get_doc_text())

        # handle links
        text = text.replace(":ref:", "")
        #text = text.replace(":func:", "")
        #if ":ref:" in text:
            #substitutions = {
            #    "device_identifier": "https://www.tinkerforge.com/en/doc/Software/Device_Identifier.html",
            #    "tutorial_authentication": "https://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Authentication/Tutorial.html",
            #    "gps_bricklet_fix_led": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS.html#fix-led",
            #    "gps_v2_bricklet_fix_led": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS_V2.html#fix-led",
            #    "led_strip_bricklet_ram_constraints": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/LED_Strip.html#ram-constraints",
            #}
            #for match in  re.finditer(":ref:`([^<]+) <([^>]+)>`", text):
            #    link_text, url = match.groups()
            #    subst = substitutions[url]
            #    re.sub("`("+link_text+") <"+url+">`", "[\g<1>]("+subst+")", text)

        text = re.sub("`([^<]+) <([^>]+)>`", r"[\g<1>](\g<2>)", text)


        # handle tables
        lines = text.split('\n')
        replaced_lines = []
        in_table_head = False
        in_table_body = False
        col_count = 0
        for line in lines:
            line = line.replace('"', '')
            if line.strip() == '.. csv-table::':
                in_table_head = True
            elif line.strip().startswith(':header: ') and in_table_head:
                line = line[len(':header: '):]
                col_count = line.count(",") + 1
                line = line.replace(",", "|")
                replaced_lines.append(line)
            elif line.strip().startswith(':widths:') and in_table_head:
                pass
            elif len(line.strip()) == 0 and in_table_head:
                in_table_head = False
                in_table_body = True

                replaced_lines.append("|".join([" --- "] * col_count))
            elif in_table_head:
                replaced_lines.append(line.replace(",", "|"))
            elif len(line.strip()) == 0 and in_table_body:
                in_table_body = False
                replaced_lines.append('')
            elif in_table_body:
                replaced_lines.append(line.replace(",", "|"))
            else:
                replaced_lines.append(line)

        text = '\n'.join(replaced_lines)
        text, links = self.get_device().specialize_rust_doc_function_links(text)
        text += '\n' + '\n'.join(links)

        text = text.replace('Callback ', 'Receiver ')
        text = text.replace(' Callback', ' Receiver')
        text = text.replace('callback ', 'receiver ')
        text = text.replace(' callback', ' receiver')
        text = text.replace('.. note::', '# Note')
        text = text.replace('.. warning::', '# Warning')

        def format_parameter(name):
            return '\\c {0}'.format(name) # FIXME

        text = common.handle_rst_param(text, format_parameter)
        text = common.handle_rst_word(text)
        text = common.handle_rst_substitutions(text, self)
        text += common.format_since_firmware(self.get_device(), self)

        return '/// ' + '\n\t/// '.join(text.strip().split('\n'))