Przeglądaj źródła

#411 fix link back to main documentation page

Falko Schindler 2 lat temu
rodzic
commit
5927a4987c
2 zmienionych plików z 12 dodań i 10 usunięć
  1. 11 9
      main.py
  2. 1 1
      nicegui/elements/query.py

+ 11 - 9
main.py

@@ -314,27 +314,29 @@ def documentation_page():
 
 
 @ui.page('/documentation/{name}')
 @ui.page('/documentation/{name}')
 def documentation_page_more(name: str):
 def documentation_page_more(name: str):
+    if not hasattr(ui, name):
+        name = name.replace('_', '')  # NOTE: "AG Grid" leads to anchor name "ag_grid", but class is `ui.aggrid`
+    module = importlib.import_module(f'website.more_documentation.{name}_documentation')
+    api = getattr(ui, name)
+    more = getattr(module, 'more', None)
+    back_link_target = str(api.__doc__ or api.__init__.__doc__).splitlines()[0].strip()
+
     add_head_html()
     add_head_html()
     add_header()
     add_header()
     with side_menu() as menu:
     with side_menu() as menu:
-        ui.markdown(f'[← back](/documentation#{create_anchor_name(name)})').classes('bold-links')
+        ui.markdown(f'[← back](/documentation#{create_anchor_name(back_link_target)})').classes('bold-links')
     with ui.column().classes('w-full p-8 lg:p-16 max-w-[1250px] mx-auto'):
     with ui.column().classes('w-full p-8 lg:p-16 max-w-[1250px] mx-auto'):
-        if not hasattr(ui, name):
-            name = name.replace('_', '')  # NOTE: "AG Grid" leads to anchor name "ag_grid", but class is `ui.aggrid`
         section_heading('Documentation', f'ui.*{name}*')
         section_heading('Documentation', f'ui.*{name}*')
-        module = importlib.import_module(f'website.more_documentation.{name}_documentation')
-        element_class = getattr(ui, name)
-        more = getattr(module, 'more', None)
         with menu:
         with menu:
             ui.markdown('**Demos**' if more else '**Demo**').classes('mt-4')
             ui.markdown('**Demos**' if more else '**Demo**').classes('mt-4')
-        element_demo(element_class)(getattr(module, 'main_demo'))
+        element_demo(api)(getattr(module, 'main_demo'))
         if more:
         if more:
             more()
             more()
-        if inspect.isclass(element_class):
+        if inspect.isclass(api):
             with menu:
             with menu:
                 ui.markdown('**Reference**').classes('mt-4')
                 ui.markdown('**Reference**').classes('mt-4')
             ui.markdown('## Reference').classes('mt-16')
             ui.markdown('## Reference').classes('mt-16')
-            generate_class_doc(element_class)
+            generate_class_doc(api)
 
 
 
 
 ui.run(uvicorn_reload_includes='*.py, *.css, *.html')
 ui.run(uvicorn_reload_includes='*.py, *.css, *.html')

+ 1 - 1
nicegui/elements/query.py

@@ -61,7 +61,7 @@ def query(selector: str) -> Query:
 
 
     To manipulate elements like the document body, you can use the `ui.query` function.
     To manipulate elements like the document body, you can use the `ui.query` function.
     With the query result you can add classes, styles, and attributes like with every other UI element.
     With the query result you can add classes, styles, and attributes like with every other UI element.
-    This can be useful for example to change the background color of the page (eg. `ui.query('body').classes('bg-green')`).
+    This can be useful for example to change the background color of the page (e.g. `ui.query('body').classes('bg-green')`).
     """
     """
     for element in get_client().elements.values():
     for element in get_client().elements.values():
         if isinstance(element, Query) and element._props['selector'] == selector:
         if isinstance(element, Query) and element._props['selector'] == selector: