| Name | ofjustpy JSON |
| Version |
1.1.2
JSON |
| download |
| home_page | None |
| Summary | A webdev framework that enables development of full-stack webpages and app purely in Python |
| upload_time | 2023-12-05 14:18:28 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.11 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# [Ofjustpy](https://github.com/ofjustpy/ofjustpy)
[](https://pypi.python.org/pypi/ofjustpy)
[](https://github.com/ofjustpy/ofjustpy/actions)
[](https://github.com/ofjustpy/ofjustpy/actions)
[](https://github.com/ofjustpy/ofjustpy/actions)
[](https://ofjustpy.github.io/ofjustpy/)
[](https://pypi.python.org/pypi/ofjustpy)
[](https://pepy.tech/project/)
[](https://pepy.tech/project/ofjustpy)
[](https://github.com/ofjustpy/ofjustpy/stargazers)
# Ofjustpy: A Full-Stack Web Development Framework in Python
**Features:**
* **Single language**: Ofjustpy allows you to build full-featured web pages using only the Python programming language. You don't need to learn and manage multiple languages like Jinja2 templating, JavaScript, HTML, and CSS. The entire functionality of a webpage can be expressed using pure Python.
2. **Emphasis on API Design**: Much emphasis has been put on API design and programmatic constructs in order
to be able to build complex responsive webpages and websites with codebase that easy to read and maintain.
3. **Scalable and efficient**: Ofjustpy enables programmers to write scalable and efficient webpage code. It maintains only a single copy of static components, regardless of the number of connections opened. Data copying per connection and per event is minized. Even for mutable components, only a single copy of the component's static portion is maintained. Additionally, communication is efficient as it transmits only the changes (diff) to the UI to the frontend.
4. **Composibility**: Ofjustpy allows users to easily build reusable components and incorporate them into their codebase. See [htmlcomponents.py](src/ofjustpy/htmlcomponents.py) and [ofjustpy-components](https://github.com/ofjustpy/ofjustpy-components) for simple to complex components build using Ofjustpy framework.
5. **Tailwind CSS Support**: Ofjustpy provides first-class and native support for Tailwind CSS constructs, enabling complex manipulation (add, remove, update classes) of the frontend UI through pure Python expressions.
6. **Async Processing**: Like its predecessor Justpy, Ofjustpy utilizes an asynchronous webserver stack that includes Starlette, ASGI, asyncio, and async/await. This architecture enables Ofjustpy to efficiently handle concurrent connections, even on single-core hardware or virtual environments, without the need for OS-level multi-threading.
7. **Technology Stack**:
The tech stack of ofjustpy consists of Svelte (as the frontend UI engine),
websockets (for communication between browser and server), Starlette (the async webserver),
amd Tailwind (for layout and design).
## Gallery
- See [examples](https://webworks.monallabs.in/examples/index) for a collection of
basic tutorial examples of webpages build using ofjustpy.
- See [Basic capabilities demo](https://webworks.monallabs.in/demo_basic_capabilities) for
webpage showing basic html components
- See [Advanced capabilities demo](https://webworks.monallabs.in/demo_advanced_capabilities)
for webpage illustrating advanced components (hierarchy navigator, pagination) in action.
## Webpage programming using Ofjustpy
The basic paradigm for building out webpages in Ofjustpy is straighforward:
1. Create components and containers
2. Describe their layout and appearance using tailwind constructs
3. For components that will respond to events on UI, describe handlers (actions) for those
events
If you are new to web development, then it would be helpful to go through the [justpy docs](https://justpy.io/) and its [examples](https://github.com/justpy-org/justpy/tree/master/examples) on which Ofjustpy is based on.
Also, pay careful attention to known corner cases and suggested workarounds mentioned in [Gotchas](https://ofjustpy.github.io/ofjustpy/Gotchas.html) to keep Ofjutpy engine happy
The demo example illustrates the three paradigms for building out webpages:
```python
import ofjustpy as oj
from py_tailwind_utils import *
labels = [oj.Mutable.Label(text="mytext1", key="mylabel1"),
oj.Mutable.Label(text="mytext2", key="mylabel2"),
oj.Mutable.Label(text="mytext3", key="mylabel3"),
oj.Mutable.Label(text="mytext4", key="mylabel4"),
]
mydeck = oj.Mutable.StackD(key="mydeck",
childs=labels,
height_anchor_key="mylabel1",
twsty_tags=[W/"1/2"])
idx = 1
def on_btn_click(dbref, msg, target_of):
global idx
mydeck_shell = target_of(mydeck)
mydeck_shell.bring_to_front(labels[idx].id)
idx = (idx + 1)%4
pass
mybtn = oj.AC.Button(key="mybtn",
text="abtn",
pcp=[W/32, H/32, bg/rose/6],
on_click=on_btn_click
)
wp_endpoint = oj.create_endpoint(key="static-components",
childs = [mydeck,
mybtn
]
)
oj.add_jproute("/", wp_endpoint)
```
### Components and their types in Ofjustpy
Ofjustpy, boradly, defines 2 kinds of components: static vs mutable.
Static components are further classified into Passive and Active,
while mutable components come in three variety: HCCMutable, HCCStatic, Mutable.
#### Passive Components
As name suggests, these do not respond to UI events and also do not undergo
any changes. Ofjustpy maintains only a single copy of such components (see (see [examples/static_webpages](examples/static_webpages))
Examples of passive components:
1. oj.PC.Label
2. oj.PC.P
3. oj.PC.Img
etc. See [SHC_types.py](src/ofjustpy/SHC_types.py) for list of all passive components.
#### Active Components
Active components handle events but like passive do not mutate.
Active components require an additional key/id argument (see [examples/input_components](examples/input_components)).
Examples of active components:
1. oj.AC.Button
2. oj.AC.TextInput
3. oj.AC.CheckboxInput
4. oj.AC.Select
5. oj.AC.A
and so on. See [SHC_types.py](src/ofjustpy/SHC_types.py) for list of all active components
#### Mutable components
Mutable components can handle events and also mutate, i.e., change
appearances. See [examples/mutable_webpages](examples/mutable_webpages) for usage.
Examples of mutable components include:
1. oj.Mutable.Button
2. oj.Mutable.Label
3. oj.Mutable.Container
and so on. See [MHC_types.py](src/ofjustpy/MHC_types.py) for list of all mutable components.
#### HCCMutable Components
These are div components
that contain mutable childrens.
The div itself is not mutable (see [examples/mutable_webpages/example_004.py](examples/mutable_webpages/example_004.py)).
HCCMutable components offer minor space optimization
over Mutable divs.
Examples of HCCMutable components:
1. oj.HCCMutable.Div
2. oj.HCCMutable.StackV
3. oj.HCCMutable.StackW
4. oj.HCCMutable.Subsection
See [MHC_types.py](src/ofjustpy/MHC_types.py) for list of all HCCMutable components.
#### HCCStatic Components
These are div components
that itself are mutable but
they contain static (passive or active) components.
Examples of HCCStatic components:
1. oj.HCCStatic.Div
2. oj.HCCStatic.StackV
See [MHC_types.py](https://github.com/ofjustpy/ofjustpy/blob/09fe497badc74d306de3e1e019dcad251de08c11/src/ofjustpy/MHC_types.py#L168C12-L168C12) for list of all HCCStatic components.
jj
#### Tailwind-derived higher-order components
In addition to standard HTML components (like, Div, Span, Button, etc.),
Ofjustpy offers advanced components that offer complex functionality. These
are build using Tailwind CSS constructs, Svelte, and Python.
1. Containers to juxtapose child components
StackH, StackV, StackG, StackW : Stack components horizontally, vertically, grid, and wrap around. See examples [examples/static_webpages/example_001.py](examples/static_webpages/example_001.py),
[examples/static_webpages/example_002.py](examples/static_webpages/example_002.py) for StackV, [examples/static_webpages/example_004.py](examples/static_webpages/example_004.py) for StackG, [examples/static_webpages/example_002.py](examples/static_webpages/example_002.py) for StackW.
2. StackD:
Deck the items on top of each other. See examples [examples/mutable_webpages/example_005.py](examples/mutable-webpages/example_005.py), [examples/mutable_webpages/example_008.py](examples/mutable-webpages/example_008.py)
3. Slider
A component with discreet value buttons to select a value.
See examples [examples/mutable_webpages/example_002.py](examples/mutable_webpages/example_002.py), [examples/mutable_webpages/example_003.py](examples/mutable_webpages/example_003.py), [examples/mutable_webpages/example_006.py](examples/mutable_webpages/example_006.py).
4. ColorSelector
Component create select drop down option for all tailwind preset color values.
See example [examples/mutable_webpages/example_007.py](examples/mutable_webpages/example_007.py)
See ofjustpy-components github repo for collection of advanced components.
## The Ofjustpy paradigms: app module, TwStyCtx, MountCtx, PageBuilderCtx
### App module
Ofjustpy requires that starlette app be defined in its own file lets say
"theapp.py". Then set the `OJ_APP_MODULE` to set the location of the `theapp.py`
relative to directory from where the webserver is being launched.
```bash
export OJ_APP_MODULE="../the_app"
```
A sample example of `theapp.py` looks as follows:
```python
from asgi_signing_middleware import SerializedSignedCookieMiddleware
import ofjustpy as oj
csrf_middleware = Middleware(CSRFMiddleware,
secret=csrf_secret,
field_name = csrf_cookie_name)
signed_cookie_middleware = Middleware(SerializedSignedCookieMiddleware,
secret=b'a very, very secret thing',
state_attribute_name='messages',
cookie_name='my_cookie',
cookie_ttl=60 * 5,
)
auth_middleware = Middleware(AuthenticationMiddleware,
backend=BasicAuthBackend(),
on_error=lambda _, exc: PlainTextResponse("error during authentication", status_code=401)
)
app = oj.load_app([auth_middleware,
signed_cookie_middleware,
csrf_middleware
])
```
### User defined default sty module and TwSty context
The default UI style of a component is determined by its type. For each component type (e.g., Button, Span), a style is defined in the snowsty.py module, which resides within the src/ofjustpy directory.
You can customize the default style by registering a style file
with Ofjustpy. To load your custom style, set the OJSTY environment variable accordingly.
Please note that the default style for a component can be overridden using the `twsty_tags` directive. You can also modify the style programmatically throu TwStyCtx context expression.
Ofjustpy provides two style definitions `snowsty` and `un`. The `un` style does not
add any styling to the components.
An example illustrate style switching:
```python
with oj.TwStyCtx("un"):
oj.Button(..., twsty_tags = []) # Draw a with un default styling
oj.Button(..., twsty_tags = []) # use dnowsty as default styling
```
### Customizing Default Styling in Ofjustpy
In Ofjustpy, the default UI style for a component is determined by its type. Each component type, such as Button or Span, has a predefined style located in the `snowsty.py` module within the `src/ofjustpy` directory.
To personalize the default styling, you can register a custom style file with Ofjustpy. To make use of your custom style, simply set the `OJSTY` environment variable accordingly.
Please bear in mind that you have the flexibility to override the default style for a component using the `twsty_tags` directive.
In addition to setting `OJSTY`, you can programmatically modify the style using the `TwStyCtx` context expression.
Ofjustpy offers two predefined style definitions: `snowsty` and `un`. The `un` style, in particular, refrains from adding any additional styling to the components.
Here's an example to illustrate style switching:
```python
with oj.TwStyCtx("un"):
oj.Button(..., twsty_tags=[]) # Draws with the 'un' default styling
oj.Button(..., twsty_tags=[]) # Uses 'snowsty' as the default styling
```
By following these guidelines, you can easily tailor the default styles in Ofjustpy to suit your project's aesthetic preferences.
### MountContext
The MountContext construct simplifies the process of mounting all the routes defined in a module. Consider the following example:
```python
with oj.MountCtx("examples"):
with oj.MountCtx("static_webpages"):
static_webpage_module = importlib.import_module("examples.static_webpages",
)
```
In the above example, all the routes
defined within the examples.static_webpages will be mounted under
`examples/static_webpages` path.
MountCtx enable a plug-and-play approach for adding modules and defining routes.
This means you can import the module into multiple web app codes without needing to modify the module code for each app. This flexibility simplifies the process of extending and reusing modules across different applications.
### PageBuilder Context
The PageBuilderCtx context is used to modify or post-process webpage endpoints defined within a module. Let's consider the following example:
```python
def page_builder(edir):
"""
We need edir to find the example directory within which the example is located.
"""
def page_builder_inner(key, childs, **kwargs):
title = kwargs.get('title')
nav_buttons = //define a list of navigation buttons
return oj.Mutable.WebPage(key=key,
childs = [oj.HCCMutable.StackV(childs = [oj.HCCMutable.Div(childs=childs),
oj.PC.Hr(twsty_tags=[bg/green/1]),
nav_buttons],
twsty_tags= [space/y/8]
)
],
**kwargs
)
return page_builder_inner
with oj.PageBuilderCtx(page_builder("mutable_webpages")):
with oj.MountCtx("input_components"):
input_components_module = importlib.import_module("examples.input_components",
)
```
In the above example, the `oj.PageBuilderCtx` context is used to post-process all endpoints defined within the `examples.input_components` module. Specifically, it allows for the addition of navigation buttons at the bottom of each page generated by the endpoints in this module. This structured approach simplifies the task of modifying and enhancing the behavior of web pages associated with the `input_components` module by applying a consistent post-processing step to all of them.
Raw data
{
"_id": null,
"home_page": null,
"name": "ofjustpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "Kabira K <kabira@monallabs.in>",
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/75/91/77b5c182d9349e168870c4aaca17bab60d6f9c101ee38bf6596ac232f00c/ofjustpy-1.1.2.tar.gz",
"platform": null,
"description": "# [Ofjustpy](https://github.com/ofjustpy/ofjustpy)\n[](https://pypi.python.org/pypi/ofjustpy)\n[](https://github.com/ofjustpy/ofjustpy/actions)\n[](https://github.com/ofjustpy/ofjustpy/actions)\n[](https://github.com/ofjustpy/ofjustpy/actions)\n\n[](https://ofjustpy.github.io/ofjustpy/)\n[](https://pypi.python.org/pypi/ofjustpy)\n[](https://pepy.tech/project/)\n[](https://pepy.tech/project/ofjustpy)\n[](https://github.com/ofjustpy/ofjustpy/stargazers)\n\n\n# Ofjustpy: A Full-Stack Web Development Framework in Python\n\n**Features:**\n\n* **Single language**: Ofjustpy allows you to build full-featured web pages using only the Python programming language. You don't need to learn and manage multiple languages like Jinja2 templating, JavaScript, HTML, and CSS. The entire functionality of a webpage can be expressed using pure Python.\n \n2. **Emphasis on API Design**: Much emphasis has been put on API design and programmatic constructs in order\nto be able to build complex responsive webpages and websites with codebase that easy to read and maintain. \n\n3. **Scalable and efficient**: Ofjustpy enables programmers to write scalable and efficient webpage code. It maintains only a single copy of static components, regardless of the number of connections opened. Data copying per connection and per event is minized. Even for mutable components, only a single copy of the component's static portion is maintained. Additionally, communication is efficient as it transmits only the changes (diff) to the UI to the frontend.\n\n\n4. **Composibility**: Ofjustpy allows users to easily build reusable components and incorporate them into their codebase. See [htmlcomponents.py](src/ofjustpy/htmlcomponents.py) and [ofjustpy-components](https://github.com/ofjustpy/ofjustpy-components) for simple to complex components build using Ofjustpy framework. \n\n5. **Tailwind CSS Support**: Ofjustpy provides first-class and native support for Tailwind CSS constructs, enabling complex manipulation (add, remove, update classes) of the frontend UI through pure Python expressions.\n\n6. **Async Processing**: Like its predecessor Justpy, Ofjustpy utilizes an asynchronous webserver stack that includes Starlette, ASGI, asyncio, and async/await. This architecture enables Ofjustpy to efficiently handle concurrent connections, even on single-core hardware or virtual environments, without the need for OS-level multi-threading.\n\n7. **Technology Stack**:\nThe tech stack of ofjustpy consists of Svelte (as the frontend UI engine), \nwebsockets (for communication between browser and server), Starlette (the async webserver), \namd Tailwind (for layout and design). \n\n## Gallery \n- See [examples](https://webworks.monallabs.in/examples/index) for a collection of \nbasic tutorial examples of webpages build using ofjustpy. \n\n- See [Basic capabilities demo](https://webworks.monallabs.in/demo_basic_capabilities) for \nwebpage showing basic html components \n\n- See [Advanced capabilities demo](https://webworks.monallabs.in/demo_advanced_capabilities)\nfor webpage illustrating advanced components (hierarchy navigator, pagination) in action. \n\n## Webpage programming using Ofjustpy\nThe basic paradigm for building out webpages in Ofjustpy is straighforward:\n1. Create components and containers\n2. Describe their layout and appearance using tailwind constructs\n3. For components that will respond to events on UI, describe handlers (actions) for those \nevents \n\nIf you are new to web development, then it would be helpful to go through the [justpy docs](https://justpy.io/) and its [examples](https://github.com/justpy-org/justpy/tree/master/examples) on which Ofjustpy is based on. \nAlso, pay careful attention to known corner cases and suggested workarounds mentioned in [Gotchas](https://ofjustpy.github.io/ofjustpy/Gotchas.html) to keep Ofjutpy engine happy \n\nThe demo example illustrates the three paradigms for building out webpages:\n```python\nimport ofjustpy as oj\nfrom py_tailwind_utils import *\n\n\nlabels = [oj.Mutable.Label(text=\"mytext1\", key=\"mylabel1\"),\n oj.Mutable.Label(text=\"mytext2\", key=\"mylabel2\"),\n oj.Mutable.Label(text=\"mytext3\", key=\"mylabel3\"),\n oj.Mutable.Label(text=\"mytext4\", key=\"mylabel4\"),\n ]\n\nmydeck = oj.Mutable.StackD(key=\"mydeck\",\n childs=labels,\n height_anchor_key=\"mylabel1\",\n \n twsty_tags=[W/\"1/2\"])\n\nidx = 1\ndef on_btn_click(dbref, msg, target_of):\n global idx\n mydeck_shell = target_of(mydeck)\n mydeck_shell.bring_to_front(labels[idx].id)\n idx = (idx + 1)%4\n pass\n\n \nmybtn = oj.AC.Button(key=\"mybtn\",\n text=\"abtn\",\n pcp=[W/32, H/32, bg/rose/6],\n on_click=on_btn_click\n )\nwp_endpoint = oj.create_endpoint(key=\"static-components\",\n childs = [mydeck,\n mybtn\n ]\n ) \noj.add_jproute(\"/\", wp_endpoint)\n\n\n\n```\n### Components and their types in Ofjustpy\nOfjustpy, boradly, defines 2 kinds of components: static vs mutable. \nStatic components are further classified into Passive and Active, \nwhile mutable components come in three variety: HCCMutable, HCCStatic, Mutable. \n\n#### Passive Components\nAs name suggests, these do not respond to UI events and also do not undergo \nany changes. Ofjustpy maintains only a single copy of such components (see (see [examples/static_webpages](examples/static_webpages))\nExamples of passive components:\n1. oj.PC.Label\n2. oj.PC.P\n3. oj.PC.Img\n\netc. See [SHC_types.py](src/ofjustpy/SHC_types.py) for list of all passive components. \n\n#### Active Components\nActive components handle events but like passive do not mutate. \nActive components require an additional key/id argument (see [examples/input_components](examples/input_components)). \nExamples of active components:\n1. oj.AC.Button\n2. oj.AC.TextInput\n3. oj.AC.CheckboxInput\n4. oj.AC.Select\n5. oj.AC.A\n\nand so on. See [SHC_types.py](src/ofjustpy/SHC_types.py) for list of all active components\n\n\n#### Mutable components\nMutable components can handle events and also mutate, i.e., change \nappearances. See [examples/mutable_webpages](examples/mutable_webpages) for usage. \nExamples of mutable components include:\n1. oj.Mutable.Button\n2. oj.Mutable.Label\n3. oj.Mutable.Container\nand so on. See [MHC_types.py](src/ofjustpy/MHC_types.py) for list of all mutable components. \n\n\n#### HCCMutable Components\nThese are div components \nthat contain mutable childrens. \nThe div itself is not mutable (see [examples/mutable_webpages/example_004.py](examples/mutable_webpages/example_004.py)). \nHCCMutable components offer minor space optimization \nover Mutable divs. \nExamples of HCCMutable components:\n1. oj.HCCMutable.Div\n2. oj.HCCMutable.StackV\n3. oj.HCCMutable.StackW\n4. oj.HCCMutable.Subsection\nSee [MHC_types.py](src/ofjustpy/MHC_types.py) for list of all HCCMutable components. \n\n#### HCCStatic Components\nThese are div components\nthat itself are mutable but \nthey contain static (passive or active) components. \nExamples of HCCStatic components:\n1. oj.HCCStatic.Div\n2. oj.HCCStatic.StackV\n\nSee [MHC_types.py](https://github.com/ofjustpy/ofjustpy/blob/09fe497badc74d306de3e1e019dcad251de08c11/src/ofjustpy/MHC_types.py#L168C12-L168C12) for list of all HCCStatic components. \njj\n\n\n#### Tailwind-derived higher-order components\nIn addition to standard HTML components (like, Div, Span, Button, etc.),\nOfjustpy offers advanced components that offer complex functionality. These\nare build using Tailwind CSS constructs, Svelte, and Python. \n\n1. Containers to juxtapose child components\nStackH, StackV, StackG, StackW : Stack components horizontally, vertically, grid, and wrap around. See examples [examples/static_webpages/example_001.py](examples/static_webpages/example_001.py), \n[examples/static_webpages/example_002.py](examples/static_webpages/example_002.py) for StackV, [examples/static_webpages/example_004.py](examples/static_webpages/example_004.py) for StackG, [examples/static_webpages/example_002.py](examples/static_webpages/example_002.py) for StackW. \n\n\n2. StackD: \nDeck the items on top of each other. See examples [examples/mutable_webpages/example_005.py](examples/mutable-webpages/example_005.py), [examples/mutable_webpages/example_008.py](examples/mutable-webpages/example_008.py)\n\n3. Slider\nA component with discreet value buttons to select a value.\nSee examples [examples/mutable_webpages/example_002.py](examples/mutable_webpages/example_002.py), [examples/mutable_webpages/example_003.py](examples/mutable_webpages/example_003.py), [examples/mutable_webpages/example_006.py](examples/mutable_webpages/example_006.py).\n\n\n4. ColorSelector\nComponent create select drop down option for all tailwind preset color values. \nSee example [examples/mutable_webpages/example_007.py](examples/mutable_webpages/example_007.py)\n\nSee ofjustpy-components github repo for collection of advanced components. \n\n\n## The Ofjustpy paradigms: app module, TwStyCtx, MountCtx, PageBuilderCtx\n### App module\nOfjustpy requires that starlette app be defined in its own file lets say \n\"theapp.py\". Then set the `OJ_APP_MODULE` to set the location of the `theapp.py`\nrelative to directory from where the webserver is being launched. \n\n\n```bash\nexport OJ_APP_MODULE=\"../the_app\"\n```\nA sample example of `theapp.py` looks as follows:\n```python\nfrom asgi_signing_middleware import SerializedSignedCookieMiddleware\n\nimport ofjustpy as oj\ncsrf_middleware = Middleware(CSRFMiddleware,\n secret=csrf_secret,\n field_name = csrf_cookie_name)\n\nsigned_cookie_middleware = Middleware(SerializedSignedCookieMiddleware,\n secret=b'a very, very secret thing', \n state_attribute_name='messages', \n cookie_name='my_cookie',\n cookie_ttl=60 * 5, \n )\n\n\nauth_middleware = Middleware(AuthenticationMiddleware,\n backend=BasicAuthBackend(),\n on_error=lambda _, exc: PlainTextResponse(\"error during authentication\", status_code=401)\n )\n\n\n\napp = oj.load_app([auth_middleware,\n signed_cookie_middleware,\n csrf_middleware\n ])\n```\n\n### User defined default sty module and TwSty context\nThe default UI style of a component is determined by its type. For each component type (e.g., Button, Span), a style is defined in the snowsty.py module, which resides within the src/ofjustpy directory.\nYou can customize the default style by registering a style file \nwith Ofjustpy. To load your custom style, set the OJSTY environment variable accordingly.\nPlease note that the default style for a component can be overridden using the `twsty_tags` directive. You can also modify the style programmatically throu TwStyCtx context expression.\nOfjustpy provides two style definitions `snowsty` and `un`. The `un` style does not \nadd any styling to the components. \n\nAn example illustrate style switching:\n```python\nwith oj.TwStyCtx(\"un\"):\n oj.Button(..., twsty_tags = []) # Draw a with un default styling \noj.Button(..., twsty_tags = []) # use dnowsty as default styling\n```\n\n\n### Customizing Default Styling in Ofjustpy\n\nIn Ofjustpy, the default UI style for a component is determined by its type. Each component type, such as Button or Span, has a predefined style located in the `snowsty.py` module within the `src/ofjustpy` directory.\n\nTo personalize the default styling, you can register a custom style file with Ofjustpy. To make use of your custom style, simply set the `OJSTY` environment variable accordingly.\n\nPlease bear in mind that you have the flexibility to override the default style for a component using the `twsty_tags` directive. \n\n\nIn addition to setting `OJSTY`, you can programmatically modify the style using the `TwStyCtx` context expression.\n\nOfjustpy offers two predefined style definitions: `snowsty` and `un`. The `un` style, in particular, refrains from adding any additional styling to the components.\n\nHere's an example to illustrate style switching:\n\n```python\nwith oj.TwStyCtx(\"un\"):\n oj.Button(..., twsty_tags=[]) # Draws with the 'un' default styling\noj.Button(..., twsty_tags=[]) # Uses 'snowsty' as the default styling\n```\n\nBy following these guidelines, you can easily tailor the default styles in Ofjustpy to suit your project's aesthetic preferences.\n\n\n\n\n### MountContext\nThe MountContext construct simplifies the process of mounting all the routes defined in a module. Consider the following example:\n\n\n```python\nwith oj.MountCtx(\"examples\"):\n with oj.MountCtx(\"static_webpages\"): \n static_webpage_module = importlib.import_module(\"examples.static_webpages\",\n )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n```\nIn the above example, all the routes \ndefined within the examples.static_webpages will be mounted under\n`examples/static_webpages` path. \nMountCtx enable a plug-and-play approach for adding modules and defining routes. \nThis means you can import the module into multiple web app codes without needing to modify the module code for each app. This flexibility simplifies the process of extending and reusing modules across different applications.\n\n\n\n### PageBuilder Context\nThe PageBuilderCtx context is used to modify or post-process webpage endpoints defined within a module. Let's consider the following example:\n```python\ndef page_builder(edir):\n \"\"\"\n We need edir to find the example directory within which the example is located.\n \n \"\"\"\n def page_builder_inner(key, childs, **kwargs):\n title = kwargs.get('title')\n nav_buttons = //define a list of navigation buttons\n \n\n return oj.Mutable.WebPage(key=key,\n childs = [oj.HCCMutable.StackV(childs = [oj.HCCMutable.Div(childs=childs),\n oj.PC.Hr(twsty_tags=[bg/green/1]),\n nav_buttons],\n twsty_tags= [space/y/8]\n )\n ],\n\n **kwargs\n )\n\n return page_builder_inner\n\n\n\nwith oj.PageBuilderCtx(page_builder(\"mutable_webpages\")):\n with oj.MountCtx(\"input_components\"):\n input_components_module = importlib.import_module(\"examples.input_components\",\n )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n```\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\nIn the above example, the `oj.PageBuilderCtx` context is used to post-process all endpoints defined within the `examples.input_components` module. Specifically, it allows for the addition of navigation buttons at the bottom of each page generated by the endpoints in this module. This structured approach simplifies the task of modifying and enhancing the behavior of web pages associated with the `input_components` module by applying a consistent post-processing step to all of them.\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A webdev framework that enables development of full-stack webpages and app purely in Python",
"version": "1.1.2",
"project_urls": {
"Documentation": "https://monallabs-org.github.io/ofjustpy/ofjustpy",
"Home": "https://webworks.monallabs.in/ofjustpy/ofjustpy",
"Source": "https://github.com/ofjustpy/ofjustpy"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "499fc261d55dd8d4a886d623c58f1883901d667825773b045e9fe08f529f7f9d",
"md5": "36851b8d32056f3b0f5505517ba43d61",
"sha256": "a6cf5ef0ca0ea0d5ee781fb50ab2434b6444a336c05220039978b7aef4bcc616"
},
"downloads": -1,
"filename": "ofjustpy-1.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "36851b8d32056f3b0f5505517ba43d61",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 37398,
"upload_time": "2023-12-05T14:18:25",
"upload_time_iso_8601": "2023-12-05T14:18:25.428490Z",
"url": "https://files.pythonhosted.org/packages/49/9f/c261d55dd8d4a886d623c58f1883901d667825773b045e9fe08f529f7f9d/ofjustpy-1.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "759177b5c182d9349e168870c4aaca17bab60d6f9c101ee38bf6596ac232f00c",
"md5": "70e13d5a6c47dd20ca9b94bcf525e242",
"sha256": "83eaa729ee912d6b387a84897bd2288df97c2e31e1073e7b05d6c4bbf0b9701d"
},
"downloads": -1,
"filename": "ofjustpy-1.1.2.tar.gz",
"has_sig": false,
"md5_digest": "70e13d5a6c47dd20ca9b94bcf525e242",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 106405,
"upload_time": "2023-12-05T14:18:28",
"upload_time_iso_8601": "2023-12-05T14:18:28.858515Z",
"url": "https://files.pythonhosted.org/packages/75/91/77b5c182d9349e168870c4aaca17bab60d6f9c101ee38bf6596ac232f00c/ofjustpy-1.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-05 14:18:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ofjustpy",
"github_project": "ofjustpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "ofjustpy"
}