Changeset 4533:35aca9b50120 in livinglogic.python.xist

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:
6 modified

Legend:

Unmodified
Added
Removed
  • MIGRATION.rst

    r4524 r4533  
     1Migrating to version 3.24 
     2========================= 
     3 
     4Changes to :mod:`ll.xist.ns.ul4` 
     5-------------------------------- 
     6 
     7*   :class:`ll.xist.ns.ul4.attr_if` is now an :class:`ll.xist.xsc.AttrElement` 
     8    subclass. Change your code from:: 
     9 
     10        html.div(id=(ul4.attr_if("foo"), "bar")) 
     11 
     12    to:: 
     13 
     14        html.div(id=ul4.attr_if("bar", cond="foo")) 
     15 
     16*   :class:`ll.xist.ns.ul4.attr_ifnn` has been removed. Replace it with the 
     17    equivalent :class:`attr_if` call. 
     18 
     19 
    120Migrating to version 3.23 
    221========================= 
  • NEWS.rst

    r4529 r4533  
     1Changes in 3.24 (released 08/09/2011) 
     2------------------------------------- 
     3 
     4*   The :class:`ProcInst` subclass :class:`ll.xist.xsc.AttrProcInst` has been 
     5    replaced with an :class:`Element` subclass :class:`ll.xist.xsc.AttrElement`. 
     6    Conditional handling of the attribute will be used, if the 
     7    :class:`AttrElement` instance is the only 
     8    child of the attribute. Outside of attributes the :class:`AttrElement` 
     9    instance will be published normally (via :meth:`publish`, which must be 
     10    implemented) 
     11 
     12*   :class:`ll.xist.ns.ul4.attr_if` is an :class:`ll.xist.xsc.AttrElement` 
     13    subclass now. The condition is in the ``cond`` attribute and the attribute 
     14    content is inside the element. Outside of an attribute :class:`attr_if` 
     15    will put a normal UL4 ``if`` condition around its content. 
     16 
     17*   :class:`ll.xist.ns.ul4.attr_ifnn` has been removed. 
     18 
     19 
    120Changes in 3.23.1 (released 07/28/2011) 
    221--------------------------------------- 
  • setup.py

    r4529 r4533  
    4949    to `Django's templating language`__. ``UL4`` templates are compiled to an 
    5050    internal bytecode format, which makes it possible to implement template 
    51     renderers in other languages and makes the template code "secure" (i.e. 
    52     template code can't open or delete files). 
     51    renderers in other languages (Java and Javascript are supported) and makes 
     52    the template code "secure" (i.e. template code can't open or delete files). 
    5353 
    5454    __ http://www.djangoproject.com/documentation/templates/ 
     
    228228args = dict( 
    229229    name="ll-xist", 
    230     version="3.23.1", 
     230    version="3.24", 
    231231    description="Extensible HTML/XML generator, cross-platform templating language, Oracle utilities and various other tools", 
    232232    long_description=description, 
  • 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)) 
  • src/ll/xist/xsc.py

    r4498 r4533  
    21222122 
    21232123 
    2124 class AttrProcInst(ProcInst): 
    2125     """ 
    2126     Special subclass of :class:`ProcInst`. 
    2127  
    2128     When an :class:`AttrProcInst` node is the first node in an attribute, it 
    2129     takes over publishing of the attribute (via the methods :meth:`publishattr` 
    2130     and :meth:`publishboolattr`). In all other cases the processing instruction 
    2131     disappears completely. 
    2132     """ 
    2133  
    2134     register = None 
    2135  
    2136     def publish(self, publisher): 
    2137         if False: 
    2138             yield "" 
    2139  
    2140     @misc.notimplemented 
    2141     def publishattr(self, publisher, attr): 
    2142         """ 
    2143         Publish the attribute :var:`attr` to the publisher :var:`publisher`. 
    2144         (Note that ``attr[0]`` is :var:`self`). 
    2145         """ 
    2146  
    2147     @misc.notimplemented 
    2148     def publishboolattr(self, publisher, attr): 
    2149         """ 
    2150         Publish the boolean attribute :var:`attr` to the publisher 
    2151         :var:`publisher`. (Note that ``attr[0]`` is :var:`self`). 
    2152         """ 
    2153  
    2154  
    21552124class Null(CharacterData): 
    21562125    """ 
     
    22872256        if publisher.validate: 
    22882257            self.checkvalid() 
    2289         if self and isinstance(self[0], AttrProcInst): 
     2258        if len(self)==1 and isinstance(self[0], AttrElement): 
    22902259            for part in self[0].publishattr(publisher, self): 
    22912260                yield part 
     
    23572326        if publisher.validate: 
    23582327            self.checkvalid() 
    2359         if self and isinstance(self[0], AttrProcInst): 
    2360             for part in self[0].publishboolattr(publisher, self): 
     2328        if len(self)==1 and isinstance(self[0], AttrElement): 
     2329            for part in self[0].publishboolattr(publisher): 
    23612330                yield part 
    23622331        else: 
     
    35043473            loc = "" 
    35053474        return "<{0.__class__.__module__}.{0.__fullname__} element object ({1}/{2}){3} at {4:#x}>".format(self, infoc, infoa, loc, id(self)) 
     3475 
     3476 
     3477class AttrElement(Element): 
     3478    """ 
     3479    Special subclass of :class:`Element`. 
     3480 
     3481    When an :class:`AttrElement` node is the only node in an attribute, it 
     3482    takes over publishing of the attribute (via the methods :meth:`publishattr` 
     3483    and :meth:`publishboolattr`). In all other cases publishing is done in the 
     3484    normal way (and must be overwritten with the :meth:`publish` method). 
     3485    """ 
     3486 
     3487    register = None 
     3488 
     3489    @misc.notimplemented 
     3490    def publish(self, publisher): 
     3491        """ 
     3492        Publish ``self`` to the publisher :var:`publisher` (outside of any 
     3493        attribute) 
     3494        """ 
     3495 
     3496    @misc.notimplemented 
     3497    def publishattr(self, publisher, attr): 
     3498        """ 
     3499        Publish the attribute :var:`attr` to the publisher :var:`publisher`. 
     3500        """ 
     3501 
     3502    @misc.notimplemented 
     3503    def publishboolattr(self, publisher, attr): 
     3504        """ 
     3505        Publish the boolean attribute :var:`attr` to the publisher 
     3506        """ 
    35063507 
    35073508 
  • test/test_ul4.py

    r4524 r4533  
    1717 
    1818from ll import ul4c, color, misc 
     19from ll.xist.ns import html, ul4 
    1920 
    2021 
     
    19271928    t = universaltemplate() 
    19281929    t.javasource() 
     1930 
     1931 
     1932@py.test.mark.ul4 
     1933def test_attr_if(): 
     1934    cond = ul4.attr_if(html.a("gu'\"rk"), cond="cond") 
     1935 
     1936    s = html.div(class_=cond).conv().string() 
     1937    for r in all_renderers: 
     1938        yield eq, u'<div></div>', r(s, cond=False) 
     1939        yield eq, u'''<div class="gu'&quot;rk"></div>''', r(s, cond=True) 
     1940 
     1941    s = html.div(class_=(cond, "hurz")).conv().string() 
     1942    for r in all_renderers: 
     1943        yield eq, u'<div class="hurz"></div>', r(s, cond=False) 
     1944        yield eq, u'''<div class="gu'&quot;rkhurz"></div>''', r(s, cond=True) 
     1945 
     1946    s = cond.conv().string() 
     1947    for r in all_renderers: 
     1948        yield eq, u'', r(s, cond=False) 
     1949        yield eq, u'''<a>gu'"rk</a>''', r(s, cond=True)