Python sphinx.domains.ObjType() Examples

The following are 1 code examples of sphinx.domains.ObjType(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sphinx.domains , or try the search function .
Example #1
Source File: pydomain_patch.py    From law with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def setup(app):
    # get the py domain
    domain = app.registry.domains["py"]

    # add the new "classattribute" object type and directive
    domain.object_types["classattribute"] = ObjType(l_("classattribute"), "attr", "obj")
    domain.directives["classattribute"] = pyd.PyClassmember

    # patch get_index_text
    PyClassmember__get_index_text = pyd.PyClassmember.get_index_text

    def get_index_text(self, modname, name_cls):
        text = PyClassmember__get_index_text(self, modname, name_cls)

        if text != "":
            return text

        name, cls = name_cls
        add_modules = self.env.config.add_module_names

        if self.objtype == "classattribute":
            try:
                clsname, attrname = name.rsplit(".", 1)
            except ValueError:
                if modname:
                    return _("%s (in module %s)") % (name, modname)
                else:
                    return name
            if modname and add_modules:
                return _("%s (%s.%s class attribute)") % (attrname, modname, clsname)
            else:
                return _("%s (%s class attribute)") % (attrname, clsname)
        else:
            return ""

    pyd.PyClassmember.get_index_text = get_index_text

    # patch get_signature_prefix
    PyClassmember__get_signature_prefix = pyd.PyClassmember.get_signature_prefix

    def get_signature_prefix(self, sig):
        prefix = PyClassmember__get_signature_prefix(self, sig)

        if prefix != "":
            return prefix

        if self.objtype == "classattribute":
            return "classattribute "
        else:
            return ""

    pyd.PyClassmember.get_signature_prefix = get_signature_prefix

    return {"version": "patch"}