byteface / domonic

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.
https://domonic.readthedocs.io/
MIT License
128 stars 13 forks source link

queryselectors need updating #15

Closed byteface closed 2 years ago

byteface commented 3 years ago

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.

byteface commented 2 years ago

I looked into this a little bit. I can't remember fully. But it might only be the class selector that fails when not provided a tag.

getElementsBySelector('.someclass') < not works getElementsBySelector('div.someclass') < works

pos = str.find(element, ".")  # Class
            if(pos + 1 and not(pos > left_bracket and pos < right_bracket)):
                # print('IM A CLASS')
                parts = str.split(element, '.')
                tag = parts[0]
                class_name = parts[1]
                # print(tag)
                # print(class_name)
                found = getElements(context, tag)
                # found = document.getElementsByClassName(class_name

I noticed if there's a '.' then it will have no tag to reference. So making that part work could be the key to swapping that in as the querySelectorAll replacement.

Frustratingly at the moment. The getElementsBySelector fails if not tag is provided. but can do slighly more complex css selectors.

byteface commented 2 years ago

this bug was fixed. so closing until this whole lot is revisited. functional but not pretty. will need to fixup on a refactor push some point.