Explorar el Código

#439 integrate table reference

Falko Schindler hace 2 años
padre
commit
65c08f41ad
Se han modificado 3 ficheros con 18 adiciones y 13 borrados
  1. 7 10
      website/more_reference/table_reference.py
  2. 2 3
      website/reference.py
  3. 9 0
      website/reference_tools.py

+ 7 - 10
website/more_reference/table_reference.py

@@ -1,12 +1,10 @@
-from typing import Optional
-
 from nicegui import ui
 
-from ..example import example
+from ..reference_tools import element_example, text_example
 
 
-def intro(menu: Optional[ui.element] = None) -> None:
-    @example(ui.table, menu)
+def intro() -> None:
+    @element_example(ui.table)
     def table_example():
         columns = [
             {'name': 'name', 'label': 'Name', 'field': 'name', 'required': True, 'align': 'left'},
@@ -21,11 +19,10 @@ def intro(menu: Optional[ui.element] = None) -> None:
 
 
 def more() -> None:
-    @example('''#### Table with expandable rows
-
-Scoped slots can be used to insert buttons that toggle the expand state of a table row.
-See the [Quasar documentation](https://quasar.dev/vue-components/table#expanding-rows) for more information.
-''', None)
+    @text_example('Table with expandable rows', '''
+        Scoped slots can be used to insert buttons that toggle the expand state of a table row.
+        See the [Quasar documentation](https://quasar.dev/vue-components/table#expanding-rows) for more information.
+    ''')
     def table_with_expandable_rows():
         columns = [
             {'name': 'name', 'label': 'Name', 'field': 'name'},

+ 2 - 3
website/reference.py

@@ -3,9 +3,8 @@ from typing import Dict
 
 from nicegui import app, ui
 
-from . import more_reference
 from .example import bash_window, python_window
-from .reference_tools import element_example, heading, intro_example, markdown, subheading, text_example
+from .reference_tools import element_example, heading, intro_example, load_example, markdown, subheading, text_example
 
 CONSTANT_UUID = str(uuid.uuid4())
 
@@ -276,7 +275,7 @@ def create_full(menu: ui.element) -> None:
         ui.button('Update', on_click=update)
         ui.button('Select all', on_click=lambda: grid.call_api_method('selectAll'))
 
-    more_reference.table_reference.intro(menu)
+    load_example(ui.table)
 
     @element_example(ui.chart)
     def chart_example():

+ 9 - 0
website/reference_tools.py

@@ -1,3 +1,4 @@
+import importlib
 import re
 from typing import Callable, Optional, Union
 
@@ -90,3 +91,11 @@ class element_example:
             subheading(title)
             ui.html(html).classes('documentation bold-links arrow-links')
             return example(None, None, browser_title=self.browser_title)(f)
+
+
+def load_example(element_class: type) -> None:
+    def pascal_to_snake(name: str) -> str:
+        return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
+    name = pascal_to_snake(element_class.__name__)
+    module = importlib.import_module(f'website.more_reference.{name}_reference')
+    getattr(module, 'intro')()