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

import domonic.html #59

Open piotrm0 opened 2 years ago

piotrm0 commented 2 years ago

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.

byteface commented 2 years ago

Hi @piotrm0 thanks so much for feedback.

You are kind of correct on this and I was going to address it by documented namepacing.

However the only place I've seen it could be an issue might be django users.

(If you don't require a parser, the lightweight htmlx repo has everything moved to a 'tags' package. *undocumented) https://github.com/byteface/htmlx/

However the issue here (in domonic) is actually 3 fold.

There's the built in html i wanted to avoid as it has the escape package many people would want.

there an 'html' element,

as well as the module name.

The only way I could think to get around it was to change the module name or document usesage for those that want namespacing, which I wish I'd done now as I spent a few hours investigating then never posted the reuslts after I figured out the same as what you arrived at. I should have realised this would be useful to tell people.

import domonic as html

which only works as a fluke due to the core init file import the html module. so you are correct in there's an issue and also great you found the same workaround. As for a solution I think documenting namespace useage high up in the readme is all I can think of without breaking backwards compatibility. I had pondered on this before.

I actually considered changing html module to tags for v1. but still not sure how that would go down. had meant to test the concept more in htmlx first.

byteface commented 2 years ago

hmmm i wonder if a module called tags that imports html would work?. specifically for namespacing. happy to hear your thoughts if you have any ideas.

piotrm0 commented 2 years ago

A module "tags" or "tag" anything else informative that would let us write "tag.br()" instead of "br()" using the star import would solve my problem.

byteface commented 2 years ago

I did have another idea which was to not import the html element in domonic root. But that would stop me from being able to do from domonic import *

I've added the tags package and imported all from html into it. I think this now does what we want?...

import domonic.tags
print(domonic.tags.h1)
# or
import domonic.tags as tags
str(tags.div)
# or 
import domonic.tags as html
print(html.span)

Let me know if this is ok. Should be there on the 0.9.9

nacho00112 commented 1 year ago

I did have another idea which was to not import the html element in domonic root. But that would stop me from being able to do from domonic import *

I've added the tags package and imported all from html into it. I think this now does what we want?...

import domonic.tags
print(domonic.tags.h1)
# or
import domonic.tags as tags
str(tags.div)
# or 
import domonic.tags as html
print(html.span)

Let me know if this is ok. Should be there on the 0.9.9

Please come back the library is incomplete and i need domonic

byteface commented 1 year ago

hi @nacho00112 . apologies I've been a little busy. Which feature in particular are you interested in?

nacho00112 commented 1 year ago

hi @nacho00112 . apologies I've been a little busy. Which feature in particular are you interested in?

I tried domonifying the google.com html source and it didn't worked