Skip to content

Commit

Permalink
Merge pull request #43 from club-1/contents-entries
Browse files Browse the repository at this point in the history
Add contents entries for object & :nocontentsentry:
  • Loading branch information
markstory authored Apr 9, 2023
2 parents e3e2f74 + 993b4c3 commit e335ccb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sphinxcontrib/phpdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class PhpObject(ObjectDescription):
"""
option_spec = {
'noindex': directives.flag,
'nocontentsentry': directives.flag,
'module': directives.unchanged,
}

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

def _object_hierarchy_parts(self, sig_node: addnodes.desc_signature):
if 'fullname' not in sig_node:
return ()
namespace = sig_node.get('namespace')
fullname = sig_node['fullname']

if isinstance(namespace, str):
return (namespace, *fullname.split('::'))
else:
return tuple(fullname.split('::'))

def _toc_entry_name(self, sig_node: addnodes.desc_signature) -> str:
if not sig_node.get('_toc_parts'):
return ''

config = self.env.app.config
objtype = sig_node.parent.get('objtype')
if config.add_function_parentheses and objtype in {'function', 'method'}:
parens = '()'
else:
parens = ''
*parents, name = sig_node['_toc_parts']
if config.toc_object_entries_show_parents == 'domain':
return sig_node.get('fullname', name) + parens
if config.toc_object_entries_show_parents == 'hide':
return name + parens
if config.toc_object_entries_show_parents == 'all':
if objtype in {'method', 'const', 'attr', 'staticmethod', 'case'} and len(parents) > 0:
name = parents.pop() + '::' + name
return '\\'.join(parents + [name + parens])
return ''

def get_index_text(self, modname, name):
"""
Return the text for the index entry of the object.
Expand Down

0 comments on commit e335ccb

Please sign in to comment.