Skip to content

Commit

Permalink
simplify doc.part
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 2, 2024
1 parent 390f106 commit 6c140b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
13 changes: 6 additions & 7 deletions website/documentation/content/doc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,18 @@ def decorator(function: Callable) -> Callable:


def part(title_: str) -> Callable:
"""Add a custom part to the current documentation page."""
"""Add a custom part with arbitrary UI and descriptive markdown elements to the current documentation page.
The content of any contained markdown elements will be used for search indexing.
"""
page = _get_current_page()

def decorator(function: Callable) -> Callable:
task_id = nicegui.slot.get_task_id()
orig = nicegui.slot.Slot.stacks[task_id]
# NOTE we create an empty context so the function is not rendered as elements but available to ElementFilter
del nicegui.slot.Slot.stacks[task_id]
with nicegui.ui.element(_client=nicegui.Client(nicegui.page.page(''), request=None)):
with nicegui_ui.element() as container:
function()
elements = nicegui.ElementFilter(kind=nicegui.ui.markdown, local_scope=True)
description = ''.join(e.content for e in elements if '```' not in e.content)
nicegui.slot.Slot.stacks[task_id] = orig
container.delete()
page.parts.append(DocumentationPart(title=title_, search_text=description, ui=function))
return function
return decorator
Expand Down
30 changes: 13 additions & 17 deletions website/documentation/content/project_structure_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
from ..windows import bash_window, python_window
from . import doc


@doc.part('Project Structure')
def setup():
ui.markdown('''
The NiceGUI package provides a [pytest plugin](https://docs.pytest.org/en/stable/how-to/writing_plugins.html)
which can be activated via `pytest_plugins = ['nicegui.testing.plugin']`.
This makes specialized [fixtures](https://docs.pytest.org/en/stable/explanation/fixtures.html) available for testing your NiceGUI user interface.
With the [`screen` fixture](/documentation/screen) you can run the tests through a headless browser (slow)
and with the [`user` fixture](/documentation/user) fully simulated in Python (fast).
There are a multitude of ways to structure your project and tests.
Here we only present two approaches which we found useful,
one for [small apps and experiments](/documentation/project_structure#simple)
and a [modular one for larger projects](/documentation/project_structure#modular).
You can find more information in the [pytest documentation](https://docs.pytest.org/en/stable/contents.html).
''').classes('bold-links arrow-links')

doc.text('Project Structure', '''
The NiceGUI package provides a [pytest plugin](https://docs.pytest.org/en/stable/how-to/writing_plugins.html)
which can be activated via `pytest_plugins = ['nicegui.testing.plugin']`.
This makes specialized [fixtures](https://docs.pytest.org/en/stable/explanation/fixtures.html) available for testing your NiceGUI user interface.
With the [`screen` fixture](/documentation/screen) you can run the tests through a headless browser (slow)
and with the [`user` fixture](/documentation/user) fully simulated in Python (fast).
There are a multitude of ways to structure your project and tests.
Here we only present two approaches which we found useful,
one for [small apps and experiments](/documentation/project_structure#simple)
and a [modular one for larger projects](/documentation/project_structure#modular).
You can find more information in the [pytest documentation](https://docs.pytest.org/en/stable/contents.html).
''')

doc.text('Simple', '''
For small apps and experiments you can put the tests in a separate file,
Expand Down

0 comments on commit 6c140b5

Please sign in to comment.