Skip to content

Commit cec94ac

Browse files
committed
Add inline_methods config for method page splitting
Control whether class methods get their own pages or stay inline on the class page via the inline_methods setting in great-docs.yml: inline_methods: true # always inline (never split) inline_methods: false # always split to separate pages inline_methods: 10 # inline up to 10, split above (default: 5) Replaces three hardcoded threshold = 5 checks with a single config-driven method on GreatDocsConfig.
1 parent 5e9c97b commit cec94ac

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

great_docs/config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
# API Reference configuration (explicit section ordering)
9595
# If not provided, auto-generates sections from discovered exports
9696
"reference": [],
97+
# Control whether class methods get their own pages or stay inline.
98+
# true: always inline methods on the class page (never split)
99+
# false: always give methods their own pages (always split)
100+
# int: inline up to N methods, split above N (default: 5)
101+
"inline_methods": 5,
97102
# Logo configuration
98103
# str: path to a single logo file (used for all contexts)
99104
# dict: {"light": "...", "dark": "...", "alt": "...", "height": "...", "href": "...", "show_title": False}
@@ -789,6 +794,28 @@ def reference_desc(self) -> str | None:
789794
return val.get("desc")
790795
return None
791796

797+
def should_split_methods(self, method_count: int) -> bool:
798+
"""Whether a class with this many methods should split them to separate pages.
799+
800+
Controlled by `inline_methods` in great-docs.yml:
801+
- true: never split (always inline)
802+
- false: always split
803+
- int N: split when method_count > N (default: 5)
804+
805+
Items with no methods are never split regardless of the setting.
806+
"""
807+
if method_count == 0:
808+
return False
809+
val = self.get("inline_methods", 5)
810+
if val is True:
811+
return False
812+
if val is False:
813+
return True
814+
try:
815+
return method_count > int(val)
816+
except (TypeError, ValueError):
817+
return method_count > 5
818+
792819
@property
793820
def authors(self) -> list[dict[str, Any]]:
794821
"""Get the rich author metadata."""

great_docs/core.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6925,9 +6925,6 @@ def _create_api_sections(self, package_name: str) -> list | None:
69256925
def _t(key: str, fallback: str) -> str:
69266926
return get_translation(key, lang) if lang != "en" else fallback
69276927

6928-
# Use static threshold of 5 methods for large class separation
6929-
method_threshold = 5
6930-
69316928
# ── Helper: build a class section with big-class splitting ────────
69326929
def _make_class_section(title: str, desc: str, class_names: list) -> list[dict]:
69336930
"""Return section dicts (possibly with a Methods companion section)."""
@@ -6939,7 +6936,7 @@ def _make_class_section(title: str, desc: str, class_names: list) -> list[dict]:
69396936

69406937
for class_name in class_names:
69416938
method_count = categories["class_methods"].get(class_name, 0)
6942-
if method_count > method_threshold:
6939+
if self._config.should_split_methods(method_count):
69436940
class_contents.append({"name": class_name, "members": []})
69446941
separate_methods.append(class_name)
69456942
else:
@@ -7306,9 +7303,6 @@ def _create_api_sections_from_config(self, package_name: str) -> list | None:
73067303
mod_prefix = qualified.split(".")[0]
73077304
module_members.setdefault(mod_prefix, []).append(qualified)
73087305

7309-
# Use the same big-class threshold as auto-discovery
7310-
method_threshold = 5
7311-
73127306
sections = []
73137307

73147308
for section_config in reference_config:
@@ -7331,7 +7325,7 @@ def _create_api_sections_from_config(self, package_name: str) -> list | None:
73317325
# This is a module name — expand into its individual members
73327326
for member in module_members[item]:
73337327
method_count = categories["class_methods"].get(member, 0)
7334-
if method_count > method_threshold:
7328+
if self._config.should_split_methods(method_count):
73357329
section_contents.append(
73367330
{"name": member, "members": []}
73377331
) # pragma: no cover
@@ -7341,7 +7335,7 @@ def _create_api_sections_from_config(self, package_name: str) -> list | None:
73417335
else:
73427336
# Regular item (class, function, etc.) — use as-is
73437337
method_count = categories["class_methods"].get(item, 0)
7344-
if method_count > method_threshold:
7338+
if self._config.should_split_methods(method_count):
73457339
section_contents.append({"name": item, "members": []})
73467340
large_classes_in_section.append(item)
73477341
else:
@@ -8044,9 +8038,6 @@ def _generate_config_with_reference(
80448038
class_methods = categories.get("class_methods", {})
80458039
class_method_names = categories.get("class_method_names", {})
80468040

8047-
# Use static threshold of 5 methods for large class separation
8048-
threshold = 5
8049-
80508041
# Track large classes that need separate method sections
80518042
large_classes: list[str] = []
80528043

@@ -8072,7 +8063,7 @@ def _generate_config_with_reference(
80728063
lines.append(" contents:")
80738064
for class_name in sorted(items):
80748065
method_count = class_methods.get(class_name, 0)
8075-
if method_count > threshold:
8066+
if self._config.should_split_methods(method_count):
80768067
lines.append(f" - name: {class_name}")
80778068
lines.append(f" members: false # {method_count} methods listed below")
80788069
large_classes.append(class_name)

0 commit comments

Comments
 (0)