-
Notifications
You must be signed in to change notification settings - Fork 64
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
Boolean attributes ($-expression and dynamic) #382
Conversation
09a39b0
to
8b3ddc2
Compare
Pull Request Test Coverage Report for Build 6009710511
💛 - Coveralls |
8b3ddc2
to
442933a
Compare
@mcdonc this should work correctly now – even for cases like an empty set or other non-true value.
I have added some tests to showcase the new behavior. |
442933a
to
d5db293
Compare
1. For a boolean attribute, if an $-expression evaluates to a false value (i.e., "not <expression>"), no text is omitted. 2. If the attribute value is the empty string, the attribute name is printed, otherwise the attribute is dropped. 3. Dynamic attributes are easier, because they're not using interpolation.
d5db293
to
76ccbed
Compare
Thanks for this work! I don't quite understand why |
@mcdonc it works for me if I add the following test case: --- a/src/chameleon/tests/test_templates.py
+++ b/src/chameleon/tests/test_templates.py
@@ -579,6 +579,7 @@ class ZopePageTemplatesTest(RenderTestCase):
'<input type="input" checked="${True}" />',
'<input type="input" checked="${False}" />',
'<input type="input" checked="${[]}" />',
+ '<input type="input" checked="${\'\'}" />',
'<input type="input" checked="checked" tal:attributes="checked default" />', # noqa: E501 line too long
)),
boolean_attributes={
@@ -600,6 +601,7 @@ class ZopePageTemplatesTest(RenderTestCase):
'<input type="input" checked="checked" />',
'<input type="input" />',
'<input type="input" />',
+ '<input type="input" />',
'<input type="input" checked="checked" />',
)),
"Output mismatch\n" + template.source |
Oh geez, I forgot the backslashes when adding the same test. Thanks! |
While handling boolean attributes (previously a configuration known as literal false – or rather the opposite of that) previously supported $-expressions such as
checked="${some_condition}"
, this behavior was accidentally changed in 3.8.0.This has now been fixed.
Additionally, boolean attributes are now respected for dynamic attributes.
This closes issue #381.