Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contents entries for object & :nocontentsentry: #43

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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