本文整理匯總了Python中sphinx.domains.ObjType方法的典型用法代碼示例。如果您正苦於以下問題:Python domains.ObjType方法的具體用法?Python domains.ObjType怎麽用?Python domains.ObjType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sphinx.domains
的用法示例。
在下文中一共展示了domains.ObjType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
# 需要導入模塊: from sphinx import domains [as 別名]
# 或者: from sphinx.domains import ObjType [as 別名]
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"}