Changeset 4533:35aca9b50120 in livinglogic.python.xist for src/ll/xist/ns/ul4.py

Show
Ignore:
Timestamp:
08/09/11 17:40:31 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Tags:
rel-3-24
Message:

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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/ns/ul4.py

    r4476 r4533  
    5656### 
    5757 
    58 class attr_ifnn(xsc.AttrProcInst): 
     58class attr_if(xsc.AttrElement): 
    5959    """ 
    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. 
     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. 
    6465    """ 
    6566 
    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))) 
     67    class Attrs(xsc.Attrs): 
     68        class cond(xsc.TextAttr): required = True 
    6869 
    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)) 
     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 
    7474        yield publisher.encode(u'<?end if?>') 
    75  
    76  
    77 class 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     """ 
    8375 
    8476    def publishattr(self, publisher, attr): 
    8577        publisher.inattr += 1 
    86         yield publisher.encode(u'<?if {content}?> {name}="'.format(content=self.content, name=attr._publishname(publisher))) 
     78        yield publisher.encode(u'<?if {cond}?> {name}="'.format(cond=unicode(self.attrs.cond), name=attr._publishname(publisher))) 
    8779        publisher.pushtextfilter(misc.xmlescape_attr) 
    88         for part in attr._publishattrvalue(publisher): 
     80        for part in self.content.publish(publisher): 
    8981            yield part 
    9082        publisher.poptextfilter() 
     
    9486    def publishboolattr(self, publisher, attr): 
    9587        name = attr._publishname(publisher) 
    96         yield publisher.encode(u"<?if {content}?> {name}".format(content=self.content, name=name)) 
     88        yield publisher.encode(u'<?if {cond}?> {name}'.format(cond=unicode(self.attrs.cond), name=attr._publishname(publisher))) 
    9789        if publisher.xhtml>0: 
    9890            yield publisher.encode(u'="{name}"'.format(name=name))