mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 18:57:34 +02:00
Render members
This commit is contained in:
@ -11,10 +11,12 @@ class Definition:
|
|||||||
'''A definition extracted by Doxygen.'''
|
'''A definition extracted by Doxygen.'''
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.params = None
|
||||||
|
|
||||||
# A map from Doxygen to HTML tags.
|
# A map from Doxygen to HTML tags.
|
||||||
tag_map = {
|
tag_map = {
|
||||||
'bold': 'b',
|
'bold': 'b',
|
||||||
|
'emphasis': 'em',
|
||||||
'computeroutput': 'code',
|
'computeroutput': 'code',
|
||||||
'para': 'p',
|
'para': 'p',
|
||||||
'programlisting': 'pre',
|
'programlisting': 'pre',
|
||||||
@ -80,6 +82,24 @@ def convert_param(param: et.Element) -> Definition:
|
|||||||
d.type = clean_type(type_str)
|
d.type = clean_type(type_str)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def render_decl(d: Definition) -> None:
|
||||||
|
text = '<pre><code class="language-cpp">'
|
||||||
|
if d.template_params is not None:
|
||||||
|
text += 'template <'
|
||||||
|
text += ', '.join(
|
||||||
|
[f'{p.type} {p.name}'.rstrip() for p in d.template_params])
|
||||||
|
text += '>\n'
|
||||||
|
text += d.type + ' ' + d.name
|
||||||
|
if d.params is not None:
|
||||||
|
params = ', '.join(
|
||||||
|
[f'{escape_html(p.type)} {p.name}' for p in d.params])
|
||||||
|
text += '(' + params + ')'
|
||||||
|
if d.trailing_return_type:
|
||||||
|
text += ' -> ' + escape_html(d.trailing_return_type)
|
||||||
|
text += ';'
|
||||||
|
text += '</code></pre>\n'
|
||||||
|
return text
|
||||||
|
|
||||||
class CxxHandler(BaseHandler):
|
class CxxHandler(BaseHandler):
|
||||||
def __init__(self, **kwargs: Any) -> None:
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
super().__init__(handler='cxx', **kwargs)
|
super().__init__(handler='cxx', **kwargs)
|
||||||
@ -145,6 +165,7 @@ class CxxHandler(BaseHandler):
|
|||||||
f"compounddef/sectiondef/memberdef/name[.='{name}']/..")
|
f"compounddef/sectiondef/memberdef/name[.='{name}']/..")
|
||||||
candidates = []
|
candidates = []
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
|
# Process a function.
|
||||||
params = [convert_param(p) for p in node.findall('param')]
|
params = [convert_param(p) for p in node.findall('param')]
|
||||||
node_param_str = ', '.join([p.type for p in params])
|
node_param_str = ', '.join([p.type for p in params])
|
||||||
if param_str and param_str != node_param_str:
|
if param_str and param_str != node_param_str:
|
||||||
@ -160,6 +181,8 @@ class CxxHandler(BaseHandler):
|
|||||||
node.find('argsstring').text.split(' -> ')[1])
|
node.find('argsstring').text.split(' -> ')[1])
|
||||||
d.desc = get_description(node)
|
d.desc = get_description(node)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
# Process a compound definition such as a struct.
|
||||||
cls = self._doxyxml.findall(f"compounddef/innerclass[.='fmt::{name}']")
|
cls = self._doxyxml.findall(f"compounddef/innerclass[.='fmt::{name}']")
|
||||||
if not cls:
|
if not cls:
|
||||||
raise Exception(f'Cannot find {identifier}. Candidates: {candidates}')
|
raise Exception(f'Cannot find {identifier}. Candidates: {candidates}')
|
||||||
@ -169,29 +192,27 @@ class CxxHandler(BaseHandler):
|
|||||||
d = Definition(name)
|
d = Definition(name)
|
||||||
d.type = node.get('kind')
|
d.type = node.get('kind')
|
||||||
d.template_params = get_template_params(node)
|
d.template_params = get_template_params(node)
|
||||||
d.params = None
|
|
||||||
d.desc = get_description(node)
|
d.desc = get_description(node)
|
||||||
|
d.members = []
|
||||||
|
for m in node.findall('sectiondef/memberdef'):
|
||||||
|
name = m.find('name').text
|
||||||
|
member = Definition(name if name else '')
|
||||||
|
type = m.find('type').text
|
||||||
|
member.type = type if type else ''
|
||||||
|
member.template_params = None
|
||||||
|
member.desc = get_description(m)
|
||||||
|
d.members.append(member)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def render(self, d: Definition, config: dict) -> str:
|
def render(self, d: Definition, config: dict) -> str:
|
||||||
text = '<div class="docblock">\n'
|
text = '<div class="docblock">\n'
|
||||||
text += '<pre><code class="language-cpp">'
|
text += render_decl(d)
|
||||||
if d.template_params is not None:
|
|
||||||
text += 'template <'
|
|
||||||
text += ', '.join(
|
|
||||||
[f'{p.type} {p.name}'.rstrip() for p in d.template_params])
|
|
||||||
text += '>\n'
|
|
||||||
text += d.type + ' ' + d.name
|
|
||||||
if d.params is not None:
|
|
||||||
params = ', '.join(
|
|
||||||
[f'{escape_html(p.type)} {p.name}' for p in d.params])
|
|
||||||
text += '(' + params + ')'
|
|
||||||
if d.trailing_return_type:
|
|
||||||
text += ' -> ' + escape_html(d.trailing_return_type)
|
|
||||||
text += ';'
|
|
||||||
text += '</code></pre>\n'
|
|
||||||
text += '<div class="docblock-desc">\n'
|
text += '<div class="docblock-desc">\n'
|
||||||
text += doxyxml2html(d.desc)
|
text += doxyxml2html(d.desc)
|
||||||
|
if d.params is None:
|
||||||
|
for m in d.members:
|
||||||
|
text += render_decl(m)
|
||||||
|
text += doxyxml2html(m.desc)
|
||||||
text += '</div>\n'
|
text += '</div>\n'
|
||||||
text += '</div>\n'
|
text += '</div>\n'
|
||||||
return text
|
return text
|
||||||
|
Reference in New Issue
Block a user