[Python-modules-commits] [yattag] 01/04: Import yattag_1.7.2.orig.tar.gz
Sandro Tosi
morph at moszumanska.debian.org
Sat Dec 10 23:33:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
morph pushed a commit to branch master
in repository yattag.
commit cda93644013fad08ec8358e8497dd7d7779177e4
Author: Sandro Tosi <morph at debian.org>
Date: Sat Dec 10 18:28:41 2016 -0500
Import yattag_1.7.2.orig.tar.gz
---
PKG-INFO | 3 ++-
setup.py | 3 ++-
test/tests_simpledoc.py | 16 +++++++++++++-
yattag/__init__.py | 2 +-
yattag/doc.py | 35 ++++++++++++++-----------------
yattag/simpledoc.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-
6 files changed, 90 insertions(+), 24 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index a0360bf..da15587 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: yattag
-Version: 1.6.0
+Version: 1.7.2
Summary: Generate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.
Home-page: http://www.yattag.org
Author: Benjamin Le Forestier
@@ -117,6 +117,7 @@ Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/setup.py b/setup.py
index 0f04946..04567f7 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open('README.rst') as fd:
setup(
name='yattag',
- version='1.6.0',
+ version='1.7.2',
packages=['yattag'],
author = 'Benjamin Le Forestier',
author_email = 'benjamin at leforestier.org',
@@ -29,6 +29,7 @@ Can fill HTML forms with default values and error messages.""",
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules',
diff --git a/test/tests_simpledoc.py b/test/tests_simpledoc.py
index b145c6c..f9905d4 100644
--- a/test/tests_simpledoc.py
+++ b/test/tests_simpledoc.py
@@ -98,6 +98,20 @@ class TestSimpledoc(unittest.TestCase):
doc.getvalue(),
'<![CDATA[Some data ]]]]><![CDATA[><script src="malicious.js">]]>'
)
-
+
+ def test_line(self):
+ doc, tag, text, line = SimpleDoc().ttl()
+ line('h1', 'Some interesting links')
+ line('a', "Python's strftime directives", href="http://strftime.org"),
+ line('a', "Example of good UX for a homepage", href="http://zombo.com")
+ self.assertEqual(
+ doc.getvalue(),
+ (
+ '<h1>Some interesting links</h1>'
+ '<a href="http://strftime.org">Python\'s strftime directives</a>'
+ '<a href="http://zombo.com">Example of good UX for a homepage</a>'
+ )
+ )
+
if __name__ == '__main__':
unittest.main()
diff --git a/yattag/__init__.py b/yattag/__init__.py
index 424a057..9d1d720 100644
--- a/yattag/__init__.py
+++ b/yattag/__init__.py
@@ -55,7 +55,7 @@ Full tutorial on yattag.org_
"""
__author__ = "Benjamin Le Forestier (benjamin at leforestier.org)"
-__version__ = '1.6.0'
+__version__ = '1.7.2'
from yattag.simpledoc import SimpleDoc
from yattag.doc import Doc
diff --git a/yattag/doc.py b/yattag/doc.py
index fd09f50..f30fd20 100644
--- a/yattag/doc.py
+++ b/yattag/doc.py
@@ -23,10 +23,7 @@ class SimpleInput(object):
attrs = dict(self.attrs)
error = errors and self.name in errors
if error:
- if 'class' in attrs:
- attrs['class'] = attrs['class'] + " error"
- else:
- attrs['class'] = "error"
+ _add_class(attrs, 'error')
lst.append(error_wrapper[0])
lst.append(html_escape(errors[self.name]))
lst.append(error_wrapper[1])
@@ -54,13 +51,11 @@ class CheckableInput(object):
lst = []
attrs = dict(self.attrs)
if self.rank == 0:
- if errors:
- if self.name in errors:
- lst.append(error_wrapper[0])
- lst.append(html_escape(errors[self.name]))
- lst.append(error_wrapper[1])
- if 'class' not in attrs:
- attrs['class'] = "error"
+ if errors and self.name in errors:
+ lst.append(error_wrapper[0])
+ lst.append(html_escape(errors[self.name]))
+ lst.append(error_wrapper[1])
+ _add_class(attrs, 'error')
if self.name in defaults and 'value' in self.attrs and defaults[self.name] == self.attrs['value']:
attrs['checked'] = 'checked'
@@ -106,13 +101,11 @@ class ContainerTag(object):
def render(self, defaults, errors, error_wrapper, inner_content = ''):
lst = []
attrs = dict(self.attrs)
- if errors:
- if self.name in errors:
- lst.append(error_wrapper[0])
- lst.append(html_escape(errors[self.name]))
- lst.append(error_wrapper[1])
- if 'class' not in attrs:
- attrs['class'] = "error"
+ if errors and self.name in errors:
+ lst.append(error_wrapper[0])
+ lst.append(html_escape(errors[self.name]))
+ lst.append(error_wrapper[1])
+ _add_class(attrs, 'error')
attrs['name'] = self.name
lst.append('<%s %s>' % (self.__class__.tag_name, dict_to_attrs(attrs)))
@@ -429,4 +422,8 @@ class Doc(SimpleDoc):
dict((name, self.errors[name]) for name in self.errors if name not in self._fields)
)
return ''.join(self.result)
-
+
+def _add_class(dct, klass):
+ classes = dct.get('class', '').split()
+ if klass not in classes:
+ dct['class'] = ' '.join(classes + [klass])
diff --git a/yattag/simpledoc.py b/yattag/simpledoc.py
index 6ae307f..28608ba 100644
--- a/yattag/simpledoc.py
+++ b/yattag/simpledoc.py
@@ -100,6 +100,38 @@ class SimpleDoc(object):
"""
for strg in strgs:
self._append(html_escape(strg))
+
+ def line(self, tag_name, text_content, *args, **kwargs):
+ """
+ Shortcut to write tag nodes that contain only text.
+ For example, in order to obtain::
+
+ <h1>The 7 secrets of catchy titles</h1>
+
+ you would write::
+
+ line('h1', 'The 7 secrets of catchy titles')
+
+ which is just a shortcut for::
+
+ with tag('h1'):
+ text('The 7 secrets of catchy titles')
+
+ The first argument is the tag name, the second argument
+ is the text content of the node.
+ The optional arguments after that are interpreted as xml/html
+ attributes. in the same way as with the `tag` method.
+
+ Example::
+
+ line('a', 'Who are we?', href = '/about-us.html')
+
+ produces::
+
+ <a href="/about-us.html">Who are we?</a>
+ """
+ with self.tag(tag_name, *args, **kwargs):
+ self.text(text_content)
def asis(self, *strgs):
"""
@@ -172,7 +204,7 @@ class SimpleDoc(object):
doc.stag('img', src = '/salmon-plays-piano.jpg')
# appends <img src="/salmon-plays-piano.jpg /> to the document
"""
- if kwargs:
+ if args or kwargs:
self._append("<%s %s />" % (
tag_name,
dict_to_attrs(_attributes(args, kwargs)),
@@ -221,6 +253,27 @@ class SimpleDoc(object):
"""
return self, self.tag, self.text
+
+ def ttl(self):
+ """
+ returns a quadruplet composed of::
+ . the document itself
+ . its tag method
+ . its text method
+ . its line method
+
+ Example::
+
+ doc, tag, text, line = SimpleDoc().ttl()
+
+ with tag('ul', id='grocery-list'):
+ line('li', 'Tomato sauce', klass="priority")
+ line('li', 'Salt')
+ line('li', 'Pepper')
+
+ print(doc.getvalue())
+ """
+ return self, self.tag, self.text, self.line
def add_class(self, *classes):
"""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/yattag.git
More information about the Python-modules-commits
mailing list