lilliepy-dir-router


Namelilliepy-dir-router JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/websitedeb/lilliepy-dir-router
SummaryFile-based router for ReactPy or LilliePy framework
upload_time2024-12-20 02:31:21
maintainerNone
docs_urlNone
authorSarthak Ghoshal
requires_python>=3.6
licenseMIT
keywords lilliepy lilliepy-dir-router reactpy router file router file based router file-router file-based-router
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Lilliepy-dir-router
a router that uses folders and files to create routes for reactpy files (is used in the lilliepy framework)

## Dependencies
* reactpy
* reactpy router
* pathlib
* importlib
* os
* re

## Setup
if you are using the lilliepy framework, then this part should be already dont for you, if not, then read this

```python
# your_python_file.py
from lilliepy_dir_router import FileRouter

FileRouter("/path/to/your/pages/folder", verbose=True) # verbose, if set to true, will print out the routes and status of the router
```

## Syntax

there are 4 special types of files/directories to use in this current release

### Folders

#### Silent Folders

silent folders are denoted as ([FOLDER_NAME]), these folders are only for grouping files together, they wont be added to said file's route

##### e.g :-
```
├── pages
│   ├── (files)
│   │   ├── file.x.py
```
* the url for ```file.x.py``` will be /file, notice how it isnt /files/file

### Files

#### Regular Files

regular files must end in a ```.x.py``` extenstion if you want it to render, if there are functions of python files you dont want to render or want to make components that you want to import to other ```.x.py``` files and it said component shouldnt have its own route, then use the regular ```.py``` extension.
* NOTE: the router will ignore files that are not in ```.x.py``` extenstion

##### Syntax
```python
# main.x.py

from reactpy import component, html # import component (to make function a component), and html (to make html), you can also import hooks from here if you want


@component # makes function component
def main(): # NOTE: FUNCTION'S NAME MUST BE THE SAME AS THE FILE'S NAME (THIS IS CASE SENSITIVE TOO)
  return html.h1("yo") # returns <h1>yo</h1>

@component
def test(): # this wont render in this file as it's name isnt the same as the file's name, however, you can use this function in your component (the functions that has the same name as the file's name)
  return html.h1("Test")

```
* again, note, function's name MUST be the same name as the file's name if you want it to render, you can create helper functions and/or import them into the render-ing component

#### ```+root.x.py```

this special file is the root file, it will render in the root of an url, and if it kept in the first dir, then it will render in "/"

##### e.g :-
```
├── pages
│   ├── +root.x.py     <-- this will render in "/"
│   ├── files
│   │   ├── +root.x.py  <-- this will render in "/files", notice it renders in the root folder
│   │   ├── file.x.py
│   ├── another_example
│   │   ├── +root.x.py  <-- this will render in "/another_example", notice it renders in the root folder
│   │   ├── file_two.x.py
│   │   ├── nested_folder
│   │   │   ├── +root.x.py    <-- this will render in "/another_example/nested_folder"
│   │   ├── nested_folder_two
│   │   │   ├── (folder)
│   │   │   │   ├── +root.x.py  <-- this will render in "/another_example/nested_folder", as the parent folder for +root.x.py is a silent folder, so it is neglected
```
* so in simpler terms, the ```+root.x.py``` file will render in the parent folder root dir url
* NOTE: it will not render in "/[PARENT_FOLDER_OF_+ROOT.X.PY_FILE]/", as this is a completely different route
* NOTE: if the parent folder is a slient folder, the +root.x.py file wont be the root file for the silent folder, it will be the root folder for the parent folder of the silent folder

##### Syntax :-
```python
# +root.x.py

from reactpy import component, html

@component
def root(): # the render-ing function for a +root.x.py file MUST be called "root" (LOWER CASE, NOT UPPPER CASE)
  return html.h1("home")
```

#### Slug Files

these are files which take in value(s) from the url, they are made by saying +[(FILE_NAME)].x.py

##### e.g :-
```
├── pages
│   ├── +[name].x.py
│   ├── id
│   │   ├── +[id].x.py
```

##### Syntax :-
```python
# +[id].x.py

from reactpy import html, component


@component
# function's name must be the same as the name given inbetween the two brackets in the file's name
def id(params): # 1 parameter must be given so that this function can access the value(s) in the url, the parameter's name MUST be called params if you want it to be a slug (this is to help differeciate between slug params and other params)
    return html.div([
        html.h1(f"Dynamic Content for ID: {params['id']}"), #params is a dictionary, trust me, knowing that helps you alot
        html.p("This page dynamically renders content based on the slug."),
    ])
```

