Example #1
0
 def run(self):
     env = self.state.document.settings.env
     modname = self.arguments[0].strip()
     noindex = "noindex" in self.options
     env.temp_data["py:module"] = modname
     env.domaindata["py"]["modules"][modname] = (
         env.docname,
         self.options.get("synopsis", ""),
         self.options.get("platform", ""),
         "deprecated" in self.options,
     )
     # make a duplicate entry in 'objects' to facilitate searching for the
     # module in PythonDomain.find_obj()
     env.domaindata["py"]["objects"][modname] = (env.docname, "module")
     targetnode = nodes.target("", "", ids=["module-" + modname], ismod=True)
     self.state.document.note_explicit_target(targetnode)
     ret = [targetnode]
     # XXX this behavior of the module directive is a mess...
     if "platform" in self.options:
         platform = self.options["platform"]
         node = nodes.paragraph()
         node += nodes.emphasis("", _("Platforms: "))
         node += nodes.Text(platform, platform)
         ret.append(node)
     # the synopsis isn't printed; in fact, it is only used in the
     # modindex currently
     if not noindex:
         indextext = _("%s (module)") % modname
         inode = addnodes.index(entries=[("single", indextext, "module-" + modname, modname)])
         ret.append(inode)
     return ret
Example #2
0
    def run(self):
        pkgname = self.arguments[0].strip()
        env = self.state.document.settings.env
        env.ref_context['qbs:package'] = pkgname

        if 'noindex' in self.options:
            return []

        sdkname = self.options.get('sdk', env.ref_context.get('qbs:sdk', None))

        if sdkname:
            pkgname = sdkname + '.' + pkgname

        env.domaindata['qbs']['packages'][pkgname] = (env.docname, self.options.get('synopsis', ''))
        env.domaindata['qbs']['objects'][pkgname] = (env.docname, 'package')

        # target
        targetname = 'package-' + pkgname
        targetnode = nodes.target('', '', ids=[targetname], ismod=True)
        self.state.document.note_explicit_target(targetnode)

        # index
        if sdkname:
            itext = _('%s (Qbs Package in %s)') % (pkgname[len(sdkname) + 1:], sdkname)
        else:
            itext = _('%s (Qbs Package') % (pkgname[len(sdkname) + 1:])
        inode = addnodes.index(entries=[('single', itext, targetname, '', None)])

        return [targetnode, inode]
Example #3
0
def index_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
    # create new reference target
    env = inliner.document.settings.env
    targetid = 'index-%s' % env.new_serialno('index')
    targetnode = nodes.target('', '', ids=[targetid])
    # split text and target in role content
    has_explicit_title, title, target = split_explicit_title(text)
    title = utils.unescape(title)
    target = utils.unescape(target)
    # if an explicit target is given, we can process it as a full entry
    if has_explicit_title:
        entries = process_index_entry(target, targetid)
    # otherwise we just create a "single" entry
    else:
        # but allow giving main entry
        main = ''
        if target.startswith('!'):
            target = target[1:]
            title = title[1:]
            main = 'main'
        entries = [('single', target, targetid, main)]
    indexnode = addnodes.index()
    indexnode['entries'] = entries
    set_role_source_info(inliner, lineno, indexnode)
    textnode = nodes.Text(title, title)
    return [indexnode, targetnode, textnode], []
Example #4
0
File: desc.py Project: 89sos98/main
    def run(self):
        self.desctype = self.name
        self.env = self.state.document.settings.env
        self.indexnode = addnodes.index(entries=[])

        node = addnodes.desc()
        node.document = self.state.document
        node['desctype'] = self.desctype
        node['noindex'] = noindex = ('noindex' in self.options)

        self.names = []
        signatures = self.get_signatures()
        for i, sig in enumerate(signatures):
            # add a signature node for each signature in the current unit
            # and add a reference target for it
            signode = addnodes.desc_signature(sig, '')
            signode['first'] = False
            node.append(signode)
            try:
                # name can also be a tuple, e.g. (classname, objname)
                name = self.parse_signature(sig, signode)
            except ValueError, err:
                # signature parsing failed
                signode.clear()
                signode += addnodes.desc_name(sig, sig)
                continue  # we don't want an index entry here
            if not noindex and name not in self.names:
                # only add target and index entry if this is the first
                # description of the object with this name in this desc block
                self.names.append(name)
                self.add_target_and_index(name, sig, signode)
Example #5
0
def make_glossary_term(env, textnodes, index_key, source, lineno, new_id=None):
    # get a text-only representation of the term and register it
    # as a cross-reference target
    term = nodes.term('', '', *textnodes)
    term.source = source
    term.line = lineno

    gloss_entries = env.temp_data.setdefault('gloss_entries', set())
    objects = env.domaindata['std']['objects']

    termtext = term.astext()
    if new_id is None:
        new_id = nodes.make_id('term-' + termtext)
    if new_id in gloss_entries:
        new_id = 'term-' + str(len(gloss_entries))
    gloss_entries.add(new_id)
    objects['term', termtext.lower()] = env.docname, new_id

    # add an index entry too
    indexnode = addnodes.index()
    indexnode['entries'] = [('single', termtext, new_id, 'main', index_key)]
    indexnode.source, indexnode.line = term.source, term.line
    term.append(indexnode)
    term['ids'].append(new_id)
    term['names'].append(new_id)

    return term
Example #6
0
def module_directive(name, arguments, options, content, lineno,
                     content_offset, block_text, state, state_machine):
    env = state.document.settings.env
    modname = arguments[0].strip()
    noindex = 'noindex' in options
    env.currmodule = modname
    env.note_module(modname, options.get('synopsis', ''),
                    options.get('platform', ''),
                    'deprecated' in options)
    modulenode = addnodes.module()
    modulenode['modname'] = modname
    modulenode['synopsis'] = options.get('synopsis', '')
    targetnode = nodes.target('', '', ids=['module-' + modname])
    state.document.note_explicit_target(targetnode)
    ret = [modulenode, targetnode]
    if 'platform' in options:
        modulenode['platform'] = options['platform']
        node = nodes.paragraph()
        node += nodes.emphasis('', _('Platforms: '))
        node += nodes.Text(options['platform'], options['platform'])
        ret.append(node)
    # the synopsis isn't printed; in fact, it is only used in the modindex currently
    if not noindex:
        indextext = _('%s (module)') % modname
        inode = addnodes.index(entries=[('single', indextext,
                                         'module-' + modname, modname)])
        ret.insert(0, inode)
    return ret
Example #7
0
 def run(self):
     # type: () -> List[nodes.Node]
     modname = self.arguments[0].strip()
     noindex = 'noindex' in self.options
     self.env.ref_context['py:module'] = modname
     ret = []
     if not noindex:
         self.env.domaindata['py']['modules'][modname] = (self.env.docname,
                                                          self.options.get('synopsis', ''),
                                                          self.options.get('platform', ''),
                                                          'deprecated' in self.options)
         # make a duplicate entry in 'objects' to facilitate searching for
         # the module in PythonDomain.find_obj()
         self.env.domaindata['py']['objects'][modname] = (self.env.docname, 'module')
         targetnode = nodes.target('', '', ids=['module-' + modname],
                                   ismod=True)
         self.state.document.note_explicit_target(targetnode)
         # the platform and synopsis aren't printed; in fact, they are only
         # used in the modindex currently
         ret.append(targetnode)
         indextext = _('%s (module)') % modname
         inode = addnodes.index(entries=[('single', indextext,
                                          'module-' + modname, '', None)])
         ret.append(inode)
     return ret
