Releases: byteface/domonic
Arrays
Arrays have been juiced up a bit.
I often rush ahead and just print stubs with weak assumptions in the code. Then come back later and unit test properly.
Anything printing to the console when tests runs is basically bad as it means it's not got an assertion yet.
I began fixing up js array unit tests but somehow got sucked into making a start on the ArrayBuffers and Typed Arrays. Typical.
They may not work propery I don't yet have use cases for them. But they are passing initial tests. They were a port of a shim however I may be able to swap out some byte calls to use stuct. Will test more later as I find some use cases. i.e. parsing something.
The existing Javascript Array will now relay any missing method calls to the native python one. so you get the best of both.
The docs have also had a bit of a refresh. It's worth cloning the repo just for the sphinx template ;)
Also some good tips on parsing can be found in the ticket for parsers after a question from a user.
pretty
Added pretty printing via the format dunder
so you can:
print(f"mydom")
for a better looking output.
this is useful as gives us mulitple ways to output and without breaking any existing implementations.
Talking of breaking existing implementations. most tag languages are now being moved to xml pacakges.
So lots of the cool stuff basically now lives in xml instead. from sitemap generation to 3d worlds. it's all in the xml folder.
Docs gets 3-4 times more traffic that the repo. So if anyone likes writing documentation get in touch. Same goes for unit tests.
More dom methods added making further compatibility with other things.
with slots pyml
Slots added by contributer Jordan-Cottle
enter added to tag with context attribute to build with. So you can do this...
d = html()
with d:
with head():
div()
with body():
div()
print('DONE!')
oh and also pyml added as a way to render template from a document.
you can go render(mydoc, 'output.pyml', 'pyml') to get a dump. will be buggy as only just started it and not test for it yet.
The other big excitement since last build was connecting to a decent parser and tree builder too. so check out the notes on the 'parser' issue ticket if you're interested.
Text()
More DOM classes started i.e. DocumentType, TextNode change to Text etc few others stubbed out.
As domonic started as a tag builder faking a few dom methods, it is now evolved a lot more than that as I integrate things like d3 and expatBuilder it has to perform more like a regular DOM so have been plumbing in more parts.
Attr upgraded a bit and method around namepaces etc.
The create_element methods on dom and html now check first if there is an existing tag. not sure how to access module methods so doing it via a globals lookup on that module which seems to work i think.
ParseString is started but you probably shouldn't use unless for really strict xml type documents. But it may be better than my parser for basic stuff and is helping drive the DOM so is there to tinker with.
Likely to be lots of bugs on new features as its a very stubby commit. As always don't trust undocumented features.
Assertions added to make it a bit more reliable to change things and to quieten the tests a bit.
better than esx
mostly d3. working hard to get selection working. still very buggy. but the working parts are certainly powerful and it's hepling to drive the development of the DOM and the javascript modules.
new window module due to the componentregistry. i find this of most interest at the momet as I've been looking for various ways to bind custom componenets over sockets and that seems like a potential for one that has it's class registered on the server side. so could be an area for play or investigation.
there's a new downstream repo called esx for the javascript only. But it's worth pointing out that domonic is only 1mb uncompressed as a total package. 'esx' is downstream from this one and will only be updated irregularly. If it becomes popular it could feed this one. but for now it will be this way around.
updated docs. DOCS GET 2-4x more traffic than the repo. So updating the docs is almost now more 2-4x more important than coding. As you can write code but if no-one knows it's there or what it can do there's not much point.
also finally fixed my linting issue that was stopping 'typing' from correctly syntax coloring. I basically had too many python linting packages installed and all fighting with each other. So you may see more type hinting appear when I'm feeling useless and unable to code and just want to piss around the edges of things padding it out and being a pedantic prick. I'm take it or leave it with typing (as I come from languages with it). So It's not a strict design design by me to omit or use them.
I feel it's getting better all the time. Never too late to start contributing. I'm still less than half way complete and that's taken over a year. So always a good time to send a pull request.
setTimeout clearTimeout
been a long time coming for these 2 methods. I can't take the credit this time. I've been avoiding them after the time it took me to do setInterval.
But many thanks to Jordan Cottle for being brave enough to wade through my mess of badly done tests to add some very cool stuff!! I learned a lot from that push also in the unit tests, so thanks.
What I also did was register all the global methods onto the module. Not sure how that will go down with people that import * but I figured it was nice to have those in 3 places. window. Global and just.. there. anyway, maybe window could extend global??...
hope you enjoy the 2 javascript classics!
DocumentFragment
so i made a start on the sanitizer api...
https://wicg.github.io/sanitizer-api/#sanitizer-algorithms
which lead to the creation of DocumentFragment.
DocumentFragment is now available. it can decorate other elements that don't have a document to make available a few methods of the Document class. when you call str on it, it only returns the content.
also quite a big change to tag.
element.attributes wasn't returning due to tag sharing the name. so tag is now changed to attributes which stringifies the kwargs and elements attributes prop now works. however be aware it returns not a dict but a list of Attr. I considered attributes_ to return kwargs but will see how this pans out. I was surprised all tests still passing so hope it doesn't affect anyone.
added a page for the utils to the docs. will see if they appear.
trim pad from_
couple of missing string methods for trim and pad
array has a static from method that has an undercore at the end. will need to document that for all clashes and get a list of ones that do it.
dont use d3... its to drive dev. altho 4 methods on there now work. see tests if you're keen to play.
Style is being phased out for a full cssom as d3 kind wanted the CSSDeclration props. So looks like a lot of work ahead there too once d3 is finished.
stubbed out Set for JS. turns out you can put dicts in a JS Set so will need to implement that to finish it off.
Stubbed out ccsom
parser slight fix (read notes)
the parers main issue is it's an inplace parser. initially for simple html blobs.
as it grew more complex it's main problem is that python wants keywords after args...
so you need to swap the keywords and the content positions around when you parse.
to do this the eval needs the code on separate lines. so it can wrap .html after the keywords and nest the content by passing it through a function rather than as a paramter. (kind of cheating).
The inplace parser is not tagged but is split mostly onto lines which are recognised at the time so could be.
to keep small blobs cute they were not being formatted. and I hand't written a proper formatter at that time. so most of the unit tests would fail when moving to a splitline parser.
This unocvered that a single line of lists gets wrapped by the eval. but split doesn't as it doesn't handle it as a single failling line.
anways to solve that it now tries twice. i.e. if fails on with splitlines. it will flatten the line.
I doubt anyones using the parser much and probably shouldn't it's s secondary feature really to the html generation.
anyway there's a cool example called codemirror in the examples folder than can now convert html to pyml with the evolving parser tools.
document
document is now a global to the dom module and updates whenever you create a html tag. it houses an empty html tag by default so that static methods are availabe.
from domonic.dom import document
print(document)
d3 selection class is started. but all d3 is undocumented so not officially supported yet. however check out the unit tests if you're interested in using selection and to see how the port is going.
They're not yet on d3 as a modules.. you have to import their methods directly. (see unit tests)
It doesn't appear to break anything... yet. but will mean you have to manually switch the reference if you have multiple documents (as extra libs d3 will rely on it.) The alternative is the dQuery method of having an init call... which may go away in favour of the global.