Skip to content

Commit e335ccb

Browse files
authored
Merge pull request #43 from club-1/contents-entries
Add contents entries for object & :nocontentsentry:
2 parents e3e2f74 + 993b4c3 commit e335ccb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

sphinxcontrib/phpdomain.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class PhpObject(ObjectDescription):
115115
"""
116116
option_spec = {
117117
'noindex': directives.flag,
118+
'nocontentsentry': directives.flag,
118119
'module': directives.unchanged,
119120
}
120121

@@ -254,6 +255,38 @@ def handle_signature(self, sig, signode):
254255
signode += addnodes.desc_returns(enumtype, enumtype)
255256
return fullname, name_prefix
256257

258+
def _object_hierarchy_parts(self, sig_node: addnodes.desc_signature):
259+
if 'fullname' not in sig_node:
260+
return ()
261+
namespace = sig_node.get('namespace')
262+
fullname = sig_node['fullname']
263+
264+
if isinstance(namespace, str):
265+
return (namespace, *fullname.split('::'))
266+
else:
267+
return tuple(fullname.split('::'))
268+
269+
def _toc_entry_name(self, sig_node: addnodes.desc_signature) -> str:
270+
if not sig_node.get('_toc_parts'):
271+
return ''
272+
273+
config = self.env.app.config
274+
objtype = sig_node.parent.get('objtype')
275+
if config.add_function_parentheses and objtype in {'function', 'method'}:
276+
parens = '()'
277+
else:
278+
parens = ''
279+
*parents, name = sig_node['_toc_parts']
280+
if config.toc_object_entries_show_parents == 'domain':
281+
return sig_node.get('fullname', name) + parens
282+
if config.toc_object_entries_show_parents == 'hide':
283+
return name + parens
284+
if config.toc_object_entries_show_parents == 'all':
285+
if objtype in {'method', 'const', 'attr', 'staticmethod', 'case'} and len(parents) > 0:
286+
name = parents.pop() + '::' + name
287+
return '\\'.join(parents + [name + parens])
288+
return ''
289+
257290
def get_index_text(self, modname, name):
258291
"""
259292
Return the text for the index entry of the object.

0 commit comments

Comments
 (0)