leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.
333 stars 31 forks source link

Add data attribute method to simpledoc #44

Closed PranavMathur closed 5 years ago

PranavMathur commented 5 years ago

This PR adds a simpledoc.data method that adds HTML5 data attributes to the current tag. The method is called in the same way as simpledoc.attr. It takes keyword arguments or (key, value) pairs, prefixes each key with "data-", then updates the current tag with the new attributes.

The commit also includes documentation on the method, adapted from the documentation of simpledoc.attr

PranavMathur commented 5 years ago

That makes sense. Would the phrase for (key, value) in kwargs work in any of the supported versions of Python? I think it has to iterate over kwargs.items() in order to yield kv-pairs. I'll make some changes and be sure to test in older versions while I'm at it. Thank you!

leforestier commented 5 years ago

You're right, it's kwargs.items().

leforestier commented 5 years ago

It's on pypi now. Thanks for your contribution!