Example #8
0
def glossary_directive(name, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):
    """Glossary with cross-reference targets for :term: roles."""
    env = state.document.settings.env
    node = addnodes.glossary()
    state.nested_parse(content, content_offset, node)

    # the content should be definition lists
    dls = [child for child in node if isinstance(child, nodes.definition_list)]
    # now, extract definition terms to enable cross-reference creation
    for dl in dls:
        dl['classes'].append('glossary')
        for li in dl.children:
            if not li.children or not isinstance(li[0], nodes.term):
                continue
            termtext = li.children[0].astext()
            new_id = 'term-' + nodes.make_id(termtext)
            if new_id in env.gloss_entries:
                new_id = 'term-' + str(len(env.gloss_entries))
            env.gloss_entries.add(new_id)
            li[0]['names'].append(new_id)
            li[0]['ids'].append(new_id)
            state.document.settings.env.note_reftarget('term', termtext.lower(),
                                                       new_id)
            # add an index entry too
            indexnode = addnodes.index()
            indexnode['entries'] = [('single', termtext, new_id, termtext)]
            li.insert(0, indexnode)
    return [node]
Example #9
0
 def run(self):
     arguments = self.arguments[0].split('\n')
     env = self.state.document.settings.env
     targetid = 'index-%s' % env.new_serialno('index')
     targetnode = nodes.target('', '', ids=[targetid])
     self.state.document.note_explicit_target(targetnode)
     indexnode = addnodes.index()
     indexnode['entries'] = ne = []
     for entry in arguments:
         entry = entry.strip()
         for type in pairindextypes:
             if entry.startswith(type+':'):
                 value = entry[len(type)+1:].strip()
                 value = pairindextypes[type] + '; ' + value
                 ne.append(('pair', value, targetid, value))
                 break
         else:
             for type in self.indextypes:
                 if entry.startswith(type+':'):
                     value = entry[len(type)+1:].strip()
                     if type == 'double':
                         type = 'pair'
                     ne.append((type, value, targetid, value))
                     break
             # shorthand notation for single entries
             else:
                 for value in entry.split(','):
                     value = value.strip()
                     if not value:
                         continue
                     ne.append(('single', value, targetid, value))
     return [indexnode, targetnode]
Example #10
0
File: rr_ext.py Project: dckc/monte
    def run(self):
        env = self.state.document.settings.env

        name = self.content[0].strip()
        expr = '\n'.join(self.content[1:]).strip()

        targetid = "syntax-%s" % name
        targetnode = nodes.target('', '', ids=[targetid])
        label = nodes.paragraph('', '', nodes.strong(text=name))
        ix = addnodes.index(entries=[
            ("single", "syntax; " + name, targetid, False)])

        try:
            it = eval(expr,
                      railroad_diagrams.__dict__)
        except Exception as ex:
            print >>stderr, "@@eek!", self.content
            print >>stderr, "@@", ex
            raise

        diag = RailroadDiagram(railroad_diagrams.Diagram(it))

        if env.config.syntax_fp:
            out = env.config.syntax_fp
            dump({'name': name, 'expr': expr}, out)
            out.write(",\n\n")

        return [targetnode, ix, label, diag]
Example #11
0
    def role(name, rawtext, text, lineno, inliner, options={}, content=[]):

        env = inliner.document.settings.env
        
        try:
            command, parameter = text.split(' ', 1)
        except ValueError:
            command = text
            parameter = ''
        
        indexstring = 'Console; Command; {}'.format(command)
        targetid = 'bcommand-{}-{}'.format(command, env.new_serialno('bcommand'))
        
        # Generic index entries
        indexnode = addnodes.index()
        indexnode['entries'] = []

        indexnode['entries'].append([
            'single',
            indexstring,
            targetid, '', None
        ])

        targetnode = nodes.target('', '', ids=[targetid])

        text_node = nodes.strong(text='{}'.format(text))
        
        return [targetnode, text_node, indexnode], []
Example #12
0
 def run(self):
     self.index_entries = []
     #~ index_entries is a list of 4-tuples of
     #~ ``(entrytype, entryname, target, ignored)``
     content = super(ActorDirective, self).run()
     indexnode = addnodes.index(entries=self.index_entries)
     return [indexnode] + content
Example #13
0
    def run(self):
        modname = self.arguments[0].strip()

        env = self.state.document.settings.env
        env.temp_data['cf3:namespace'] = modname

        ret = []
        if 'noindex' in self.options:
            return ret

        env.domaindata['cf3']['namespaces'][modname] = (
            env.docname, self.options.get('synopsis', ''),
            'deprecated' in self.options,
        )
        targetnode = nodes.target(
            '', '', ids=['namespace-' + modname], ismod=True
        )
        self.state.document.note_explicit_target(targetnode)
        ret.append(targetnode)

        indextext = _('%s (namespace)') % modname
        ret.append(
            addnodes.index(entries=[
                ('single', indextext, 'namespace-' + modname, modname)
            ])
        )

        return ret
Example #14
0
 def run(self):
     env = self.state.document.settings.env
     modname = self.arguments[0].strip()
     noindex = 'noindex' in self.options
     env.temp_data['tcpip:module'] = modname
     env.domaindata['tcpip']['modules'][modname] = \
         (env.docname, self.options.get('synopsis', ''),
          self.options.get('platform', ''), 'deprecated' in self.options)
     targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True)
     self.state.document.note_explicit_target(targetnode)
     ret = [targetnode]
     # XXX this behavior of the module directive is a mess...
     if 'platform' in self.options:
         platform = self.options['platform']
         node = nodes.paragraph()
         node += nodes.emphasis('', _('Platforms: '))
         node += nodes.Text(platform, platform)
         ret.append(node)
     # the synopsis isn't printed; in fact, it is only used in the
     # modindex currently
     if not noindex:
         indextext = _('%s (module)') % modname
         inode = addnodes.index(entries=[('single', indextext,
                                          'module-' + modname, modname)])
         ret.append(inode)
     return ret
Example #15
0
    def run(self):
        language = self.arguments[0]

        indexed_languages = self.options.get('index_as') or language
        index_specs = ['pair: {}; language'.format(l)
                       for l in indexed_languages.splitlines()]

        name = nodes.fully_normalize_name(language)
        target = 'language-{}'.format(name)
        targetnode = nodes.target('', '', ids=[target])
        self.state.document.note_explicit_target(targetnode)

        indexnode = addnodes.index()
        indexnode['entries'] = []
        indexnode['inline'] = False
        set_source_info(self, indexnode)
        for spec in index_specs:
            indexnode['entries'].extend(process_index_entry(spec, target))

        sectionnode = nodes.section()
        sectionnode['names'].append(name)

        title, messages = self.state.inline_text(language, self.lineno)
        titlenode = nodes.title(language, '', *title)

        sectionnode += titlenode
        sectionnode += messages
        self.state.document.note_implicit_target(sectionnode, sectionnode)

        self.state.nested_parse(self.content, self.content_offset, sectionnode)

        return [indexnode, targetnode, sectionnode]
