Skip to content

Commit

Permalink
Docs/cli docs (#138)
Browse files Browse the repository at this point in the history
* feat: add a global starfyre import way

* add js

* add js files

* complete the feature

* fix formatting

* docs: update starfyre docs
  • Loading branch information
sansyrox authored Jan 18, 2024
1 parent a1fa1a5 commit 2065e95
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 30 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A sample project is hosted on [GitHub](https://github.com/sansyrox/first-starfyr
To create an application

```bash
python3 -m starfyre --create="my-app"
starfyre --create="my-app"
```

It will use the [create-starfyre-app](https://github.com/sparckles/create-starfyre-app) as the template to create a new project.
Expand All @@ -49,7 +49,7 @@ def message():
return "World"

---client
import js
from starfyre import js

def handle_click():
js.console.log("Hello World")
Expand Down Expand Up @@ -172,9 +172,9 @@ Fireworks = "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
You can specify the dependencies using the following commands:

```bash
python3 -m starfyre --add-pyxide-package="package-name"
python3 -m starfyre --add-server-package="package-name"
python3 -m starfyre --add-js-module="module-name" --as="alias"
starfyre --add-pyxide-package="package-name"
starfyre --add-server-package="package-name"
starfyre --add-js-module="module-name" --as="alias"
```


Expand Down
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A sample project is hosted on [GitHub](https://github.com/sansyrox/first-starfyr
To create an application

```bash
python3 -m starfyre --create="my-app"
starfyre --create="my-app"
```

It will use the [create-starfyre-app](https://github.com/sparckles/create-starfyre-app) as the template to create a new project.
Expand All @@ -46,7 +46,7 @@ def message():
return "World"

---client
import js
from starfyre import js

def handle_click():
js.console.log("Hello World")
Expand Down Expand Up @@ -169,9 +169,9 @@ Fireworks = "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
You can specify the dependencies using the following commands:

```bash
python3 -m starfyre --add-pyxide-package="package-name"
python3 -m starfyre --add-server-package="package-name"
python3 -m starfyre --add-js-module="module-name" --as="alias"
starfyre --add-pyxide-package="package-name"
starfyre --add-server-package="package-name"
starfyre --add-js-module="module-name" --as="alias"
```


Expand Down
4 changes: 2 additions & 2 deletions docs/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The compiler is a core component of Starfyre that facilitates the conversion of

- **Exception Handling**: The compiler introduces new exception classes to handle specific scenarios, such as the absence of `__init__.fyre` or conflicts due to the use of an `index.fyre` file.

- **Parsing `.fyre` Files**: Each `.fyre` file is parsed to extract `Python`, `CSS`, `PyML`, `JS`, and client-side Python components. These components are then transpiled into intermediate representations.
- **Parsing `.fyre` Files**: Each `.fyre` file is parsed to extract `Python`, `CSS`, `Pyxide`, `JS`, and client-side Python components. These components are then transpiled into intermediate representations.

- **IR Generation**: The transpiled components are combined to generate an intermediate representation (IR) of the `.fyre` file's content.

Expand All @@ -19,7 +19,7 @@ The compiler is a core component of Starfyre that facilitates the conversion of
## Transpiler Details
The transpiler takes the intermediate representation (IR) of `.fyre` files, which are `.py` files that capture the abstracted structure of the original `.fyre` code, and generates executable Python code. It accomplishes this through the following steps:

1) **Extracting IR Components**: The transpiler extracts `Python`, `CSS`, `PyML`, `JS`, and client-side Python components from the IR.
1) **Extracting IR Components**: The transpiler extracts `Python`, `CSS`, `Pyxide`, `JS`, and client-side Python components from the IR.

2) **Creating Python Code**: Based on the extracted components, the transpiler creates Python code that utilizes the `create_component` and `hydrate` functions appropriately. It also handles the special case of the `__init__.fyre` file.

Expand Down
18 changes: 9 additions & 9 deletions docs/component_parser.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Component Parser in Starfyre

### Introduction
This document provides an overview of the `ComponentParser` in Starfyre. This crucial feature ensures the correct parsing of PyML structure, validates tags, and maintains proper tag order in Starfyre components.
This document provides an overview of the `ComponentParser` in Starfyre. This crucial feature ensures the correct parsing of Component structure, validates tags, and maintains proper tag order in Starfyre components.

### Feature Overview
The `ComponentParser` is responsible for parsing `PyML` structures and ensuring that they adhere to specified rules. It plays a significant role in validating tags, their attributes, and their order within the component.
The `ComponentParser` is responsible for parsing `Component` structures and ensuring that they adhere to specified rules. It plays a significant role in validating tags, their attributes, and their order within the component.

### Implementation Details
The `ComponentParser` in Starfyre is implemented as a class inheriting the `HTMLParser`. Here's an overview of its functionality:
Expand All @@ -21,30 +21,30 @@ class ComponentParser(HTMLParser):
def handle_data(self, data):
# Logic for handling data...

# Additional methods for processing PyML content...
# Additional methods for processing Component content...

```
### Event Handling and Props
The parser identifies event handlers and props within PyML tags, ensuring they are correctly associated with their respective components.
The parser identifies event handlers and props within component tags, ensuring they are correctly associated with their respective components.

### Custom Components
When encountering custom components in PyML, the parser correctly integrates them into the component hierarchy. This ensures that custom components are properly recognized and processed.
When encountering custom components, the parser correctly integrates them into the component hierarchy. This ensures that custom components are properly recognized and processed.

### Error Handling
The Component Parser performs thorough error checking, ensuring that tags are valid and in the correct order. When an issue is detected, it raises an exception with detailed information, including the component name and line number.

### Usage Example
Here's an example of how the Component Parser is utilized within Starfyre:

1) Create a `PyML` file for your Starfyre component.
1) Create a `.fyre` file for your Starfyre component.

2) Define your component structure using `PyML` syntax.
2) Define your component structure using `.fyre` syntax.

3) Use the `ComponentParser` class to parse the `PyML` content of your component.
3) Use the `ComponentParser` class to parse the `.fyre` content of your component.

4) Handle any exceptions raised during parsing, including the `UnknownTagError`.

5) Utilize the parsed component structure to generate dynamic content within your Starfyre application.

### Conclusion
The Component Parser is a critical part of Starfyre, ensuring the correct parsing and validation of PyML structures. With the introduction of the UnknownTagError and improved error reporting, developers can more easily identify and resolve issues within their components.
The Component Parser is a critical part of Starfyre, ensuring the correct parsing and validation of Pyxide structures. With the introduction of the UnknownTagError and improved error reporting, developers can more easily identify and resolve issues within their components.
5 changes: 4 additions & 1 deletion starfyre/dist_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def write_python_client_file(path: Path):
dist_path.mkdir(exist_ok=True)
with pkg_resources.path("starfyre.js", "store.py") as store_py, pkg_resources.path(
"starfyre.js", "dom_helpers.py"
) as dom_helpers:
) as dom_helpers, pkg_resources.path("starfyre.js", "starfyre.py") as starfyre:
store_path = dist_path / "store.py"
shutil.copy(str(store_py), str(store_path))
dom_helpers_path = dist_path / "dom_helpers.py"
shutil.copy(str(dom_helpers), str(dom_helpers_path))
starfyre_path = dist_path / "starfyre.py"
shutil.copy(str(starfyre), str(starfyre_path))


def generate_html_pages(file_routes, project_dir: Path):
Expand Down Expand Up @@ -136,6 +138,7 @@ def copy_starfyre_config(project_dir: Path):

pyscript_data = {}
pyscript_data["packages"] = data["pyxide_packages"]
pyscript_data["files"] = {"./starfyre.py": "./starfyre.py"}

js_modules_main = {}
for js_module in data["js_modules"]:
Expand Down
2 changes: 1 addition & 1 deletion starfyre/js/dom_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ujson as json
import js
import ujson as json


def is_listener(name):
Expand Down
6 changes: 6 additions & 0 deletions starfyre/js/starfyre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import js
from pyscript import display, document, window

websocket = js.WebSocket

__all__ = ["websocket", "document", "window", "js", "display"]
3 changes: 1 addition & 2 deletions starfyre/js/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import random

import js

from starfyre import js

store = GLOBAL_STORE
observers = GLOBAL_OBSERVERS
Expand Down
2 changes: 1 addition & 1 deletion test_application/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

python3 -m starfyre --build --path="."
starfyre --build --path="."
2 changes: 1 addition & 1 deletion test_application/pages/__init__.fyre
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle_on_click(e):


from pyscript.js_modules import Fireworks
from pyscript import document
from starfyre import document

#container = document.querySelector("[data-pyxide-id='root']")
#f = Fireworks.Fireworks.new(container)
Expand Down
2 changes: 1 addition & 1 deletion test_application/serve.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

python3 -m starfyre --serve --path="."
starfyre --serve --path="."
1 change: 1 addition & 0 deletions test_application/starfyre_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ server_packages = []
[js_modules]
is_odd = "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
Fireworks = "https://cdn.jsdelivr.net/npm/[email protected]/+esm"

4 changes: 2 additions & 2 deletions test_application/store.fyre
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---client

from pyscript import display
from pyscript import window, document
from starfyre import display
from starfyre import window, document


---

0 comments on commit 2065e95

Please sign in to comment.