Skip to content

Commit d1cb526

Browse files
committed
[[NODE]] migration: simplify has_any_toc_nodes()
1 parent 520e64d commit d1cb526

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

strictdoc/backend/sdoc/models/document.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,6 @@ def assign_meta(self, meta: DocumentMeta) -> None:
194194
def has_any_nodes(self) -> bool:
195195
return len(self.section_contents) > 0
196196

197-
def has_any_toc_nodes(self) -> bool:
198-
for node_ in self.section_contents:
199-
# Skip nodes without a TOC level.
200-
if (
201-
isinstance(node_, SDocSectionIF)
202-
and node_.ng_resolved_custom_level == "None"
203-
):
204-
continue
205-
return True
206-
return False
207-
208197
def get_display_title(
209198
self,
210199
include_toc_number: bool = True, # noqa: ARG002

strictdoc/export/html/generators/view_objects/document_screen_view_object.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mypy: disable-error-code="no-untyped-call,no-untyped-def,union-attr"
22
from dataclasses import dataclass
33
from datetime import datetime
4-
from typing import List, Optional, Union
4+
from typing import List, Optional, Union, Iterator
55

66
from jinja2 import Template
77
from markupsafe import Markup
@@ -10,6 +10,7 @@
1010
from strictdoc.backend.sdoc.models.document import SDocDocument
1111
from strictdoc.backend.sdoc.models.document_grammar import GrammarElement
1212
from strictdoc.backend.sdoc.models.document_view import ViewElement
13+
from strictdoc.backend.sdoc.models.model import SDocElementIF
1314
from strictdoc.backend.sdoc.models.node import SDocNode, SDocNodeField
1415
from strictdoc.backend.sdoc.models.section import SDocSection
1516
from strictdoc.core.document_tree import DocumentTree
@@ -302,9 +303,12 @@ def get_document_by_path(self, full_path: str) -> SDocDocument:
302303
def get_grammar_elements(self) -> List[GrammarElement]:
303304
return self.document.grammar.elements
304305

305-
def table_of_contents(self):
306+
def table_of_contents(self) -> Iterator[SDocElementIF]:
306307
yield from self.document_iterator.table_of_contents()
307308

309+
def document_has_any_toc_nodes(self) -> bool:
310+
return any(self.table_of_contents())
311+
308312
def document_content_iterator(self):
309313
yield from self.document_iterator.all_content(
310314
print_fragments=True,

strictdoc/export/html/templates/screens/document/pdf/toc.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- if view_object.document.has_any_toc_nodes() -%}
1+
{%- if view_object.document_has_any_toc_nodes() -%}
22
<div class="pdf-toc" data-testid="pdf-toc-list">
33
<div class="pdf-toc-row">
44
<span class="pdf-toc-cell"></span>

0 commit comments

Comments
 (0)