Example #16
0
    def run(self):
        env = self.state.document.settings.env
        # normalize whitespace in fullname like XRefRole does
        fullname = ws_re.sub(' ', self.arguments[0].strip())
        targetname = '%s-%s' % (self.ref_type, fullname)

        # keep the target; this may be used to generate a BBIndex later
        targets = env.domaindata['bb']['targets'].setdefault(self.ref_type, {})
        targets[fullname] = env.docname, targetname

        # make up the descriptor: a target and potentially an index descriptor
        node = nodes.target('', '', ids=[targetname])
        ret = [node]

        # add the target to the document
        self.state.document.note_explicit_target(node)

        # append the index node if necessary
        entries = []
        for tpl in self.indextemplates:
            colon = tpl.find(':')
            if colon != -1:
                indextype = tpl[:colon].strip()
                indexentry = tpl[colon+1:].strip() % (fullname,)
            else:
                indextype = 'single'
                indexentry = tpl % (fullname,)
            entries.append((indextype, indexentry, targetname, targetname))

        if entries:
            inode = addnodes.index(entries=entries)
            ret.insert(0, inode)

        return ret 
Example #17
0
def make_glossary_term(env, textnodes, index_key, source, lineno, new_id=None):
    # type: (BuildEnvironment, Iterable[nodes.Node], str, str, int, str) -> nodes.term
    # get a text-only representation of the term and register it
    # as a cross-reference target
    term = nodes.term('', '', *textnodes)
    term.source = source
    term.line = lineno

    gloss_entries = env.temp_data.setdefault('gloss_entries', set())
    termtext = term.astext()
    if new_id is None:
        new_id = nodes.make_id('term-' + termtext)
    if new_id in gloss_entries:
        new_id = 'term-' + str(len(gloss_entries))
    gloss_entries.add(new_id)

    std = cast(StandardDomain, env.get_domain('std'))
    std.add_object('term', termtext.lower(), env.docname, new_id)

    # add an index entry too
    indexnode = addnodes.index()
    indexnode['entries'] = [('single', termtext, new_id, 'main', index_key)]
    indexnode.source, indexnode.line = term.source, term.line
    term.append(indexnode)
    term['ids'].append(new_id)
    term['names'].append(new_id)

    return term
Example #18
0
    def run(self):
        # type: () -> List[nodes.Node]
        # normalize whitespace in fullname like XRefRole does
        fullname = ws_re.sub(' ', self.arguments[0].strip())
        targetname = '%s-%s' % (self.name, fullname)
        node = nodes.target('', '', ids=[targetname])
        self.state.document.note_explicit_target(node)
        ret = [node]  # type: List[nodes.Node]
        if self.indextemplate:
            indexentry = self.indextemplate % (fullname,)
            indextype = 'single'
            colon = indexentry.find(':')
            if colon != -1:
                indextype = indexentry[:colon].strip()
                indexentry = indexentry[colon + 1:].strip()
            inode = addnodes.index(entries=[(indextype, indexentry,
                                             targetname, '', None)])
            ret.insert(0, inode)
        name = self.name
        if ':' in self.name:
            _, name = self.name.split(':', 1)

        std = cast(StandardDomain, self.env.get_domain('std'))
        std.add_object(name, fullname, self.env.docname, targetname)

        return ret
Example #19
0
def indexmarkup_role(typ, rawtext, text, lineno, inliner,
                     options={}, content=[]):
    """Role for PEP/RFC references that generate an index entry."""
    env = inliner.document.settings.env
    if not typ:
        typ = env.config.default_role
    else:
        typ = typ.lower()
    has_explicit_title, title, target = split_explicit_title(text)  # type: bool, unicode, unicode  # NOQA
    title = utils.unescape(title)
    target = utils.unescape(target)
    targetid = 'index-%s' % env.new_serialno('index')
    indexnode = addnodes.index()
    targetnode = nodes.target('', '', ids=[targetid])
    inliner.document.note_explicit_target(targetnode)
    if typ == 'pep':
        indexnode['entries'] = [
            ('single', _('Python Enhancement Proposals; PEP %s') % target,
             targetid, '', None)]
        anchor = ''  # type: unicode
        anchorindex = target.find('#')
        if anchorindex > 0:
            target, anchor = target[:anchorindex], target[anchorindex:]
        if not has_explicit_title:
            title = "PEP " + utils.unescape(title)
        try:
            pepnum = int(target)
        except ValueError:
            msg = inliner.reporter.error('invalid PEP number %s' % target,
                                         line=lineno)
            prb = inliner.problematic(rawtext, rawtext, msg)
            return [prb], [msg]
        ref = inliner.document.settings.pep_base_url + 'pep-%04d' % pepnum
        sn = nodes.strong(title, title)
        rn = nodes.reference('', '', internal=False, refuri=ref+anchor,
                             classes=[typ])
        rn += sn
        return [indexnode, targetnode, rn], []
    elif typ == 'rfc':
        indexnode['entries'] = [
            ('single', 'RFC; RFC %s' % target, targetid, '', None)]
        anchor = ''
        anchorindex = target.find('#')
        if anchorindex > 0:
            target, anchor = target[:anchorindex], target[anchorindex:]
        if not has_explicit_title:
            title = "RFC " + utils.unescape(title)
        try:
            rfcnum = int(target)
        except ValueError:
            msg = inliner.reporter.error('invalid RFC number %s' % target,
                                         line=lineno)
            prb = inliner.problematic(rawtext, rawtext, msg)
            return [prb], [msg]
        ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum
        sn = nodes.strong(title, title)
        rn = nodes.reference('', '', internal=False, refuri=ref+anchor,
                             classes=[typ])
        rn += sn
        return [indexnode, targetnode, rn], []
Example #20
0
    def run(self):
        env = self.state.document.settings.env
        modname = self.arguments[0].strip()
        noindex = 'noindex' in self.options
        env.temp_data['lua:module'] = modname
        ret = []
        if not noindex:
            env.domaindata['lua']['modules'][modname] = \
                (env.docname, self.options.get('synopsis', ''),
                 self.options.get('platform', ''), 'deprecated' in self.options)

            ids = "lua-module.%s" % (modname)

            # make a duplicate entry in 'objects' to facilitate searching for
            # the module in LuaDomain.find_obj()
            env.domaindata['lua']['objects'][modname] = (env.docname, 'module', ids)
            targetnode = nodes.target('', '', ids=[ids],
                                      ismod=True)
            self.state.document.note_explicit_target(targetnode)
            # the platform and synopsis aren't printed; in fact, they are only
            # used in the modindex currently
            ret.append(targetnode)
            indextext = _('%s (module)') % modname
            inode = addnodes.index(entries=[('single', indextext,
                                             ids, '')])
            ret.append(inode)
        return ret
