Skip to content

Commit 006aa63

Browse files
committed
display function signature on function pages
fixes #3
1 parent 2323d45 commit 006aa63

File tree

4 files changed

+73
-55
lines changed

4 files changed

+73
-55
lines changed

src/builder/files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use super::{
33
builder::Builder,
44
traits::{BuildResult, Entry, NavItem, OutputEntry, ASTEntry},
5-
shared::{fmt_fun_decl, fmt_section, fmt_classlike_decl},
5+
shared::{fmt_class_method, fmt_section, fmt_classlike_decl},
66
namespace::CppItemKind
77
};
88
use crate::{
@@ -89,7 +89,7 @@ impl<'e> OutputEntry<'e> for File {
8989
) && matcher(entry)
9090
)
9191
.into_iter()
92-
.map(|fun| fmt_fun_decl(fun.entity(), builder))
92+
.map(|fun| fmt_class_method(fun.entity(), builder))
9393
.collect()
9494
),
9595
),

src/builder/function.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::{html::Html, url::UrlPath};
44
use clang::Entity;
55

66
use super::{
7-
traits::{ASTEntry, BuildResult, EntityMethods, Entry, NavItem, OutputEntry},
8-
builder::Builder,
9-
shared::output_entity,
7+
builder::Builder, shared::{output_entity, output_function}, traits::{ASTEntry, BuildResult, EntityMethods, Entry, NavItem, OutputEntry}
108
};
119

1210
pub struct Function<'e> {
@@ -53,7 +51,7 @@ impl<'e> OutputEntry<'e> for Function<'e> {
5351
fn output(&self, builder: &Builder<'e>) -> (Arc<String>, Vec<(&'static str, Html)>) {
5452
(
5553
builder.config.templates.function.clone(),
56-
output_entity(self, builder),
54+
output_function(self, builder),
5755
)
5856
}
5957

src/builder/shared.rs

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -214,56 +214,61 @@ pub fn fmt_field(field: &Entity, builder: &Builder) -> Html {
214214
.into()
215215
}
216216

