root/livinglogic.python.xist/src/ll/xist/ns/ul4.py @ 4533:35aca9b50120

Revision 4533:35aca9b50120, 3.3 KB (checked in by Walter Doerwald <walter@…>, 8 years ago)

Replace ll.xist.xsc.AttrProcInst? with ll.xist.xsc.AttrElement?.

This makes it possible to have a useful output for the new element outside of
attributes.

Make ll.xist.ns.ul4.attr_if an AttrElement? subclass.

Remove ll.xist.ns.ul4.attr_ifnn.

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_if(xsc.AttrElement):
59    """
60    Conditional attribute: The ``cond`` attribute is a expression. If this
61    expression is true, the attribute will be output normally (with the elements
62    content as content (except for boolean attributes)), otherwise the attribute
63    itself will be skipped. Outside of an attribute this will produce a normal
64    UL4 ``if`` around its content.
65    """
66
67    class Attrs(xsc.Attrs):
68        class cond(xsc.TextAttr): required = True
69
70    def publish(self, publisher):
71        yield publisher.encode(u'<?if {cond}?>'.format(cond=unicode(self.attrs.cond)))
72        for part in self.content.publish(publisher):
73            yield part
74        yield publisher.encode(u'<?end if?>')
75
76    def publishattr(self, publisher, attr):
77        publisher.inattr += 1
78        yield publisher.encode(u'<?if {cond}?> {name}="'.format(cond=unicode(self.attrs.cond), name=attr._publishname(publisher)))
79        publisher.pushtextfilter(misc.xmlescape_attr)
80        for part in self.content.publish(publisher):
81            yield part
82        publisher.poptextfilter()
83        yield publisher.encode(u'"<?end if?>')
84        publisher.inattr -= 1
85
86    def publishboolattr(self, publisher, attr):
87        name = attr._publishname(publisher)
88        yield publisher.encode(u'<?if {cond}?> {name}'.format(cond=unicode(self.attrs.cond), name=attr._publishname(publisher)))
89        if publisher.xhtml>0:
90            yield publisher.encode(u'="{name}"'.format(name=name))
91        yield publisher.encode(u'<?end if?>')
92
93
94###
95### Processing instructions for block structures (if/elif/else/for and def)
96###
97
98class if_(xsc.ProcInst):
99    xmlname = "if"
100    prettyindentbefore = 0
101    prettyindentafter = 1
102
103
104
105class elif_(xsc.ProcInst):
106    xmlname = "elif"
107    prettyindentbefore = -1
108    prettyindentafter = 1
109
110
111class else_(xsc.ProcInst):
112    xmlname = "else"
113    prettyindentbefore = -1
114    prettyindentafter = 1
115
116
117class end(xsc.ProcInst):
118    """
119    Ends an :class:`if_` or :class:`for_`. The PI value may be the type of the
120    block (either ``"if"``, ``"for"`` or ``"def"``). If the value is empty the
121    innermost block will be closed without any checks for the type of block.
122    """
123    prettyindentbefore = -1
124    prettyindentafter = 0
125
126
127class for_(xsc.ProcInst):
128    xmlname = "for"
129    prettyindentbefore = 0
130    prettyindentafter = 1
131
132
133class break_(xsc.ProcInst):
134    xmlname = "break"
135
136
137class continue_(xsc.ProcInst):
138    xmlname = "continue"
139
140
141class def_(xsc.ProcInst):
142    xmlname = "def"
143    prettyindentbefore = 0
144    prettyindentafter = 1
Note: See TracBrowser for help on using the browser.