Example #21
0
    def run(self):
        env = self.state.document.settings.env
        node = addnodes.glossary()
        node.document = self.state.document
        self.state.nested_parse(self.content, self.content_offset, node)

        # the content should be definition lists
        dls = [child for child in node
               if isinstance(child, nodes.definition_list)]
        # now, extract definition terms to enable cross-reference creation
        new_dl = nodes.definition_list()
        new_dl['classes'].append('glossary')
        items = []
        for dl in dls:
            for li in dl.children:
                if not li.children or not isinstance(li[0], nodes.term):
                    continue
                termtext = li.children[0].astext()
                new_id = 'term-' + nodes.make_id(termtext)
                if new_id in env.gloss_entries:
                    new_id = 'term-' + str(len(env.gloss_entries))
                env.gloss_entries.add(new_id)
                li[0]['names'].append(new_id)
                li[0]['ids'].append(new_id)
                env.note_reftarget('term', termtext.lower(), new_id)
                # add an index entry too
                indexnode = addnodes.index()
                indexnode['entries'] = [('single', termtext, new_id, termtext)]
                li.insert(0, indexnode)
                items.append((termtext, li))
        if 'sorted' in self.options:
            items.sort(key=lambda x: x[0].lower())
        new_dl.extend(item[1] for item in items)
        node.children = [new_dl]
        return [node]
Example #22
0
 def run(self):
     env = self.state.document.settings.env
     modname = self.arguments[0].strip()
     noindex = 'noindex' in self.options
     env.currmodule = modname
     env.note_module(modname, self.options.get('synopsis', ''),
                     self.options.get('platform', ''),
                     'deprecated' in self.options)
     modulenode = addnodes.module()
     modulenode['modname'] = modname
     modulenode['synopsis'] = self.options.get('synopsis', '')
     targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True)
     self.state.document.note_explicit_target(targetnode)
     ret = [modulenode, targetnode]
     if 'platform' in self.options:
         platform = self.options['platform']
         modulenode['platform'] = platform
         node = nodes.paragraph()
         node += nodes.emphasis('', _('Platforms: '))
         node += nodes.Text(platform, platform)
         ret.append(node)
     # the synopsis isn't printed; in fact, it is only used in the
     # modindex currently
     if not noindex:
         indextext = _('%s (module)') % modname
         inode = addnodes.index(entries=[('single', indextext,
                                          'module-' + modname, modname)])
         ret.insert(0, inode)
     return ret
Example #23
0
def index_directive(name, arguments, options, content, lineno,
                    content_offset, block_text, state, state_machine):
    arguments = arguments[0].split('\n')
    env = state.document.settings.env
    targetid = 'index-%s' % env.index_num
    env.index_num += 1
    targetnode = nodes.target('', '', ids=[targetid])
    state.document.note_explicit_target(targetnode)
    indexnode = addnodes.index()
    indexnode['entries'] = ne = []
    for entry in arguments:
        entry = entry.strip()
        for type in pairindextypes:
            if entry.startswith(type+':'):
                value = entry[len(type)+1:].strip()
                value = pairindextypes[type] + '; ' + value
                ne.append(('pair', value, targetid, value))
                break
        else:
            for type in indextypes:
                if entry.startswith(type+':'):
                    value = entry[len(type)+1:].strip()
                    ne.append((type, value, targetid, value))
                    break
            # shorthand notation for single entries
            else:
                for value in entry.split(','):
                    value = value.strip()
                    if not value:
                        continue
                    ne.append(('single', value, targetid, value))
    return [indexnode, targetnode]
Example #24
0
    def role(name, rawtext, text, lineno, inliner, options={}, content=[]):

        env = inliner.document.settings.env

        # Generic index entries
        indexnode = addnodes.index()
        indexnode['entries'] = []
        
        try:
            platform, version = text.split(' ', 1)
            targetid = 'os-{}-{}-{}'.format(platform, version, env.new_serialno('os'))
            indexnode['entries'].append([
                'single',
                'Platform; {}; {}'.format(platform, version),
                targetid, '', None
            ])            
        except ValueError:
            platform = text
            version = ''
            targetid = 'os-{}-{}-{}'.format(platform, version, env.new_serialno('os'))            
            indexnode['entries'].append([
                'single',
                'Platform; {}'.format(platform),
                targetid, '', None
            ])

        targetnode = nodes.target('', '', ids=[targetid])

        text_node = nodes.strong(text='{}'.format(text))
        
        return [targetnode, text_node, indexnode], []
Example #25
0
    def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
        #version = self.arguments[0]
        #summary = self.arguments[1]
        version, summary = text.split(':', 1)
        summary = summary.strip()
        
        indexstring = 'bareos-{}; {}'.format(version, summary)
        idstring = 'bareos-{}-{}'.format(version, summary)
        _id = nodes.make_id(idstring)
        
        # Generic index entries
        indexnode = addnodes.index()
        indexnode['entries'] = []

        indexnode['entries'].append([
            'pair',
            indexstring,
            _id, '', None
        ])

        targetnode = nodes.target('', '', ids=[_id])

        #text_node = nodes.Text(text='Version >= {}'.format(version))
        #text_node = nodes.strong(text='Version >= {}'.format(version))
        text_node = nodes.emphasis(text='Version >= {}'.format(version))
        # target does not work with generated.
        #text_node = nodes.generated(text='Version >= {}'.format(version))
        
        return [targetnode, text_node, indexnode], []
Example #26
0
 def run(self):
     populated = CPPAutoDocObject._populate(self)
     indexnode = addnodes.index(entries=[])
     title = '{name} Namespace Reference'.format(name = self._get_name())
     main_section = self._make_main_section(title)
     if populated:
         obj = self._get_obj()
         section = self._make_section('Introduction')
         section += self._make_brief(obj)
         main_section += section
         section = self._make_section('Inner Definitions')
         main_section += section
         section += self._make_innernamespaces(obj)
         section += self._make_innermacros(obj)
         section += self._make_innertypes(obj)
         section += self._make_innerclasses(obj)
         section += self._make_innerfunctions(obj)
         section = self._make_section('Detailed Description')
         section += self._make_details(obj)
         main_section += section
         main_section += self._make_methods_documentation(obj)
         main_section += self._make_enums_documentation(obj)
     else:
         main_section += nodes.paragraph(text='Unknown Namespace.')
     return [indexnode, main_section]
Example #27
0
 def run(self):
     env = self.state.document.settings.env
     modname = self.arguments[0].strip()
     noindex = "noindex" in self.options
     env.ref_context["py:module"] = modname
     ret = []
     if not noindex:
         env.domaindata["py"]["modules"][modname] = (
             env.docname,
             self.options.get("synopsis", ""),
             self.options.get("platform", ""),
             "deprecated" in self.options,
         )
         # make a duplicate entry in 'objects' to facilitate searching for
         # the module in PythonDomain.find_obj()
         env.domaindata["py"]["objects"][modname] = (env.docname, "module")
         targetnode = nodes.target("", "", ids=["module-" + modname], ismod=True)
         self.state.document.note_explicit_target(targetnode)
         # the platform and synopsis aren't printed; in fact, they are only
         # used in the modindex currently
         ret.append(targetnode)
         indextext = _("%s (module)") % modname
         inode = addnodes.index(entries=[("single", indextext, "module-" + modname, "", None)])
         ret.append(inode)
     return ret
 def create_index_node(self, env, tag, attributes):
     if sphinx.version_info[:2] < (1, 4):  # Sphinx earlier than v1.4
         entries = [("single", tag, tag, "")]
     else:  # Sphinx v1.4 and later
         entries = [("single", tag, tag, "", None)]
     index_node = addnodes.index()
     index_node["entries"] = entries
     return index_node
