Giter Club home page Giter Club logo

byteface / domonic Goto Github PK

View Code? Open in Web Editor NEW
130.0 5.0 12.0 48.49 MB

Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.

Home Page: https://domonic.readthedocs.io/

License: MIT License

Python 98.55% HTML 1.27% Makefile 0.13% Shell 0.04%
python dom html dom-api javascript terminal prototype python3 hacktoberfest hacktoberfest2021

domonic's People

Contributors

alfasst avatar arjixwastaken avatar byteface avatar code-review-doctor avatar dependabot[bot] avatar frackoverflow avatar jordan-cottle avatar kainech avatar kthy avatar lmgarret avatar shoginn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

domonic's Issues

import domonic.html

Hi, I'm trying to get a handle on domonic.html module via import domonic.html or from domonic import html as opposed to from domonic.html import * (to be able to do html.span("hello") instead of span("hello")). However, domonic.html is ambiguous with the value "html" that gets imported in domonic/__init__.py . I think the star import there is responsible but I'm no expert. Given that import, all of html's exports are accessible by dom; i.e. you can write dom.span("html") which would seem to accomplish my needs but I don't think was intended in the design of these modules; that is I can confusingly write import domonic as html when I want import domonic.html.

Some tests are skipped due to duplicate names

Test names must be unique per scope otherwise the second test overrides the first one with the same name.

For example if you had a test file that does:

def test_a():
    pass

def test_a():
    pass

Then only the second test_a will be ran. More details here.

These are the tests that are overriding previously defined tests due to this problem:

def test_body(self):

I found this issue automatically, see other issues here

MutationObserver

While answering a question on stackoverflow today i realised that domonics mutationobserver is still commented out as TODO but also querySelectorAll is supposed to be 'not live'...

https://stackoverflow.com/questions/69975232/track-changes-within-dom-element-with-mutationobserver-python/69987634?noredirect=1#comment123721040_69987634

I have a feeling ours will be live. so should be returning node copies instead? It may not be and passing by value so I'll have to check.

If anyone is keen to dev this bit up then take it away. Otherwise will leave as a ticket for now til i get time.

linting

whats a good example of a .vscode linting setting.

feature request: boolean attributes

In HTML5, there are a number of boolean attributes, e.g. async, checked and disabled. It would be nice if these could be recognized and simply output as their short form. Currently, as a workaround, you can give them an empty string or their own name as value, e.g.

_script(_src="foo.js", _async="async")

gives

<script src="foo.js" async="async"/>

but would be nice if we could have

<script src="foo.js" async/>

docs

js docs are particularly weak. only really auto docs with no examples.

best examples would be the use of Casting to get the method you need.

d3 - Tile

Tile was unfinished but ended up in the repo.

@FrackOverflow If you enjoyed fixing my polygon d3 has a tons of fun stuff. i.e d3 - heirachy

and some real beauties if you dig around. i.e. https://github.com/d3/d3-plugins/tree/master/superformula

FYI my reason for porting d3 was to create 'real world' test cases for the use of Javascript.py class in domonic.

Just so you know it was mainly done to help me evolved the Javascript class. It makes it useful for quickly porting stuff. But ideally we'd do it all in proper python as swap out the js-like useage. Just incase you wonder why the code in the d3 section in strange.

Exception: unable to update parent 'Comment' object has no attribute 'args'

When instantiating a domonic.html.comment (or a dom.Comment, same same) object in a Sanic response, I'm getting the exception unable to update parent 'Comment' object has no attribute 'args' (from dom.py line 193) seven to eleven times in my log. I can't reproduce it in a REPL session. I also can't figure out why I get any particular number of exceptions, but they are the same number from page load to page load.

@app.route("/test_comment")
async def test_comment(req):
    return response.html(f"{html(head(), body(comment('foo')))}")
[2021-10-11 12:39:04 +0200] [9197] [INFO] Starting worker [9197]
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
unable to update parent 'Comment' object has no attribute 'args'
[2021-10-11 12:39:15 +0200] [9197] [DEBUG] KeepAlive Timeout. Closing connection.

parser

I think I'm going to need a few types of parser. a normal one, one that uses python built in one, peg ones, ones that can do xml/svg/html/... as well as my evolving one. consider importing something light if it could easily output domonic style pyml. but this could do with conversations with others that are good at that kind of thing for suggestions to improve. etc.

queryselectors need updating