217-
pub fn fmt_fun_decl(fun: &Entity, builder: &Builder) -> Html {
217+
fn fmt_fun_signature(fun: &Entity, builder: &Builder) -> Html {
218+
HtmlElement::new("summary")
219+
.with_classes(&["entity", "fun"])
220+
.with_child_opt(fmt_template_args(fun, builder))
221+
.with_child(HtmlElement::new("span")
222+
.with_class("function-signature")
223+
.with_child_opt(
224+
fun.is_static_method()
225+
.then_some(Html::span(&["keyword", "space-after"], "static")),
226+
)
227+
.with_child_opt(
228+
fun.is_virtual_method()
229+
.then_some(Html::span(&["keyword", "space-after"], "virtual")),
230+
)
231+
.with_child_opt(fun.get_result_type().map(|t| fmt_type(&t, builder)))
232+
.with_child(Html::span(
233+
&["name", "space-before"],
234+
&fun.get_name().unwrap_or("_anon".into()),
235+
))
236+
.with_child(
237+
HtmlElement::new("span").with_class("params").with_children(
238+
fun.get_function_arguments()
239+
.map(|args| {
240+
args.iter()
241+
.map(|arg| fmt_param(arg, builder))
242+
.collect::<Vec<_>>()
243+
})
244+
.unwrap_or(Vec::new())
245+
.insert_between(|| Html::span(&["comma", "space-after"], ","))
246+
.surround(HtmlText::new("(").into(), HtmlText::new(")").into()),
247+
),
248+
)
249+
.with_child_opt(
250+
fun.is_const_method()
251+
.then_some(Html::span(&["keyword", "space-before"], "const")),
252+
)
253+
.with_child_opt(
254+
fun.is_pure_virtual_method().then_some::<Html>(
255+
HtmlList::new(vec![
256+
Html::span(&["space-before"], "="),
257+
Html::span(&["space-before", "literal"], "0"),
258+
])
259+
.into(),
260+
)
261+
)
262+
)
263+
.into()
264+
}
265+
266+
pub fn fmt_class_method(fun: &Entity, builder: &Builder) -> Html {
218267
HtmlElement::new("details")
219268
.with_class("entity-desc")
220269
.with_attr_opt("id", member_fun_link(fun))
221270
.with_child(
222-
HtmlElement::new("summary")
223-
.with_classes(&["entity", "fun"])
224-
.with_child_opt(fmt_template_args(fun, builder))
225-
.with_child(HtmlElement::new("span")
226-
.with_class("function-signature")
227-
.with_child_opt(
228-
fun.is_static_method()
229-
.then_some(Html::span(&["keyword", "space-after"], "static")),
230-
)
231-
.with_child_opt(
232-
fun.is_virtual_method()
233-
.then_some(Html::span(&["keyword", "space-after"], "virtual")),
234-
)
235-
.with_child_opt(fun.get_result_type().map(|t| fmt_type(&t, builder)))
236-
.with_child(Html::span(
237-
&["name", "space-before"],
238-
&fun.get_name().unwrap_or("_anon".into()),
239-
))
240-
.with_child(
241-
HtmlElement::new("span").with_class("params").with_children(
242-
fun.get_function_arguments()
243-
.map(|args| {
244-
args.iter()
245-
.map(|arg| fmt_param(arg, builder))
246-
.collect::<Vec<_>>()
247-
})
248-
.unwrap_or(Vec::new())
249-
.insert_between(|| Html::span(&["comma", "space-after"], ","))
250-
.surround(HtmlText::new("(").into(), HtmlText::new(")").into()),
251-
),
252-
)
253-
.with_child_opt(
254-
fun.is_const_method()
255-
.then_some(Html::span(&["keyword", "space-before"], "const")),
256-
)
257-
.with_child_opt(
258-
fun.is_pure_virtual_method().then_some::<Html>(
259-
HtmlList::new(vec![
260-
Html::span(&["space-before"], "="),
261-
Html::span(&["space-before", "literal"], "0"),
262-
])
263-
.into(),
264-
)
265-
)
266-
)
271+
fmt_fun_signature(fun, builder)
267272
)
268273
.with_child(
269274
HtmlElement::new("div").with_child(
@@ -430,7 +435,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
430435
"Public static methods",
431436
entry.entity().get_member_functions(Access::Public, Include::Statics)
432437
.into_iter()
433-
.map(|e| fmt_fun_decl(&e, builder))
438+
.map(|e| fmt_class_method(&e, builder))
434439
.collect::<Vec<_>>(),
435440
),
436441
),
@@ -440,7 +445,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
440445
"Public member functions",
441446
entry.entity().get_member_functions(Access::Public, Include::Members)
442447
.into_iter()
443-
.map(|e| fmt_fun_decl(&e, builder))
448+
.map(|e| fmt_class_method(&e, builder))
444449
.collect::<Vec<_>>(),
445450
),
446451
),
@@ -451,7 +456,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
451456
"Protected member functions",
452457
entry.entity().get_member_functions(Access::Protected, Include::Members)
453458
.into_iter()
454-
.map(|e| fmt_fun_decl(&e, builder))
459+
.map(|e| fmt_class_method(&e, builder))
455460
.collect::<Vec<_>>(),
456461
),
457462
),
@@ -491,6 +496,20 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
491496
ent
492497
}
493498

499+
pub fn output_function<'e, T: ASTEntry<'e>>(
500+
entry: &T,
501+
builder: &Builder,
502+
) -> Vec<(&'static str, Html)> {
503+
let mut ent = output_entity(entry, builder);
504+
ent.extend(vec![
505+
(
506+
"function_signature",
507+
fmt_fun_signature(entry.entity(), builder)
508+
)
509+
]);
510+
ent
511+
}
512+
494513
fn fmt_autolinks_recursive<'a>(
495514
entity: &CppItem,
496515
config: Arc<Config>,

templates/function.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<h1 class="entity-title">Function <i data-feather="code" class="icon"></i><a href="{page_url}">{name}</a></h1>
33
<div>
44
{header_link}
5+
{function_signature}
56
</div>
67
<div>
78
{description}

0 commit comments

Comments
 (0)