Example #29
0
 def run(self):
     populated = CPPAutoDocObject._populate(self)
     indexnode = addnodes.index(entries=[])
     main_node = addnodes.desc()
     main_node['objtype'] = 'type'
     if populated:
         obj = self._get_obj()
         main_node += self._make_typedef_documentation(obj)
     return [indexnode, main_node]
Example #30
0
    def run(self):
        """Same as :meth:`sphinx.directives.ObjectDescription`
        but using :class:`FortranDocFieldTransformer`"""
        if ':' in self.name:
            self.domain, self.objtype = self.name.split(':', 1)
        else:
            self.domain, self.objtype = '', self.name
        self.env = self.state.document.settings.env
        self.indexnode = addnodes.index(entries=[])

        node = addnodes.desc()
        node.document = self.state.document
        node['domain'] = self.domain
        # 'desctype' is a backwards compatible attribute
        node['objtype'] = node['desctype'] = self.objtype
        node['noindex'] = noindex = ('noindex' in self.options)

        self.names = []
        signatures = self.get_signatures()
        for i, sig in enumerate(signatures):
            # add a signature node for each signature in the current unit
            # and add a reference target for it
            signode = addnodes.desc_signature(sig, '')
            signode['first'] = False
            node.append(signode)
            try:
                # name can also be a tuple, e.g. (classname, objname);
                # this is strictly domain-specific (i.e. no assumptions may
                # be made in this base class)
                name = self.handle_signature(sig, signode)
            except ValueError:
                # signature parsing failed
                signode.clear()
                signode += addnodes.desc_name(sig, sig)
                continue  # we don't want an index entry here
            if not isinstance(name[0], unicode):
                name = (unicode(name), name[1])
            if not noindex and name not in self.names:
                # only add target and index entry if this is the first
                # description of the object with this name in this desc block
                self.names.append(name)
                self.add_target_and_index(name, sig, signode)

        modname = signode.get('module')
        typename = signode.get('type')
        contentnode = addnodes.desc_content()
        node.append(contentnode)
        if self.names:
            # needed for association of version{added,changed} directives
            self.env.temp_data['object'] = self.names[0]
        self.before_content()
        self.state.nested_parse(self.content, self.content_offset, contentnode)
        FortranDocFieldTransformer(self, modname=modname, typename=typename).transform_all(contentnode)
        self.env.temp_data['object'] = None
        self.after_content()
        return [self.indexnode, node]
Example #31
0
 def run(self):
     # type: () -> List[nodes.Node]
     arguments = self.arguments[0].split('\n')
     targetid = 'index-%s' % self.env.new_serialno('index')
     targetnode = nodes.target('', '', ids=[targetid])
     self.state.document.note_explicit_target(targetnode)
     indexnode = addnodes.index()
     indexnode['entries'] = []
     indexnode['inline'] = False
     set_source_info(self, indexnode)
     for entry in arguments:
         indexnode['entries'].extend(process_index_entry(entry, targetid))
     return [indexnode, targetnode]
Example #32
0
 def result_nodes(self, document, env, node, is_ref):
     if not is_ref:
         return [node], []
     varname = node['reftarget']
     tgtid = 'index-%s' % env.new_serialno('index')
     indexnode = addnodes.index()
     indexnode['entries'] = [
         ('single', varname, tgtid, ''),
         ('single', _('environment variable; %s') % varname, tgtid, '')
     ]
     targetnode = nodes.target('', '', ids=[tgtid])
     document.note_explicit_target(targetnode)
     return [indexnode, targetnode, node], []
Example #33
0
 def result_nodes(self, document, env, node, is_ref):
     if not is_ref:
         return [node], []
     varname = node["reftarget"]
     tgtid = "index-%s" % env.new_serialno("index")
     indexnode = addnodes.index()
     indexnode["entries"] = [
         ("single", varname, tgtid, varname, None),
         ("single", "configuration section; %s" % varname, tgtid, varname, None),
     ]
     targetnode = nodes.target("", "", ids=[tgtid])
     document.note_explicit_target(targetnode)
     return [indexnode, targetnode, node], []
Example #34
0
 def result_nodes(self, document: nodes.document, env: "BuildEnvironment", node: Element,
                  is_ref: bool) -> Tuple[List[Node], List[system_message]]:
     if not is_ref:
         return [node], []
     varname = node['reftarget']
     tgtid = 'index-%s' % env.new_serialno('index')
     indexnode = addnodes.index()
     indexnode['entries'] = [
         ('single', varname, tgtid, '', None),
         ('single', _('environment variable; %s') % varname, tgtid, '', None)
     ]
     targetnode = nodes.target('', '', ids=[tgtid])
     document.note_explicit_target(targetnode)
     return [indexnode, targetnode, node], []
Example #35
0
 def result_nodes(self, document, env, node, is_ref):
     # type: (nodes.Node, BuildEnvironment, nodes.Node, bool) -> Tuple[List[nodes.Node], List[nodes.Node]]  # NOQA
     if not is_ref:
         return [node], []
     varname = node['reftarget']
     tgtid = 'index-%s' % env.new_serialno('index')
     indexnode = addnodes.index()
     indexnode['entries'] = [
         ('single', varname, tgtid, '', None),
         ('single', _('environment variable; %s') % varname, tgtid, '', None)
     ]
     targetnode = nodes.target('', '', ids=[tgtid])
     document.note_explicit_target(targetnode)
     return [indexnode, targetnode, node], []
Example #36
0
 def run(self):
     env = self.state.document.settings.env
     modname = self.arguments[0].strip()
     env.temp_data['coffee:module'] = modname
     targetnode = nodes.target('',
                               '',
                               ids=['module-' + modname],
                               ismod=True)
     self.state.document.note_explicit_target(targetnode)
     indextext = _('%s (module)') % modname
     inode = addnodes.index(entries=[('single', indextext,
                                      'module-' + modname, '')])
     #section = nodes.section()
     return [nodes.title('', modname), targetnode, inode]
Example #37
0
    def run(self):
        self.env = self.state.document.settings.env
        modname = self.arguments[0].strip()

        try:
            modname = ErlangSignature.canon_atom(modname)
            modname_error = False
        except ValueError:
            _warn(self.env,
                  'invalid Erlang module name: %s',
                  modname,
                  location=(self.env.docname, self.lineno))
            modname = "'invalid-module-name'"
            modname_error = True

        _ref_context(self.env)['erl:module'] = modname

        if 'noindex' in self.options:
            return []

        targetnode = nodes.target('',
                                  '',
                                  ids=['module-' + modname],
                                  ismod=True)
        self.state.document.note_explicit_target(targetnode)

        if not modname_error:
            minv = self.env.domaindata['erl']['modules']
            if modname not in minv:
                minv[modname] = (self.env.docname,
                                 self.options.get('synopsis', ''),
                                 self.options.get('platform', ''), 'deprecated'
                                 in self.options)
            else:
                _warn(
                    self.env,
                    'duplicate Erlang module name of %s, other instance in %s.',
                    modname,
                    self.env.doc2path(minv[modname][0]),
                    location=(self.env.docname, self.lineno))

        # the synopsis isn't printed; in fact, it is only used in the
        # modindex currently
        indextext = _('%s (Erlang module)') % modname
        inode = addnodes.index(entries=[
            _indexentry('single', indextext, 'module-' +
                        modname, modname, None)
        ])
        return [targetnode, inode]
