domonic icon indicating copy to clipboard operation
domonic copied to clipboard

import domonic.html

Open piotrm0 opened this issue 3 years ago • 8 comments

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.

piotrm0 avatar Apr 02 '22 21:04 piotrm0

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 avatar Apr 03 '22 13:04 byteface

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.

byteface avatar Apr 03 '22 14:04 byteface

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.

piotrm0 avatar Apr 04 '22 19:04 piotrm0

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

byteface avatar Apr 05 '22 00:04 byteface

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

nacho00112 avatar Jul 26 '23 12:07 nacho00112

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

byteface avatar Aug 03 '23 08:08 byteface

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

nacho00112 avatar Aug 03 '23 17:08 nacho00112