Kaynağa Gözat

rename header and footer into before_content and after_content to avoid conflicts with new layout elements

Falko Schindler 2 yıl önce
ebeveyn
işleme
30b7565691
3 değiştirilmiş dosya ile 17 ekleme ve 17 silme
  1. 6 6
      examples/customization/custom.py
  2. 4 4
      nicegui/page.py
  3. 7 7
      tests/test_pages.py

+ 6 - 6
examples/customization/custom.py

@@ -10,15 +10,15 @@ class page(ui.page):
         super().__init__(route, classes='fit column items-start', title='Modularization Demo')
         self.kwargs = kwargs
 
-    async def header(self) -> None:
-        await super().header()
+    async def before_content(self) -> None:
+        await super().before_content()
         navbar(**self.kwargs)
-        # start using a ui row to let all content between header and footer be centered
+        # enter a ui.row to center all content
         self.content = ui.row().classes('justify-center fit mt-10').__enter__()
 
-    async def footer(self) -> None:
-        await super().footer()
-        # closing the row which was opened in header
+    async def after_content(self) -> None:
+        await super().after_content()
+        # close the row which was opened in before_content()
         self.content.__exit__(None, None, None)
 
 

+ 4 - 4
nicegui/page.py

@@ -208,7 +208,7 @@ class page:
                         if self.shared:
                             raise RuntimeError('Cannot use `request` argument in shared page')
                     await self.connected(request)
-                    await self.header()
+                    await self.before_content()
                     args = {**kwargs, **convert_arguments(request, self.converters, func)}
                     result = await func(**args) if is_coroutine(func) else func(**args)
                     if isinstance(result, types.GeneratorType):
@@ -220,7 +220,7 @@ class page:
                             raise RuntimeError('Yielding for page_ready is not supported on shared pages')
                         await result.__anext__()
                     self.page.page_ready_generator = result
-                    await self.footer()
+                    await self.after_content()
                 return self.page
             except Exception as e:
                 globals.log.exception(e)
@@ -234,10 +234,10 @@ class page:
     async def connected(self, request: Optional[Request]) -> None:
         pass
 
-    async def header(self) -> None:
+    async def before_content(self) -> None:
         pass
 
-    async def footer(self) -> None:
+    async def after_content(self) -> None:
         pass
 
 

+ 7 - 7
tests/test_pages.py

@@ -148,15 +148,15 @@ def test_customized_page(screen: Screen):
             assert isinstance(request, Request)
             trace.append('connected')
 
-        async def header(self) -> None:
+        async def before_content(self) -> None:
             assert isinstance(self.page.view, justpy.htmlcomponents.Div), \
                 'we should be able to access the underlying JustPy view'
-            await super().header()
-            trace.append('header')
+            await super().before_content()
+            trace.append('before_content')
 
-        async def footer(self) -> None:
-            await super().footer()
-            trace.append('footer')
+        async def after_content(self) -> None:
+            await super().after_content()
+            trace.append('after_content')
 
     @custom_page('/', dark=True)
     def mainpage():
@@ -167,7 +167,7 @@ def test_customized_page(screen: Screen):
     screen.should_contain('Hello, world!')
     screen.should_contain('My Customized Page')
     assert 'body--dark' in screen.get_tags('body')[0].get_attribute('class')
-    assert trace == ['init', 'connected', 'header', 'content', 'footer']
+    assert trace == ['init', 'connected', 'before_content', 'content', 'after_content']
 
 
 def test_shared_page_with_request_parameter_raises_exception(screen: Screen):