Example #38
0
def make_glossary_term(env: "BuildEnvironment",
                       textnodes: Iterable[Node],
                       index_key: str,
                       source: str,
                       lineno: int,
                       node_id: str = None,
                       document: nodes.document = None) -> nodes.term:
    # get a text-only representation of the term and register it
    # as a cross-reference target
    term = nodes.term('', '', *textnodes)
    term.source = source
    term.line = lineno
    termtext = term.astext()

    if node_id:
        # node_id is given from outside (mainly i18n module), use it forcedly
        term['ids'].append(node_id)
    elif document:
        node_id = make_id(env, document, 'term', termtext)
        term['ids'].append(node_id)
        document.note_explicit_target(term)
    else:
        warnings.warn(
            'make_glossary_term() expects document is passed as an argument.',
            RemovedInSphinx40Warning)
        gloss_entries = env.temp_data.setdefault('gloss_entries', set())
        node_id = nodes.make_id('term-' + termtext)
        if node_id == 'term':
            # "term" is not good for node_id.  Generate it by sequence number instead.
            node_id = 'term-%d' % env.new_serialno('glossary')

        while node_id in gloss_entries:
            node_id = 'term-%d' % env.new_serialno('glossary')
        gloss_entries.add(node_id)
        term['ids'].append(node_id)

    std = cast(StandardDomain, env.get_domain('std'))
    std.note_object('term',
                    termtext.lower(),
                    node_id,
                    location=(env.docname, lineno))

    # add an index entry too
    indexnode = addnodes.index()
    indexnode['entries'] = [('single', termtext, node_id, 'main', index_key)]
    indexnode.source, indexnode.line = term.source, term.line
    term.append(indexnode)

    return term
Example #39
0
 def result_nodes(self, document, env, node, is_ref):
     try:
         indexnode = addnodes.index()
         targetid = 'index-%s' % env.new_serialno('index')
         targetnode = nodes.target('', '', ids=[targetid])
         doctitle = list(document.traverse(nodes.title))[0].astext()
         idxtext = "%s; %s" % (node.astext(), doctitle)
         idxtext2 = "%s; %s" % ('sourcefile', node.astext())
         indexnode['entries'] = [
             ('single', idxtext, targetid, '', None),
             ('single', idxtext2, targetid, '', None),
         ]
         return [indexnode, targetnode, node], []
     except KeyError as e:
         return [node], [e.args[0]]
    def run(self):
        env = self.state.document.settings.env
        app = env.app

        group_name = self.arguments[0]
        namespace = self.options.get('namespace')

        cached_groups = env.domaindata['oslo.config']['groups']

        # Store the current group for use later in option directives
        env.temp_data['oslo.config:group'] = group_name
        app.debug('oslo.config group %s' % group_name)

        # Store the location where this group is being defined
        # for use when resolving cross-references later.
        # FIXME: This should take the source namespace into account, too
        cached_groups[group_name] = env.docname

        result = ViewList()
        source_name = '<' + __name__ + '>'

        def _add(text):
            "Append some text to the output result view to be parsed."
            result.append(text, source_name)

        if namespace:
            title = '%s: %s' % (namespace, group_name)
        else:
            title = group_name

        _add(title)
        _add('-' * len(title))
        _add('')
        for line in self.content:
            _add(line)
        node = nodes.section()
        node.document = self.state.document
        nested_parse_with_titles(self.state, result, node)

        first_child = node.children[0]

        # Compute the normalized target and set the node to have that
        # as an id
        target_name = cfg._normalize_group_name(group_name)
        first_child['ids'].append(target_name)

        indexnode = addnodes.index(entries=[])
        return [indexnode] + node.children
Example #41
0
def omero_command_role(typ, rawtext, etext, lineno, inliner,
                     options={}, content=[]):
    """Role for CLI commands that generates an index entry."""

    env = inliner.document.settings.env
    targetid = 'cmd-%s' % env.new_serialno('index')

    # Create index and target nodes
    indexnode = addnodes.index()
    targetnode = nodes.target('', '', ids=[targetid])
    inliner.document.note_explicit_target(targetnode)
    indexnode['entries'] = [('single', "omero " + "; ".join(etext.split(" ")), targetid, '')]

    # Mark the text using literal node
    sn = nodes.literal('omero ' + etext, 'omero ' +  etext)
    return [indexnode, targetnode, sn], []
Example #42
0
    def run(self):
        """
        Main directive entry function, called by docutils upon encountering the
        directive.

        This directive is meant to be quite easily subclassable, so it delegates
        to several additional methods.  What it does:

        * find out if called as a domain-specific directive, set self.domain
        * create a `desc` node to fit all description inside
        * parse standard options, currently `noindex`
        * create an index node if needed as self.indexnode
        * parse all given signatures (as returned by self.get_signatures())
          using self.handle_signature(), which should either return a name
          or raise ValueError
        * add index entries using self.add_target_and_index()
        * parse the content and handle doc fields in it
        """


        # set info for sphinx_directive
        self.sphinx_directive.objtype = self.objtype
        self.sphinx_directive.domain = self.domain
        self.sphinx_directive.env = self.sphinx_directive.state.document.settings.env
        self.sphinx_directive.indexnode = addnodes.index(entries=[])

        # setup this node
        self.node = addnodes.desc()
        self.node.document = self.sphinx_directive.state.document
        self.node['domain'] = self.domain

        # 'desctype' is a backwards compatible attribute
        self.node['objtype'] = self.node['desctype'] = self.sphinx_directive.objtype
        self.node['noindex'] = noindex = ('noindex' in self.sphinx_directive.options)
        self.noindex = noindex 

        self.sphinx_directive.names = []

        # get renderer
        self.data_object_renderer = self.get_data_object_renderer()

        #self.data_object_renderer.handle()
        self.node.extend(self.data_object_renderer.render())


        return [self.sphinx_directive.indexnode, self.node]
Example #43
0
File: nscp.py Project: r1se/nscp
	def run(self):
		env = self.state.document.settings.env
		modname = self.arguments[0].strip()
		noindex = 'noindex' in self.options
		env.temp_data['nscp:module'] = modname
		env.domaindata['nscp']['modules'][modname] = (env.docname, self.options.get('synopsis', ''), 'deprecated' in self.options)
		ret = []
		if not noindex:
			targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True)
			self.state.document.note_explicit_target(targetnode)
			# the platform and synopsis aren't printed; in fact, they are only
			# used in the modindex currently
			ret.append(targetnode)
			indextext = _('%s (module)') % modname
			inode = addnodes.index(entries=[('single', indextext, modname, '')])
			ret.append(inode)
		return ret
