Mercurial > genshi > genshi-test
comparison genshi/template/text.py @ 605:bc5faca93699
Text templates now default to rendering as plain text; it is no longer necessary to explicitly specify the "text" method to the `render()` or `serialize()` method of the generated markup stream. See tickets #62 and #118.
author | cmlenz |
---|---|
date | Mon, 27 Aug 2007 19:04:20 +0000 |
parents | 7145e4eba2ec |
children | 9ada030ad986 |
comparison
equal
deleted
inserted
replaced
604:6d1fa718794f | 605:bc5faca93699 |
---|---|
56 ... We have the following items for you: | 56 ... We have the following items for you: |
57 ... {% for item in items %} | 57 ... {% for item in items %} |
58 ... * ${'Item %d' % item} | 58 ... * ${'Item %d' % item} |
59 ... {% end %} | 59 ... {% end %} |
60 ... ''') | 60 ... ''') |
61 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render('text') | 61 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render() |
62 Dear Joe, | 62 Dear Joe, |
63 <BLANKLINE> | 63 <BLANKLINE> |
64 <BLANKLINE> | 64 <BLANKLINE> |
65 We have the following items for you: | 65 We have the following items for you: |
66 <BLANKLINE> | 66 <BLANKLINE> |
81 ... We have the following items for you: | 81 ... We have the following items for you: |
82 ... {% for item in items %}\ | 82 ... {% for item in items %}\ |
83 ... * $item | 83 ... * $item |
84 ... {% end %}\ | 84 ... {% end %}\ |
85 ... ''') | 85 ... ''') |
86 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render('text') | 86 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render() |
87 Dear Joe, | 87 Dear Joe, |
88 <BLANKLINE> | 88 <BLANKLINE> |
89 We have the following items for you: | 89 We have the following items for you: |
90 * 1 | 90 * 1 |
91 * 2 | 91 * 2 |
101 ... We have the following items for you: | 101 ... We have the following items for you: |
102 ... {% for item in items %}\ | 102 ... {% for item in items %}\ |
103 ... * $item | 103 ... * $item |
104 ... {% end %}\ | 104 ... {% end %}\ |
105 ... ''') | 105 ... ''') |
106 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render('text') | 106 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render() |
107 Dear Joe, | 107 Dear Joe, |
108 <BLANKLINE> | 108 <BLANKLINE> |
109 {# This is a comment #} | 109 {# This is a comment #} |
110 We have the following items for you: | 110 We have the following items for you: |
111 * 1 | 111 * 1 |
120 ('otherwise', OtherwiseDirective), | 120 ('otherwise', OtherwiseDirective), |
121 ('for', ForDirective), | 121 ('for', ForDirective), |
122 ('if', IfDirective), | 122 ('if', IfDirective), |
123 ('choose', ChooseDirective), | 123 ('choose', ChooseDirective), |
124 ('with', WithDirective)] | 124 ('with', WithDirective)] |
125 serializer = 'text' | |
125 | 126 |
126 _DIRECTIVE_RE = r'((?<!\\)%s\s*(\w+)\s*(.*?)\s*%s|(?<!\\)%s.*?%s)' | 127 _DIRECTIVE_RE = r'((?<!\\)%s\s*(\w+)\s*(.*?)\s*%s|(?<!\\)%s.*?%s)' |
127 _ESCAPE_RE = r'\\\n|\\(\\)|\\(%s)|\\(%s)' | 128 _ESCAPE_RE = r'\\\n|\\(\\)|\\(%s)|\\(%s)' |
128 | 129 |
129 def __init__(self, source, basedir=None, filename=None, loader=None, | 130 def __init__(self, source, basedir=None, filename=None, loader=None, |
225 ... * $item | 226 ... * $item |
226 ... #end | 227 ... #end |
227 ... | 228 ... |
228 ... All the best, | 229 ... All the best, |
229 ... Foobar''') | 230 ... Foobar''') |
230 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render('text') | 231 >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render() |
231 Dear Joe, | 232 Dear Joe, |
232 <BLANKLINE> | 233 <BLANKLINE> |
233 We have the following items for you: | 234 We have the following items for you: |
234 * 1 | 235 * 1 |
235 * 2 | 236 * 2 |
243 ('otherwise', OtherwiseDirective), | 244 ('otherwise', OtherwiseDirective), |
244 ('for', ForDirective), | 245 ('for', ForDirective), |
245 ('if', IfDirective), | 246 ('if', IfDirective), |
246 ('choose', ChooseDirective), | 247 ('choose', ChooseDirective), |
247 ('with', WithDirective)] | 248 ('with', WithDirective)] |
249 serializer = 'text' | |
248 | 250 |
249 _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' | 251 _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' |
250 r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', | 252 r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', |
251 re.MULTILINE) | 253 re.MULTILINE) |
252 | 254 |