-
Notifications
You must be signed in to change notification settings - Fork 119
Add support for HTMX and Unpoly tags #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add support for HTMX and Unpoly tags #201
Conversation
|
Have a look also in this pull request. |
|
In the past I have not accepted any 3rd-party integrations (and still don't wish to in the main library), but would like to find a middle ground. Please see #210 if you'd like to continue this PR |
| # A list of attribute prefixes which mean that underscores should be converted to dashes | ||
| # This allows attributes like data_username or hx_post become data-username and hx-post | ||
| # hx_ prefix is for HTMX and up_ prefix is for Unpoly | ||
| SPECIAL_PREFIX_LIST = ('data_', 'aria_', 'up_', 'hx_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: move this to dominate.ATTR_PREFIXES and add a function to modify it:
ATTR_PREFIXES = ['data_', 'aria_']
def add_attr_prefix(*args: tuple[str]):
ATTR_PREFIXES.extend(args)Then, a user who wants to use htmx or unpoly does dominate.add_attr_prefix('hx_', 'up_').
This provides flexibility without the need to support a 3rd party library by name.
Global settings are often discouraged but, in this case, it makes sense IMO since you aren't always guaranteed to have a top level object to configure. The Python stdlib also has top-level global configs for this in a number of places where they make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maye DASHED_ATTRS is the right name for this.
| ''' | ||
| return text(s, escape=False) | ||
|
|
||
| class novalue: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend changing this to set = () so you can do:
tags.a('foo', up_instant=set)IMO, there is no need for it to be a class and be instantiated every time.
Alternatively or additionally, the html spec refers to such attributes as boolean attributes. So, IMO, the attribute handling code could just look for is True and, if that's the case, set the attr name without the value.
tags.a('foo', up_instant=True)
Personally, I'd just go with supporting True, document it, and and not add the special sentinel value for simplicity sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realize boolean attrs are already supported.
|
@Knio this is a great library, thanks for all the leg work you have done to get it to this point. I didn't realize until I started using it how much I've been longing to get away from Jinja templates and raw HTML.
I add some comments to the PR that I think, with minor changes, would make it a good middle ground. Almost no additional burden on dominate from a support perspective but all the flexibility needed to support any library that uses custom attribute prefixes for functionality. |
This PR adds the necessary support to render HTML for the Unpoly and HTMX libraries.
The biggest change is adding
util.novaluewhich can be set as the attribute of a class to make it render in HTML without a value.It also adds
hx_andup_as prefixes for attributes to be converted from underscores to dashes.