Example #44
0
    def run(self):
        # type: () -> Tuple[List[nodes.Node], List[nodes.system_message]]  # NOQA
        target_id = "index-%s" % self.env.new_serialno("index")

        self.http_type = self.name.lower()[4:]
        if self.http_type not in HTTPRole.NAME_MAP:
            msg = self.inliner.reporter.error("invalid HTTP reference %s" %
                                              self.name,
                                              line=self.lineno)
            prb = self.inliner.problematic(self.rawtext, self.rawtext, msg)
            return [prb], [msg]

        entries = [(
            "single",
            "HTTP; HTTP %s %s" % (self.http_type, self.target),
            target_id,
            "",
            None,
        )]

        index = addnodes.index(entries=entries)
        target = nodes.target("", "", ids=[target_id])
        self.inliner.document.note_explicit_target(target)

        try:
            refuri = self.build_uri()
            reference = nodes.reference("",
                                        "",
                                        internal=False,
                                        refuri=refuri,
                                        classes=["rfc"])
            if self.has_explicit_title:
                reference += nodes.strong(self.title, self.title)
            else:
                title = "HTTP %s %s " % (self.http_type, self.target)
                if _is_status(self):
                    title += " " + httpclient.responses[int(self.target)]
                reference += nodes.strong(title, title)
        except ValueError:
            msg = self.inliner.reporter.error(
                "invalid HTTP mozilla reference %s" % self.target,
                line=self.lineno)
            prb = self.inliner.problematic(self.rawtext, self.rawtext, msg)
            return [prb], [msg]

        return [index, target, reference], []
Example #45
0
    def run(self):
        env = self.state.document.settings.env
        directory = normalized_directory_name(self.arguments[0].strip())
        env.temp_data['snip:directory'] = directory

        if 'noindex' not in self.options:
            # create an index entry
            directories = env.domaindata['snip']['directories']
            directories[directory] = DirectoryEntry(env.docname)
            target = nodes.target('', '', ids=[directory])
            self.state.document.note_explicit_target(target)
            indextext = '{0} (snippet directory)'.format(directory)
            index = addnodes.index(
                entries=[('single', indextext, directory, '')])
            return [target, index]
        else:
            return []
Example #46
0
    def run(self):
        env = self.state.document.settings.env
        section = self.arguments[0].strip()

        if ':' in self.name:
            self.domain, self.objtype = self.name.split(':', 1)
        else:
            self.domain, self.objtype = '', self.name

        if section == 'None':
            env.ref_context.pop(self.section_key, None)
            return []

        env.ref_context[self.section_key] = section
        targetname = self.target_prefix + section
        node = nodes.target('', '', ids=[targetname])
        self.state.document.note_explicit_target(node)

        indexentry = self.get_index_entry(section)

        inode = addnodes.index(
            entries = [
                (self.indextype, indexentry, targetname, '', None)])

        # find title of parent section node
        title = find_section_title(self.state.parent)

        data_key = CabalDomain.types[self.objtype]

        # find how many sections in this document were added
        num = env.domaindata['cabal']['index-num'].get(env.docname, 0)
        env.domaindata['cabal']['index-num'][env.docname] = num + 1

        meta = Meta(since=self.options.get('since'),
                    deprecated=self.options.get('deprecated'),
                    removed=self.options.get('removed'),
                    synopsis=self.options.get('synopsis'),
                    index = num,
                    title = title)

        store = env.domaindata['cabal'][data_key]
        if not section in store:
            store[section] = env.docname, targetname, meta

        return [inode, node]
Example #47
0
    def run(self):
        env = self.state.document.settings.env
        workspace_name = self.arguments[0].strip()
        workspace_path = self.options.get('path', '')
        env.ref_context['bazel:workspace'] = workspace_name
        ret = []

        env.domaindata['bazel']['workspaces'][workspace_name] = (env.docname,
                                                                 workspace_path)
        # make a duplicate entry in 'objects' to facilitate searching for
        # the module in PythonDomain.find_obj()
        env.domaindata['bazel']['objects'][workspace_name] = (env.docname, 'workspace')
        targetnode = nodes.target('', '', ids=['workspace-' + workspace_name],
                                  ismod=True)
        self.state.document.note_explicit_target(targetnode)
        # the platform and synopsis aren't printed; in fact, they are only
        # used in the modindex currently
        ret.append(targetnode)
        indextext = _('%s (workspace)') % workspace_name
        inode = addnodes.index(entries=[('single', indextext,
                                         'module-' + workspace_name, '', None)])
        ret.append(inode)

        if self.options.get('hide', False) is None:
            # No output is wanted
            return ret

        workspace_string = workspace_name
        if self.options.get('show_type', False) is None:
            sig_type_string = 'workspace: '
            ret.append(addnodes.desc_name(sig_type_string, sig_type_string,
                                          classes=['bazel', 'type', 'workspace']))

        if workspace_path:
            workspace_string += ' ({})'.format(workspace_path)

        workspace_name_node = addnodes.desc_name(workspace_string, workspace_string)

        ret.append(workspace_name_node)

        contentnode = addnodes.desc_content()
        ret.append(contentnode)
        self.state.nested_parse(self.content, self.content_offset, contentnode)
        # DocFieldTransformer(self).transform_all(contentnode)
        return ret
 def __call__(self,
              name,
              rawtext,
              text,
              lineno,
              inliner,
              options={},
              content=[]):
     targetnode = nodes.target('', '')
     inliner.document.note_explicit_target(targetnode)
     targetid = targetnode['ids'][0]
     indexnode = addnodes.index()
     indexnode['entries'] = ne = []
     indexnode['inline'] = True
     indexnode.source, indexnode.line = inliner.document.current_source, lineno
     ne.extend(process_index_entry(text, targetid))
     textnode = self.node_class(text, text)
     return ([textnode, indexnode, targetnode], [])
Example #49
0
    def run(self):
        env = self.state.document.settings.env
        statename = self.arguments[0].strip()

        if "noindex" in self.options:
            return []

        targetnode = nodes.target("", "", ids=["module-" + statename], ismod=True)
        self.state.document.note_explicit_target(targetnode)

        formula = env.temp_data.get("salt:formula")

        indextext = "{1} ({0}-formula)".format(formula, statename)
        inode = addnodes.index(
            entries=[("single", indextext, "module-{}".format(statename), "")]
        )

        return [targetnode, inode]
Example #50
0
    def apply(self):
        env = self.document.settings.env

        # Treat some documents as ecm domain objects.
        objtype, sep, tail = env.docname.rpartition('/')
        make_index_entry = _ecm_index_objs.get(objtype)
        if make_index_entry:
            title = self.parse_title(env.docname)
            # Insert the object link target.
            targetid = '%s:%s' % (objtype, title)
            targetnode = nodes.target('', '', ids=[targetid])
            self.document.insert(0, targetnode)
            # Insert the object index entry.
            indexnode = addnodes.index()
            indexnode['entries'] = [make_index_entry(title, targetid)]
            self.document.insert(0, indexnode)
            # Add to ecm domain object inventory
            _ecm_object_inventory(env, self.document, 1, objtype, targetid)
