Using decorators¶
Code for this section¶
routing.py¶
1"""MkNodes routing example.
2
3MkNodes also supports setting up Navs via decorators.
4"""
5
6import mknodes as mk
7
8
9NAV_TEXT = """You can also use decorators to attach MkNavs. These navs then can continue
10to build the tree without using decorators (by adding sub-navs).
11"""
12
13nav = mk.MkNav("Using decorators")
14
15
16@nav.route.page("Routed page")
17def routed_page(page: mk.MkPage) -> None:
18 """Builds a MkPage and attaches it to the router MkNav."""
19 page += mk.MkAdmonition("I'm a page added via decorators!")
20
21
22@nav.route.page("Routed", "Deeply", "Nested", "Nested page")
23def routed_nested_page(page: mk.MkPage) -> None:
24 """Builds a nested MkPage and attaches it to the router MkNav."""
25 page += mk.MkAdmonition("I'm a nested page added via decorators!")
26
27
28@nav.route.nav("Routed", "Deeply", "Nested", "Nav")
29def routed_nav(nav: mk.MkNav) -> None:
30 """Builds a nested MkNav and attaches it to the router MkNav."""
31 index_page = nav.add_page(is_index=True)
32 index_page += mk.MkAdmonition(NAV_TEXT)
33 page = nav.add_page("Routed section page")
34 page += mk.MkAdmonition("Routed section page content")