we have a new replacement method that can do complex css queries but for some reason it doesn't do simple ones i.e. single tags. so they needed to be merged however an issue arose as the new one used getElementByID which was using querySelctor. fuck. So I losts a ton of fucking time and broke a branch (that had my an attempt at dict setters for attribs in it). anyways. will have another attempts at merging these together to work properly again another time. Or unless someone really really complains.

unit tests

I'm bad at these. so any help tightening them up is always appreciated. plus i learn seeing what people do. However be aware changing any prints to assertions you will find bugs.

type hints

I've been casually adding it. So feel free to put more in if you see places it won't hurt.

requirements upper bounds

I've been enjoying your library, it has some of the better implementations in an easy to implement way (ex. _methods)

One thing I've noticed is that you have specified that your requirements are all static (requests/urllib for example).

Because your implementation of those requirements are not really integrated into your library, would it not make more sense to create a major version upper limit?

my rec:

requests~=2.26
urllib3~=1.26

Im of course ready to be corrected on this.

mathml example with the shim in place

i made a ticket to remember to do this. but just to note if anyone has examples of any type feel free to put them forward. I find them useful. so as long as they small ish and show of a particular feature that's not yet been shown in another example then please do consider putting it forward. thanks.

htmx integration

HeyπŸ‘‹ I'm exploring ways to integrate htmx with domonic. Although the **{"":""} method works just fine, but it tends to result in spaghetti-like code just like React or Vue 😝

Screenshot_20240218_184043

To avoid this, I've worked around. However, the challenge lies in creating custom elements inherited from base elements for inputs, links, buttons, forms, and perhaps divs each one for each one .
here is an example of my simple cutom button:

from domonic import button

class Button(button):
    def __init__(self, text, accent, icon):
        super().__init__(text)
        self.setAttribute("accent", accent)

    def change_accent(self, accent):
        self.setAttribute("accent", accent)

    def htmx_get(self, url: str):
        self.setAttribute("hx-get", url)

    def htmx_post(self, url: str):
        self.setAttribute("hx-post", url)

    def htmx_trigger(self, event: str):
        self.setAttribute("hx-trigger", event)

    def htmx_target(self, target: str):
        self.setAttribute("hx-target", target)

    def htmx_swap(self, swap: str):
        self.setAttribute("hx-swap", swap)

the question, Is there a way to achieve this without having to inherit from each element and create a custom one?
It would be fantastic if domonic had a built-in htmx functions for buttons, inputs, forms, hrefs, or even divs, similar to the div.html() For example:

htmx_button = button('some action').htmx_post('/post').htmx_target('.post')
# or like so
htmx_button = button('some action')
htmx_button.set_hxpost("/post")
htmx_button.set_hxtarget(".post")

You get the point.

upgrade requests to >=2.31.0

Hi! requests 2.31.0 addresses some security issues that affect versions v2.3.0 and v2.30.0. Upgrading domonic's dependency would be nice.
For context, we use domonic as a dev dependency in our stack to locally produce some html documentation files, but cannot upgrade requests since domonic has the requirement requests~=2.28.0.

Which makes me think, would it be possible to make requests as an extra dependency for people who want to load remote html? e.g. in our case we're not interested in this feature, but I see what it could be used for and I would find it reasonable to pip install domonic[requestes] if I wanted to use this feature.

Thanks!

slots

I read something about these improving performance but also heard they make your thing immutable. i then figured i could extend a slotted object? and the extended one wouldn't?. i put the placeholders in for slots on the html tag and commented them out for later testing and consideration but stil haven't read and understood enough about them tbh. So this will have to be something I come back to or take advice on.

insertAdjacent

there's a few methods with insertAdjacent etc on dom which look a bit tricky. if anyone needs them feel free to push if i dont get to them.

regex class - need more work

I've realised flagging some things as help wanted works. 2 tickets closed recently by someone else.

So I will make effort to let people know what I will probably be slow getting too.

Regex is a class low down my radar and I've only done what's needed as I go. if anyone needs this or wants to take it on, then go ahead. Realistically i wont get to it otherwise for a while yet as still busy on other areas.

bug with rendering urls in <a> tags

Howdy. There seems to be some issue rendering the href tag, at least in <a> tags. If you include query parameters it cuts off the link past the ?, if you include https://. See below.

Note, the link does work if put into resulting html correctly (meaning, with the query).

from domonic import a, render