Example #51
0
    def run(self):
        env = self.state.document.settings.env

        cppmethod = CppMethod()
        cppmethod['name'] = self.arguments[0]  # TODO: parse name

        targetname = '%s-%s' % ('cppmethod', cppmethod['name'])
        targetnode = nodes.target('', '', ids=[targetname])
        self.state.document.note_explicit_target(targetnode)

        indextext = _('%s (C++ method)') % cppmethod['name']
        inode = addnodes.index(entries=[('single', indextext,
                                         'cppmethod-' + cppmethod['name'],
                                         cppmethod['name'])])

        self.state.nested_parse(self.content, self.content_offset, cppmethod)

        return [inode, targetnode, cppmethod]
Example #52
0
    def run(self) -> List[Node]:
        arguments = self.arguments[0].split('\n')

        if 'name' in self.options:
            targetname = self.options['name']
            targetnode = nodes.target('', '', names=[targetname])
        else:
            targetid = 'index-%s' % self.env.new_serialno('index')
            targetnode = nodes.target('', '', ids=[targetid])

        self.state.document.note_explicit_target(targetnode)
        indexnode = addnodes.index()
        indexnode['entries'] = []
        indexnode['inline'] = False
        self.set_source_info(indexnode)
        for entry in arguments:
            indexnode['entries'].extend(process_index_entry(entry, targetnode['ids'][0]))
        return [indexnode, targetnode]
Example #53
0
    def run(self):
        env = self.state.document.settings.env
        statename = self.arguments[0].strip()

        if 'noindex' in self.options:
            return []

        targetnode = nodes.target('', '', ids=['module-' + statename],
                ismod=True)
        self.state.document.note_explicit_target(targetnode)

        formula = env.temp_data.get('salt:formula')

        indextext = u'{1} ({0}-formula)'.format(formula, statename)
        inode = addnodes.index(entries=[
            ('single', indextext, 'module-{0}'.format(statename), ''),
        ])

        return [targetnode, inode]
Example #54
0
 def result_nodes(self, document, env, node, is_ref):
     """Called before returning the finished nodes.  *node* is the reference
     node if one was created (*is_ref* is then true), else the content node.
     This method can add other nodes and must return a ``(nodes, messages)``
     tuple (the usual return value of a role function).
     """
     # this code adds index entries for each role instance
     if not is_ref:
         return [node], []
     varname = node['reftarget']
     tgtid = 'index-%s' % env.new_serialno('index')
     indexnode = addnodes.index()
     indexnode['entries'] = [
         ('single', varname, tgtid, ''),
         #('single', _('environment variable; %s') % varname, tgtid, ''),
     ]
     targetnode = nodes.target(node.rawsource, '', ids=[tgtid])
     document.note_explicit_target(targetnode)
     return [indexnode, targetnode, node], []
Example #55
0
    def _build_option_index(self, progname, ids, names, synopses):
        """
        Build index for program option and register it in the environment

        :param progname: program name
        :param ids: list of all option ids
        :param names: list of all option names
        :param synopses: list of all option synopses
        :return: index node
        """
        env = self.state.document.settings.env
        result = addnodes.index(entries=[])
        for id, name, synopsis in zip(ids, names, synopses):
            env.domaindata['std']['progoptions'][progname, name] = env.docname, id
            if synopsis != name:
                env.domaindata['std']['progoptions'][progname, synopsis] = env.docname, id
            pair = '{} command line option; {}'.format(progname, ', '.join(synopses))
            result['entries'].append(('pair', pair, id, '', None))
        return result
Example #56
0
    def _init(self, name: str, qualified_type_name: str):
        self._node_id = nodes.make_id(nodes.fully_normalize_name(name))
        self._node = ModelElementNode(ids=[self._node_id])
        self._parse_msgs = []
        self._target = nodes.target()
        self.state.add_target(self._node_id, '', self._target, self.lineno)

        ## add node to index
        name_in_index = 'ModelElement; ' + name
        target_anchor = self._node_id

        self._indexnode = addnodes.index()
        self._indexnode['entries'] = ne = []
        self._indexnode['inline'] = False
        set_source_info(self, self._indexnode)
        ne.extend(process_index_entry(name_in_index, target_anchor))

        self._model_element_type = reflectionutil.model_element_type(
            qualified_type_name=qualified_type_name, )
Example #57
0
    def _init(self, trait_name: str):
        self._node_id = trait_node_id_from_trait_name(trait_name)
        self._node = TraitNode(ids=[self._node_id])
        self._parse_msgs = []
        self._target = nodes.target()
        self.state.add_target(self._node_id, '', self._target, self.lineno)

        ## add node to index
        name_in_index = 'Trait; ' + trait_name
        target_anchor = self._node_id

        self._indexnode = addnodes.index()
        self._indexnode['entries'] = ne = []
        self._indexnode['inline'] = False
        set_source_info(self, self._indexnode)
        ne.extend(process_index_entry(name_in_index, target_anchor))

        self._trait_instance = reflectionutil.trait_instance(trait_name)
        self._trait_class = reflectionutil.trait_class(trait_name)
Example #58
0
    def run(self):
        env = self.state.document.settings.env

        cppclass = CppClass()
        cppclass['name'] = self.arguments[0]
        cppclass['derives'] = self.options.get('derives')

        targetname = '%s-%s' % ('cppclass', cppclass['name'])
        targetnode = nodes.target('', '', ids=[targetname])
        self.state.document.note_explicit_target(targetnode)

        indextext = _('%s (C++ class)') % cppclass['name']
        inode = addnodes.index(entries=[('single', indextext,
                                         'cppclass-' + cppclass['name'],
                                         cppclass['name'])])

        self.state.nested_parse(self.content, self.content_offset, cppclass)

        return [inode, targetnode, cppclass]
Example #59
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]
Example #60
0
    def handle_ada_decl(self, decl):
        # type: (lal.BasicDecl) -> Tuple[List[nodes.Node], N.desc_content]

        # Get the documentation content
        doc, annotations = self.get_documentation(decl)

        # Create sphinx nodes
        self.indexnode = N.index(entries=[])
        node = N.desc()
        node.document = self.state.document
        signode = N.desc_signature('', '')
        signode['first'] = False
        node.append(signode)

        # Do decl-type specific stuff in specialized methods
        handlers = [
            (lal.BasicSubpDecl, lal.ExprFunction, self.handle_subprogram_decl),
            (lal.BaseTypeDecl, self.handle_type_decl),
            (lal.ObjectDecl, self.handle_object_decl),
            (lal.PackageRenamingDecl, self.handle_package_renaming_decl),
            (lal.GenericPackageInstantiation, self.handle_package_inst),
            (lal.GenericSubpInstantiation, self.handle_subp_inst),
            (lal.ExceptionDecl, self.handle_exception_decl),
        ]
        for h in handlers:
            types, handler = h[:-1], h[-1]
            if isinstance(decl, types):
                handler(decl, node, signode, annotations)
                break
        else:
            self.handle_decl_generic(decl, node, signode, annotations)

        # Create the documentation's content
        content_node = N.desc_content()
        node.append(content_node)

        rst = ViewList()
        for i, l in enumerate(doc, 1):
            rst.append(l, 'no_file.rst', i)

        nested_parse_with_titles(self.state, rst, content_node)
        return [self.indexnode, node], content_node