leforestier / yattag

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

Use 'phor' to give tags the 'for' attribute. #76

Closed buzzingwires closed 1 year ago

buzzingwires commented 1 year ago

'for' is another reserved keyword like 'class', and will not work as a keyword parameter for 'tag()', 'stag()', etc'. Allow 'phor' to be passed to specify the 'for' attribute, instead. Additionally, the new structure of the code will allow more substitutions to be easily added by placing entries in the dict '_attr_key_translations' in 'simpledoc.py'

leforestier commented 1 year ago

Thanks for your contribution, but I think it's better if people use (key, value) pairs in cases like this. For example:

with tag("label", ("for", "shampoo")):
    text("hello")

I only keep the klass shortcut to avoid breaking people's code, but if I were to design this library today I wouldn't add it.

buzzingwires commented 1 year ago

Understood! Firstly, my apologies for not reading the main documentation more closely, since it already states this approach should be used for reserved keywords other than 'class', and thank you for clarifying your design paradigm. I agree the key/value notation is ultimately a lot more orthogonal.