if __name__ == "__main__":

    urls = [
      'example.com/stuff?things=morestuff',
      'https://example.com/stuff?things=morestuff',
      'https://example.com/stuff',
      'https://www.example.com/stuff?thing',
      'https://www.example.com/?stuff'
    ]

    for url in urls:
        print(
            f'''
---------
Renders as: {render(a(_href=url))}
 should be: <a href="{url}"></a>
---------'''
        )

results in the following:

---------
Renders as: <a href="example.com/stuff?things=morestuff"></a>
 should be: <a href="example.com/stuff?things=morestuff"></a>
---------

---------
Renders as: <a href="https://example.com/stuff"></a>
 should be: <a href="https://example.com/stuff?things=morestuff"></a>
---------

---------
Renders as: <a href="https://example.com/stuff"></a>
 should be: <a href="https://example.com/stuff?thing"></a>
---------

---------
Renders as: <a href="https://www.example.com/stuff"></a>
 should be: <a href="https://www.example.com/stuff?thing"></a>
---------

---------
Renders as: <a href="https://www.example.com/"></a>
 should be: <a href="https://www.example.com/?stuff"></a>
---------

number utils

I think having a package for utils then having utils for different types of thing is good. obviously preffered if somethign to do with DOM or internets etc. i.e. ip utils maybe. things like that.

cssom

this is in the style.py file at the moment. I semi started it as d3 thing i was doing used some part of it. but I probably wont take that on fully just yet if someone else want it first take it.

f-string response includes closing tags for void elements

When converting the html object with str and returning it as a response, closing tags for void elements like meta are correctly omitted.

When converting it in an f-string and returning it as a response, closing tags are erroneously included. Example of a simple Sanic route:

@app.route("/404.html")
async def not_found(req: request.Request) -> response.HTTPResponse:
    four_oh_four = html(
        head(
            meta(_charset="utf-8")
        ),
        body(
            h1("Page Not Found"),
            p("Sorry, but the page you were trying to view does not exist."),
        ),
        _lang="en"
    )
    return response.html(f"{four_oh_four}")

which generates the following HTML:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		</meta>
	</head>
	<body>
		<h1>Page Not Found</h1>
		<p>Sorry, but the page you were trying to view does not exist.</p>
	</body>
</html>

Note the errant </meta> on line 5. For comparison, the output with return response.html(str(four_oh_four)) is

<html lang="en"><head><meta charset="utf-8" /></head><body><h1>Page Not Found</h1><p>Sorry, but the page you were trying to view does not exist.</p></body></html>

but then I don't get the doctype element.

docstrings

when i first copy and paste method names from MDN page. i just turn the description of the method into a comment then start trying to make them work.

however later we have docstrings that looks like this

def somemethod(x,y,z):
""" some description of the method """

what I'd prefer is they all had proper docstrings and sometimes have been replacing them as I see them. so you will see a mix of both styles in the code. But feel free to help on that effort. they are quite quick to do. as you can auto gen the docstring. then as you start to type a description copilot usually does a semi decent job of finishing it. If you see any docstrings that are done like the example above. just feel free to change them to the proper ones as you go.

timeouts -

currently missing decent setTimout and clearTimeout methods.

I'd like these to work 2 ways. async and not. so a flag needs to be added to make async=True. currently i doubled up and 2 new ones to 'Global' so the old implementations could be left alone. (not that they worked. its just a sleep.)

ideally somehow utilise the SetInterval work that was done in the past. I had avoided ayncio due to api changes between python versions. I'd get setInterval to work in one version but it would fail in another so went to 'threads' for the Job class. howeer this is only async atm. should it block during exec?

for now I can't see me getting to this for a while. so making a ticket not to use setTimeout and clearTimeout as they aren't done. But will be once I get time and can think about how I resolve these issues.

unit test and assertion for any existing or new method

If you want to get involved then create an assertion in a unit test for any given method. some are still just print statements at the moment.

this may also uncover bugs. so be prepared.

or create a new unit test for a method that isn't done yet and make it work. good luck

xpath

I haven't even started to look into this. But figured i'd see if this 'up for grabs' label is worth trying.

https://up-for-grabs.net/#/

if anyone want to try xpath integration. Is there something in standard lib?. another small lib that works already with domonic? figured i'd start a discussion.

dquery finish get and ajax calls

i didnt do much here. just a quick test. its very lazily done but a cute feature if finished. I may not get to it for a while so there for the taking. as are many methods in this class still.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.