#### ```+not_found.x.py```
this page (or component) will handle all 404 error routes

##### Syntax :-
```python
from reactpy import component, html


@component
def not_found(): #function's name MUST be not_found
  return html.h1("Not found")
```

### When to use ```.x.py``` and ```.py```

you should use ```.x.py``` when:
  * you want the file to render
  * it dosnt contain sensitive backend code
  * it dosnt have parameters other than the slug file's ```params``` parameter

you should use ```.py``` when:
  * you want to make a component that you want to import and not have a url of its own
  * you want to do backend code
  * you have more parameters than just the slug's ```params``` parameter

you could think of ```.x.py``` as the client components and ```.py``` as the server components in reactjs

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/websitedeb/lilliepy-dir-router",
    "name": "lilliepy-dir-router",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "lilliepy, lilliepy-dir-router, reactpy, router, file router, file based router, file-router, file-based-router",
    "author": "Sarthak Ghoshal",
    "author_email": "sarthak22.ghoshal@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/54/7ec8b903f8d3341b6a330fd2fd633fdd72a2546c0c4205a4883926705426/lilliepy_dir_router-0.1.tar.gz",
    "platform": null,
    "description": "# Lilliepy-dir-router\r\na router that uses folders and files to create routes for reactpy files (is used in the lilliepy framework)\r\n\r\n## Dependencies\r\n* reactpy\r\n* reactpy router\r\n* pathlib\r\n* importlib\r\n* os\r\n* re\r\n\r\n## Setup\r\nif you are using the lilliepy framework, then this part should be already dont for you, if not, then read this\r\n\r\n```python\r\n# your_python_file.py\r\nfrom lilliepy_dir_router import FileRouter\r\n\r\nFileRouter(\"/path/to/your/pages/folder\", verbose=True) # verbose, if set to true, will print out the routes and status of the router\r\n```\r\n\r\n## Syntax\r\n\r\nthere are 4 special types of files/directories to use in this current release\r\n\r\n### Folders\r\n\r\n#### Silent Folders\r\n\r\nsilent folders are denoted as ([FOLDER_NAME]), these folders are only for grouping files together, they wont be added to said file's route\r\n\r\n##### e.g :-\r\n```\r\n\u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac pages\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac (files)\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac file.x.py\r\n```\r\n* the url for ```file.x.py``` will be /file, notice how it isnt /files/file\r\n\r\n### Files\r\n\r\n#### Regular Files\r\n\r\nregular files must end in a ```.x.py``` extenstion if you want it to render, if there are functions of python files you dont want to render or want to make components that you want to import to other ```.x.py``` files and it said component shouldnt have its own route, then use the regular ```.py``` extension.\r\n* NOTE: the router will ignore files that are not in ```.x.py``` extenstion\r\n\r\n##### Syntax\r\n```python\r\n# main.x.py\r\n\r\nfrom reactpy import component, html # import component (to make function a component), and html (to make html), you can also import hooks from here if you want\r\n\r\n\r\n@component # makes function component\r\ndef main(): # NOTE: FUNCTION'S NAME MUST BE THE SAME AS THE FILE'S NAME (THIS IS CASE SENSITIVE TOO)\r\n  return html.h1(\"yo\") # returns <h1>yo</h1>\r\n\r\n@component\r\ndef test(): # this wont render in this file as it's name isnt the same as the file's name, however, you can use this function in your component (the functions that has the same name as the file's name)\r\n  return html.h1(\"Test\")\r\n\r\n```\r\n* again, note, function's name MUST be the same name as the file's name if you want it to render, you can create helper functions and/or import them into the render-ing component\r\n\r\n#### ```+root.x.py```\r\n\r\nthis special file is the root file, it will render in the root of an url, and if it kept in the first dir, then it will render in \"/\"\r\n\r\n##### e.g :-\r\n```\r\n\u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac pages\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +root.x.py     <-- this will render in \"/\"\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac files\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +root.x.py  <-- this will render in \"/files\", notice it renders in the root folder\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac file.x.py\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac another_example\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +root.x.py  <-- this will render in \"/another_example\", notice it renders in the root folder\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac file_two.x.py\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac nested_folder\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +root.x.py    <-- this will render in \"/another_example/nested_folder\"\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac nested_folder_two\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac (folder)\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +root.x.py  <-- this will render in \"/another_example/nested_folder\", as the parent folder for +root.x.py is a silent folder, so it is neglected\r\n```\r\n* so in simpler terms, the ```+root.x.py``` file will render in the parent folder root dir url\r\n* NOTE: it will not render in \"/[PARENT_FOLDER_OF_+ROOT.X.PY_FILE]/\", as this is a completely different route\r\n* NOTE: if the parent folder is a slient folder, the +root.x.py file wont be the root file for the silent folder, it will be the root folder for the parent folder of the silent folder\r\n\r\n##### Syntax :-\r\n```python\r\n# +root.x.py\r\n\r\nfrom reactpy import component, html\r\n\r\n@component\r\ndef root(): # the render-ing function for a +root.x.py file MUST be called \"root\" (LOWER CASE, NOT UPPPER CASE)\r\n  return html.h1(\"home\")\r\n```\r\n\r\n#### Slug Files\r\n\r\nthese are files which take in value(s) from the url, they are made by saying +[(FILE_NAME)].x.py\r\n\r\n##### e.g :-\r\n```\r\n\u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac pages\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +[name].x.py\r\n\u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac id\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201a   \u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac +[id].x.py\r\n```\r\n\r\n##### Syntax :-\r\n```python\r\n# +[id].x.py\r\n\r\nfrom reactpy import html, component\r\n\r\n\r\n@component\r\n# function's name must be the same as the name given inbetween the two brackets in the file's name\r\ndef id(params): # 1 parameter must be given so that this function can access the value(s) in the url, the parameter's name MUST be called params if you want it to be a slug (this is to help differeciate between slug params and other params)\r\n    return html.div([\r\n        html.h1(f\"Dynamic Content for ID: {params['id']}\"), #params is a dictionary, trust me, knowing that helps you alot\r\n        html.p(\"This page dynamically renders content based on the slug.\"),\r\n    ])\r\n```\r\n\r\n#### ```+not_found.x.py```\r\nthis page (or component) will handle all 404 error routes\r\n\r\n##### Syntax :-\r\n```python\r\nfrom reactpy import component, html\r\n\r\n\r\n@component\r\ndef not_found(): #function's name MUST be not_found\r\n  return html.h1(\"Not found\")\r\n```\r\n\r\n### When to use ```.x.py``` and ```.py```\r\n\r\nyou should use ```.x.py``` when:\r\n  * you want the file to render\r\n  * it dosnt contain sensitive backend code\r\n  * it dosnt have parameters other than the slug file's ```params``` parameter\r\n\r\nyou should use ```.py``` when:\r\n  * you want to make a component that you want to import and not have a url of its own\r\n  * you want to do backend code\r\n  * you have more parameters than just the slug's ```params``` parameter\r\n\r\nyou could think of ```.x.py``` as the client components and ```.py``` as the server components in reactjs\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "File-based router for ReactPy or LilliePy framework",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/websitedeb/lilliepy-dir-router"
    },
    "split_keywords": [
        "lilliepy",
        " lilliepy-dir-router",
        " reactpy",
        " router",
        " file router",
        " file based router",
        " file-router",
        " file-based-router"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b1542f89f020c9f4ff886a6c8e92d65b585fd20726298ee2f662d70570387a1",
                "md5": "a93f83cf29add26024e589d3ecf79265",
                "sha256": "52cf10049ae7a8915edbc8c4701e427e52c74fc06eabc6023c6a0e8140cdd270"
            },
            "downloads": -1,
            "filename": "lilliepy_dir_router-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a93f83cf29add26024e589d3ecf79265",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5042,
            "upload_time": "2024-12-20T02:31:19",
            "upload_time_iso_8601": "2024-12-20T02:31:19.135162Z",
            "url": "https://files.pythonhosted.org/packages/2b/15/42f89f020c9f4ff886a6c8e92d65b585fd20726298ee2f662d70570387a1/lilliepy_dir_router-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49547ec8b903f8d3341b6a330fd2fd633fdd72a2546c0c4205a4883926705426",
                "md5": "ce5e9cb8995965c5a8ed4484e0fdebd4",
                "sha256": "004114fa528bd0330b90adffd69507edfb8b8b1222e8fe420c47d46395d944a5"
            },
            "downloads": -1,
            "filename": "lilliepy_dir_router-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ce5e9cb8995965c5a8ed4484e0fdebd4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5044,
            "upload_time": "2024-12-20T02:31:21",
            "upload_time_iso_8601": "2024-12-20T02:31:21.216261Z",
            "url": "https://files.pythonhosted.org/packages/49/54/7ec8b903f8d3341b6a330fd2fd633fdd72a2546c0c4205a4883926705426/lilliepy_dir_router-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-20 02:31:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "websitedeb",
    "github_project": "lilliepy-dir-router",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "lilliepy-dir-router"
}
        
Elapsed time: 0.41696s