Exemplo n.º 1
0
 def run(self):
     node = ObjectDescription.run(self)
     contentnode = node[1][-1]
     # label is the key to find the field-value
     labelmap = {field_type.name: unicode(field_type.label)  # name -> label
                 for field_type in self.doc_field_types}
     field_nodes = {}
     for child in contentnode:
         if isinstance(child, nodes.field_list):
             for field in child:
                 if isinstance(field, nodes.field):
                     # label -> field_node
                     field_nodes[field[0].astext()] = field
     # merge
     for field_src, field_dest in self.doc_merge_fields.items():
         # name -> label -> field_node
         label_src = labelmap[field_src]
         if label_src in field_nodes:
             field_node_src = field_nodes[label_src]
             label_dest = labelmap[field_dest]
             if label_dest in field_nodes:
                 field_node_dest = field_nodes[label_dest]
                 for item_src in field_node_src[1][0]:
                     name = item_src[0][0].astext()
                     for item_dest in field_node_dest[1][0]:
                         if name == item_dest[0][0].astext():
                             # merge first paragraph
                             self.merge_field(item_src[0],
                                              item_dest[0])
             for child in contentnode:
                 if isinstance(child, nodes.field_list):
                     child.remove(field_node_src)
     return node
Exemplo n.º 2
0
    def run(self):
        """Run this directive.

        In addition to the default processing of the
        :class:`~sphinx.directives.ObjectDescription` directive, add the
        automatically extracted documentation if the ``auto`` option was set.

        """
        result_nodes = ObjectDescription.run(self)

        if 'auto' in self.options:
            cont_node = result_nodes[-1][-1]
            symbol = self.lookup_auto_symbol()
            docstring = symbol and self.get_auto_docstring(symbol)
            if not docstring:
                self.state_machine.reporter.warning(
                    'no docstring for symbol {0}'.format(self.names[0]),
                    line=self.lineno)
            else:
                self.before_content()
                # We don't add the raw source to prevent Sphinx from trying to
                # highlight this block.  Yes, that's hacky, but we've
                # apparently no other chance to keep Pygments out of the party
                docstring_block = nodes.el_docstring_block(docstring, docstring)
                cont_node.insert(0, docstring_block)
                transformer = EmacsHelpModeMarkup(self.state.document,
                                                  docstring_block)
                transformer.apply()
                self.after_content()

        return result_nodes
Exemplo n.º 3
0
 def run(self):
     index, content = ObjectDescription.run(self)
     fields = nodes.field_list()
     for f in self.fields:
         field = f.make_field(self)
         if field:
             fields += field
     # Insert option fields right after signature
     content.insert(1, fields)
     return [index, content]
Exemplo n.º 4
0
    def run(self):
        env = self.state.document.settings.env

        self.name = self.get_name()
        fullname = self.get_fullname(self.name)

        if 'noindex' not in self.options:
            env.domaindata['d']['objects'][fullname] = (env.docname, self.get_objtype())

        return ObjectDescription.run(self)
Exemplo n.º 5
0
    def run(self):
        # Automatically generate the "rose:NAME" ref_context variable.
        self.add_ref_context(self.NAME)
        index_node, cont_node = ObjectDescription.run(self)

        # Add a marker on the output node so we can determine the context
        # namespace later (see RoseDomain.resolve_xref).
        context_var = self.ROSE_CONTEXT % self.NAME
        cont_node.ref_context = {context_var: self.process_name(
            self.arguments[0].strip())[0]}

        # Add children if initialised via python - see RoseAutoDirective.
        block = block_quote()  # Create indented section.
        for child_node in self.registered_children:
            block.append(child_node)  # Add child node to indented section.
        cont_node.append(block)  # Add indented section to this node.

        return [index_node, cont_node]
