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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give interfaces their own autosummary and automodule sections #136

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion sphinx_js/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Module:
attributes: list["TopLevel"] = Factory(list)
functions: list["Function"] = Factory(list)
classes: list["Class"] = Factory(list)
interfaces: list["Interface"] = Factory(list)


@define(slots=False)
Expand Down Expand Up @@ -306,7 +307,7 @@ class Interface(TopLevel, _MembersAndSupers):
"""An interface, a la TypeScript"""

type_params: list[TypeParam] = Factory(list)
kind: str = "classes"
kind: str = "interfaces"


@define
Expand Down
2 changes: 1 addition & 1 deletion sphinx_js/js/convertTopLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class Converter {
supers: this.relatedTypes(cls, "extendedTypes"),
type_params: this.typeParamsToIR(cls.typeParameters),
...this.topLevelProperties(cls),
kind: "classes",
kind: "interfaces",
};
return [result, cls.children];
}
Expand Down
2 changes: 1 addition & 1 deletion sphinx_js/js/ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type _MembersAndSupers = {
export type Interface = TopLevel &
_MembersAndSupers & {
type_params: TypeParam[];
kind: "classes";
kind: "interfaces";
};

export type Class = TopLevel &
Expand Down
4 changes: 3 additions & 1 deletion sphinx_js/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def rst_for(self, obj: TopLevel) -> str:
renderer_class = AutoAttributeRenderer
case Function(_):
renderer_class = AutoFunctionRenderer
case Class(_):
case Class(_) | Interface(_):
renderer_class = AutoClassRenderer
case _:
raise RuntimeError("This shouldn't happen...")
Expand Down Expand Up @@ -676,6 +676,7 @@ def rst( # type:ignore[override]
rst.append(self.rst_for_group(obj.attributes))
rst.append(self.rst_for_group(obj.functions))
rst.append(self.rst_for_group(obj.classes))
rst.append(self.rst_for_group(obj.interfaces))
return "\n\n".join(["\n\n".join(r) for r in rst])


Expand All @@ -699,6 +700,7 @@ def rst_nodes(self) -> list[Node]:
("attributes", module.attributes),
("functions", module.functions),
("classes", module.classes),
("interfaces", module.interfaces),
]
pkgname = "".join(self._partial_path)

Expand Down
1 change: 1 addition & 0 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@ def _create_modules(self, ir_objects: Sequence[ir.TopLevel]) -> Iterable[ir.Modu
mod.attributes = sorted(mod.attributes, key=attrgetter("name"))
mod.functions = sorted(mod.functions, key=attrgetter("name"))
mod.classes = sorted(mod.classes, key=attrgetter("name"))
mod.interfaces = sorted(mod.interfaces, key=attrgetter("name"))
return modules.values()
5 changes: 5 additions & 0 deletions tests/test_build_ts/source/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ export class Z {
* Another thing.
*/
export const q = { a: "z29", b: 76 };

/**
* Interface documentation
*/
export interface I {}
11 changes: 11 additions & 0 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ class module.Z(a, b)
type: number

Z.z()

class module.I()

Interface documentation

*interface*

*exported from* "module"
"""
),
)
Expand Down Expand Up @@ -412,3 +420,6 @@ def test_autosummary(self):

classes = soup.find(class_="classes")
assert classes.find(class_="summary").get_text() == "This is a summary."

classes = soup.find(class_="interfaces")
assert classes.find(class_="summary").get_text() == "Interface documentation"
Loading