[Checkins] SVN: z3c.pt/trunk/ Configure boolean HTML attributes.
Malthe Borch
mborch at gmail.com
Mon Aug 22 09:56:38 EDT 2011
Log message for revision 122656:
Configure boolean HTML attributes.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/setup.py
U z3c.pt/trunk/src/z3c/pt/pagetemplate.py
A z3c.pt/trunk/src/z3c/pt/tests/boolean.pt
U z3c.pt/trunk/src/z3c/pt/tests/false.pt
U z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2011-08-20 17:19:54 UTC (rev 122655)
+++ z3c.pt/trunk/CHANGES.txt 2011-08-22 13:56:37 UTC (rev 122656)
@@ -1,6 +1,14 @@
Changelog
=========
+In next release ...
+
+- Configure HTML boolean attributes (in HTML-mode only)::
+
+ "compact", "nowrap", "ismap", "declare", "noshade",
+ "checked", "disabled", "readonly", "multiple", "selected",
+ "noresize", "defer"
+
2.1.2 (2011-08-19)
~~~~~~~~~~~~~~~~~~
Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py 2011-08-20 17:19:54 UTC (rev 122655)
+++ z3c.pt/trunk/setup.py 2011-08-22 13:56:37 UTC (rev 122656)
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys
-version = '2.1.2'
+version = '2.1.3-dev'
install_requires = [
'setuptools',
@@ -10,7 +10,7 @@
'zope.i18n >= 3.5',
'zope.traversing',
'zope.contentprovider',
- 'Chameleon >= 2.3.7',
+ 'Chameleon >= 2.4.0',
]
setup(name='z3c.pt',
Modified: z3c.pt/trunk/src/z3c/pt/pagetemplate.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2011-08-20 17:19:54 UTC (rev 122655)
+++ z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2011-08-22 13:56:37 UTC (rev 122656)
@@ -21,6 +21,18 @@
_marker = object()
+BOOLEAN_HTML_ATTRS = frozenset([
+ # List of Boolean attributes in HTML that should be rendered in
+ # minimized form (e.g. <img ismap> rather than <img ismap="">)
+ # From http://www.w3.org/TR/xhtml1/#guidelines (C.10)
+ # TODO: The problem with this is that this is not valid XML and
+ # can't be parsed back!
+ "compact", "nowrap", "ismap", "declare", "noshade", "checked",
+ "disabled", "readonly", "multiple", "selected", "noresize",
+ "defer"
+])
+
+
class OpaqueDict(dict):
def __new__(cls, dictionary):
inst = dict.__new__(cls)
@@ -70,6 +82,13 @@
literal_false = True
@property
+ def boolean_attributes(self):
+ if self.content_type == 'text/xml':
+ return set()
+
+ return BOOLEAN_HTML_ATTRS
+
+ @property
def builtins(self):
builtins = {
'nothing': None,
Added: z3c.pt/trunk/src/z3c/pt/tests/boolean.pt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/boolean.pt (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/tests/boolean.pt 2011-08-22 13:56:37 UTC (rev 122656)
@@ -0,0 +1,4 @@
+<form>
+ <input type="input" tal:attributes="checked False" />
+ <input type="input" tal:attributes="checked True" />
+</form>
\ No newline at end of file
Modified: z3c.pt/trunk/src/z3c/pt/tests/false.pt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/false.pt 2011-08-20 17:19:54 UTC (rev 122655)
+++ z3c.pt/trunk/src/z3c/pt/tests/false.pt 2011-08-22 13:56:37 UTC (rev 122656)
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
<form>
<input type="input" tal:attributes="checked False" />
</form>
\ No newline at end of file
Modified: z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_templates.py 2011-08-20 17:19:54 UTC (rev 122655)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_templates.py 2011-08-22 13:56:37 UTC (rev 122656)
@@ -29,12 +29,19 @@
result = template(callable=dont_call)
self.failUnless('ok' in result)
- def test_false(self):
+ def test_false_attribute(self):
from z3c.pt.pagetemplate import PageTemplateFile
template = PageTemplateFile("false.pt")
result = template()
self.failUnless('False' in result)
+ def test_boolean_attribute(self):
+ from z3c.pt.pagetemplate import PageTemplateFile
+ template = PageTemplateFile("boolean.pt")
+ result = template()
+ self.failIf('False' in result)
+ self.failUnless('checked="checked"' in result)
+
def test_path(self):
from z3c.pt.pagetemplate import PageTemplateFile
template = PageTemplateFile("path.pt")
More information about the checkins
mailing list