Skip to content
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

Add custom stimulus tag to make it easier to create stimuli in django… #60

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

JulianFeinauer
Copy link
Contributor

… templates.

Type of PR (feature, enhancement, bug fix, etc.)

feature

Description

See #59

Why should this be added

Makes it easier to use.

Checklist

  • Tests are passing
  • Documentation has been added or amended for this feature / update

Copy link
Owner

@jonathan-s jonathan-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm especially interested in the validation for this! It would also be great if you could write some unittests for this, since this will be user facing. This such a small component that unittests are perfectly suitable for this.

And thanks for taking the time for this!

"""
# TODO Validate that the reflex is present and can be handled
data = ' '.join([f'data-{key}="{val}"' for key, val in kwargs.items()])
return mark_safe(f'data-reflex="click->{reflex}" {data}')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments here

  • You can trigger a reflex on a lot of different actions besides click. This is one example on the extreme end. "cable-ready:after-morph@document->chat#scroll" (see https://sockpuppet.argpar.se/patterns#capture-all-dom-update-events).
  • Do we need mark_safe here? If the developer for whatever reason decides to put user data in this template tag and that user data happens to be a script. I'd rather see some broken html than open it up to a XSS attack.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I think having click as a 'default' action is perfectly fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathan-s these are both cood comments. I used click as its the most "natural" one. But agree that it would be cool to have another method to enter that.

To your seccond command.. we need it at least for the double-ticks (") otherwise they would be escaped. But I agree that it would be better to "safify" the value parts. Do you agree with that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added several tests now. Do you agree with them?

sockpuppet/templatetags/sockpuppet.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants