Introducing PHYAL,
A simple to use Framework with a Python syntax that can replace HTML in a comfortable and easy way.
I have seen people discouraged by websites because of HTML not being similar to other languages they have seen. So, I made a framework that allows you to make websites using a Python like syntax, in Python, without the trouble of HTML.
You can check it out here today → PHYAL Replit - PHYAL GitHub
If you could consider giving the GitHub Repo a Star, that would help me a lot.
You can import PHYAL
like so → import phyal
And in the shell → pip install phyal
Make sure to check out the README.md
to learn how to easily use it.
PHYAL - 0.2.2
- Added import statement so you can use
PHYAL
without the source code
PHYAL - 0.2.1
- Merged
framework.py
and html_generator.py
to remove clutter
PHYAL - 0.2.0
Thanks to @NuclearPasta0 for the suggestion
- Updated Syntax to make it easier to read
PHYAL - 0.1.0
Alpha release of PHYAL to see if it received well.
- Added a select few elements to use in
PHYAL
(more/all will come later)
- Basic use (could possibly be buggy, in that case message me here on
Replit Ask
about it
If you have any ideas you can also create a Pull Request
or Issue
on the GitHub Repo here → GitHub - SalladShooter/PHYAL: A simple to use Framework with a Python syntax that can replace HTML in a comfortable and easy way..
If you notice anything that needs improving please share your feedback! I will credit you if you make a suggestion in the next update.
Made by @SalladShooter - 2024
7 Likes
Nice.
I’d like to give some feedback about the code design, mostly at the Tag and Tags.
I see that the flow with tags is with method chaining a.b().c().d()
. To me it feels unnecessary, but if there is a certain reason for this, then okay. I know it is common in JS and other languages.
In Tag
, you have an attributes
list that can be filled up with the attribute()
method. Ignoring the subclasses of Tag
for now, why is it a list and why is it filled with attribute()
? Why not a dict
, or SimpleNamespace
, or a combination of the two? Also, a good time to set the attributes
would be in __init__()
, right? The id()
method would also be redundant.
def __init__(self, name, text='', **attributes):
...
self.attributes = attributes
The add_children()
method also seems a little strange to me, if children were instead set in __init__()
, I feel like it would look nicer.
Having one subclass for each kind of Tag looks really weird and unpythonic. A factory getter on Tags
, with a separate dict when a Tag requires some attributes, might be better. Or even forgo the Tags
collection and have users directly use Tag()
.
If you have feedback on my feedback, please share your feedback!
2 Likes
@NuclearPasta0 how exactly would you want this to look, are you talking about it changing the source code or syntax?
To change the source code and syntax.
Here’s how the syntax might work.
html_content.append(str(Tag('a', 'Link', my_attr='https://google.com')))
html_content.append(str(
Tag('p', 'Hello World', id='what', children=[
Tag('div', children=[
...
])
])
))
# or
html_content = [str(
Tag(
'p',
'Hello World',
id='what',
children=[
Tag('div', children=[
...
]),
Tag(...),
]
)
))]
from types import SimpleNamespace
# Tag
def __init__(self, name, text='', /, *, children=(), **attributes):
...
self.children = list(children)
self.attributes = SimpleNamespace(**attributes)
A benefit of not having Tag
subclasses is that you don’t have to account for every tag, and there may be tags that you haven’t implemented I guess.
Also, you may want to do the str()
conversion internally, so html_content
is of type list[Tag]
.
P.S.: I don’t know html.
4 Likes
You may be wondering “where is PHYAL?”, don’t worry, I didn’t give up or forget. I am working on a massive update that will take PHYAL out of its early test stages to a place where actual projects could get made. I plan on finishing this update by 2024-05-01T05:00:00Z. In the mean time if you want to help out you can check the GitHub to find issues with current updates, add some code of your own, or share your ideas on GitHub Disscusions.
Have a good day,
@SalladShooter
1 Like