root/livinglogic.python.xist/src/ll/xist/ns/ul4.py @ 4476:5a746d3c5fce

Revision 4476:5a746d3c5fce, 3.6 KB (checked in by Walter Doerwald <walter@…>, 8 years ago)

More None markup.

Line 
1# -*- coding: utf-8 -*-
2
3## Copyright 2009-2011 by LivingLogic AG, Bayreuth/Germany
4## Copyright 2009-2011 by Walter Dörwald
5##
6## All Rights Reserved
7##
8## See ll/__init__.py for the license
9
10
11from ll import misc
12from ll.xist import xsc
13
14
15###
16### Processing instructions for output
17###
18
19class print_(xsc.ProcInst):
20    """
21    Prints the expression in the processing instruction data.
22    """
23    xmlname = "print"
24
25
26class printx(xsc.ProcInst):
27    """
28    Prints the expression in the processing instruction data and escapes
29    the characters ``&``, ``<``, ``>``, ``'`` and ``"``.
30    """
31
32
33###
34### Processing instruction for statements
35###
36
37class code(xsc.ProcInst):
38    """
39    A :class:`code` processing instruction contains a statement (such as an
40    assignment or augmented assignment).
41    """
42
43
44###
45### Processing instruction for calling sub-templates
46###
47
48class render(xsc.ProcInst):
49    """
50    A :class:`render` processing instruction calls another template.
51    """
52
53
54###
55### Processing instructions for conditional attributes
56###
57
58class attr_ifnn(xsc.AttrProcInst):
59    """
60    Conditional attribute: If this PI is used as the first in an attribute, it's
61    value is treated as an expression. If this expression is not ``None``
62    it is output as the value of the attribute, otherwise the attribute itself
63    will be skipped.
64    """
65
66    def publishattr(self, publisher, attr):
67        yield publisher.encode(u'<?if not isnone({content})?> {name}="<?printx {content}?>"<?end if?>'.format(content=self.content, name=attr._publishname(publisher)))
68
69    def publishboolattr(self, publisher, attr):
70        name = attr._publishname(publisher)
71        yield publisher.encode(u"<?if not isnone({content})?> {name}".format(content=self.content, name=name))
72        if publisher.xhtml>0:
73            yield publisher.encode(u'="{name}"'.format(name=name))
74        yield publisher.encode(u'<?end if?>')
75
76
77class attr_if(xsc.AttrProcInst):
78    """
79    Conditional attribute: If this PI is used as the first in an attribute, it's
80    value is treated as an expression. If this expression is true, the attribute
81    will be output normally, otherwise the attribute itself will be skipped.
82    """
83
84    def publishattr(self, publisher, attr):
85        publisher.inattr += 1
86        yield publisher.encode(u'<?if {content}?> {name}="'.format(content=self.content, name=attr._publishname(publisher)))
87        publisher.pushtextfilter(misc.xmlescape_attr)
88        for part in attr._publishattrvalue(publisher):
89            yield part
90        publisher.poptextfilter()
91        yield publisher.encode(u'"<?end if?>')
92        publisher.inattr -= 1
93
94    def publishboolattr(self, publisher, attr):
95        name = attr._publishname(publisher)
96        yield publisher.encode(u"<?if {content}?> {name}".format(content=self.content, name=name))
97        if publisher.xhtml>0:
98            yield publisher.encode(u'="{name}"'.format(name=name))
99        yield publisher.encode(u'<?end if?>')
100
101
102###
103### Processing instructions for block structures (if/elif/else/for and def)
104###
105
106class if_(xsc.ProcInst):
107    xmlname = "if"
108    prettyindentbefore = 0
109    prettyindentafter = 1
110
111
112
113class elif_(xsc.ProcInst):
114    xmlname = "elif"
115    prettyindentbefore = -1
116    prettyindentafter = 1
117
118
119class else_(xsc.ProcInst):
120    xmlname = "else"
121    prettyindentbefore = -1
122    prettyindentafter = 1
123
124
125class end(xsc.ProcInst):
126    """
127    Ends an :class:`if_` or :class:`for_`. The PI value may be the type of the
128    block (either ``"if"``, ``"for"`` or ``"def"``). If the value is empty the
129    innermost block will be closed without any checks for the type of block.
130    """
131    prettyindentbefore = -1
132    prettyindentafter = 0
133
134
135class for_(xsc.ProcInst):
136    xmlname = "for"
137    prettyindentbefore = 0
138    prettyindentafter = 1
139
140
141class break_(xsc.ProcInst):
142    xmlname = "break"
143
144
145class continue_(xsc.ProcInst):
146    xmlname = "continue"
147
148
149class def_(xsc.ProcInst):
150    xmlname = "def"
151    prettyindentbefore = 0
152    prettyindentafter = 1
Note: See TracBrowser for help on using the browser.