Exemplo n.º 6
0
    def run(self):
        nodes = ObjectDescription.run(self)

        # Insert a dedicated signature for the key binding before all other
        # signatures, but only for commands.  Nothing else has key bindings.
        binding = self.options.get('binding')
        if binding:
            binding = self.with_prefix_arg(binding)
            desc_node = nodes[-1]
            assert isinstance(desc_node, addnodes.desc)
            signode = addnodes.desc_signature(binding, '')
            # No clue what this property is for, but ObjectDescription sets it
            # for its signatures, so we should do as well for our signature.
            signode['first'] = False
            desc_node.insert(0, signode)
            signode += addnodes.desc_name(binding, binding)

        return nodes
Exemplo n.º 7
0
    def run(self):
        # Automatically generate the "rose:NAME" ref_context variable.
        self.add_ref_context(self.NAME)
        index_node, cont_node = ObjectDescription.run(self)

        # Add a marker on the output node so we can determine the context
        # namespace later (see RoseDomain.resolve_xref).
        context_var = self.ROSE_CONTEXT % self.NAME
        cont_node.ref_context = {context_var: self.process_name(
            self.arguments[0].strip())[0]}

        # Add children if initialised via python - see RoseAutoDirective.
        block = block_quote()  # Create indented section.
        for child_node in self.registered_children:
            block.append(child_node)  # Add child node to indented section.
        cont_node.append(block)  # Add indented section to this node.

        return [index_node, cont_node]
Exemplo n.º 8
0
    def run(self):
        nodes = ObjectDescription.run(self)

        # Insert a dedicated signature for the key binding before all other
        # signatures, but only for commands.  Nothing else has key bindings.
        binding = self.options.get('binding')
        if binding:
            binding = self.with_prefix_arg(binding)
            desc_node = nodes[-1]
            assert isinstance(desc_node, addnodes.desc)
            signode = addnodes.desc_signature(binding, '')
            # No clue what this property is for, but ObjectDescription sets it
            # for its signatures, so we should do as well for our signature.
            signode['first'] = False
            desc_node.insert(0, signode)
            signode += addnodes.desc_name(binding, binding)

        return nodes
Exemplo n.º 9
0
    def run(self):
        index, content = ObjectDescription.run(self)
        fields = nodes.field_list()
        for f in self.fields:
            field = f.make_field(self)
            if field:
                fields += field
        # Insert option fields right after signature
        content.insert(1, fields)

        name = self.arguments[0]
        module = self.options.get('module', None)
        qname = '{}.{}'.format(module, name) if module else name
        classname = self.name[4:] if self.name.startswith(
            'fab:') else self.name
        indextext = '{} ({} in {})'.format(name, classname, module)
        index = addnodes.index(entries=[('single', indextext, name, None,
                                         None)])
        return [index, content]
Exemplo n.º 10
0
 def run(self):
     node = ObjectDescription.run(self)
     contentnode = node[1][-1]
     # label is the key to find the field-value
     labelmap = {field_type.name: unicode(field_type.label)  # name -> label
                 for field_type in self.doc_field_types}
     field_nodes = {}
     for child in contentnode:
         if isinstance(child, nodes.field_list):
             for field in child:
                 if isinstance(field, nodes.field):
                     # label -> field_node
                     field_nodes[field[0].astext()] = field
     # merge fields
     # ex)
     # :constant CONST: description
     # :constant-type CONST: int32
     # :constant-value: value
     for field_src, field_dest in self.doc_merge_fields.items():
         # name -> label -> field_node
         label_src = labelmap[field_src]
         if label_src in field_nodes:
             field_node_src = field_nodes[label_src]
             label_dest = labelmap[field_dest]
             if label_dest in field_nodes:
                 field_node_dest = field_nodes[label_dest]
                 for item_src in field_node_src[1][0]:
                     name = item_src[0][0].astext()
                     for item_dest in field_node_dest[1][0]:
                         if name == item_dest[0][0].astext():
                             # merge first paragraph
                             self.merge_field(item_src[0],
                                              item_dest[0])
             for child in contentnode:
                 if isinstance(child, nodes.field_list):
                     child.remove(field_node_src)
     return node
Exemplo n.º 11
0
    def run(self):
        self.ref_context_key = self.get_reference_context()

        index_node, cont_node = ObjectDescription.run(self)

        return [index_node, cont_node]