Source

sphinx-vala-domain / sphinx / domains / vala.py

# -*- coding: utf-8 -*-
"""
    sphinx.domains.vala
    ~~~~~~~~~~~~~~~~~~~

    The Vala language domain.

    :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""
from sphinx.domains import Domain
from sphinx.util.compat import Directive


class ValaCurrentNamespace(Directive):
    """
    This directive tells Sphinx that we're documenting stuff in a namespace
    foo, you won't be able to reference this.
    """
    # TODO: add more tests for this once we have an object type

    has_content = False
    required_arguments = 1
    optional_arguments = 0
    final_argument_whitespace = False
    option_spec = {}

    def run(self):
        env = self.state.document.settings.env
        namespace = self.arguments[0].strip()
        if namespace == 'global':
            env.temp_data['vala:namespace'] = None
        else:
            env.temp_data['vala:namespace'] = namespace
        return []


class ValaDomain(Domain):
    """Vala language domain."""
    name = 'vala'
    label = 'Vala'
    # TODO: add object types for:
    #       - classes
    #       - methods
    #       - interfaces
    #       - structs
    #       - enums
    #       - errordomains
    #       - members
    #       - namespace? this could be used like a python module
    object_types = {}
    directives = {
        'currentnamespace': ValaCurrentNamespace,
    }
    roles = {}
    initial_data = {
        'objects': {}, # fullname -> docname, objtype
    }

    def clear_doc(self, docname):
        for fullname, (dn, objtype) in self.data['objects'].items():
            if dn == docname:
                del self.data['objects'][fullname]

    def get_objects(self):
        for fullname, (docname, objtype) in self.data['objects'].iteritems():
            yield fullname, fullname, objtype, docname, fullname, 1