Changeset 140

Show
Ignore:
Timestamp:
04/15/10 16:13:14
Author:
johnny
Message:

Fixed bug in t:replace of non-node items, fixed py.test 1.2 support, fixed
some issues in setup, removed apigen (project is dead, hopefully new one soon).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/convert.py

    r138 r140  
    1 from templess import (nodebase, elnode, textnode, commentnode, cdatanode, 
    2                       templessnode, template) 
     1from templess import ( 
     2    nodebase, elnode, textnode, commentnode, cdatanode, 
     3    templessnode, template) 
    34import util 
    45 
     
    411412                        retnode, node.charset) 
    412413                if doreplace: 
    413                     for child in retnode: 
     414                    children = list(retnode.children) 
     415                    for child in children: 
     416                        # avoid converting text nodes more than once 
     417                        if (isinstance(child, textnode) and 
     418                                child != children[-1]): 
     419                            continue 
    414420                        for s in self._generate_node(child, context, html): 
    415421                            yield s 
  • trunk/doc/CHERRYPY.txt

    r96 r140  
    5050 
    5151.. _`CherryPy`: http://www.cherrypy.org 
    52  
  • trunk/doc/INSTALL.txt

    r108 r140  
    3333johnny@johnnydebris.net (until I have a mailinglist set up, please check the 
    3434project pages to see if a mailinglist is available before sending me emails). 
    35  
  • trunk/setup.py

    r115 r140  
    11from setuptools import setup, find_packages 
     2import os 
    23 
    3 version =  open('version.txt').read().strip(
    4  
    5 long_description = open('doc/README.txt').read() 
     4here = os.path.dirname(__file__
     5version =  open(os.path.join(here, 'version.txt')).read().strip() 
     6long_description = open(os.path.join(here, 'doc/README.txt')).read() 
    67 
    78setup(name='templess', 
     
    3233      """, 
    3334      ) 
    34  
  • trunk/test/oneshot.py

    r102 r140  
    88    import templess 
    99 
    10 here = py.magic.autopath().dirpath() 
     10here = py.path.local(__file__).dirpath() 
    1111 
    1212includeel = templess.xmlstring(u'<div>foo</div>') 
     
    4040 
    4141def main(): 
    42     t = (py.magic.autopath().dirpath() / 
    43                 'templates/testtemplate.html').open() 
     42    t = (here / 'templates/testtemplate.html').open() 
    4443    template = templess.template(t) 
    4544    rendered = template.unicode(context) 
  • trunk/test/test_nanosax.py

    r96 r140  
    11import py 
    2 here = py.magic.autopath().dirpath() 
     2here = py.path.local(__file__).dirpath() 
    33py.std.sys.path.append(here.dirpath().strpath) 
    44 
  • trunk/test/test_templess.py

    r138 r140  
    11import py 
    2 here = py.magic.autopath().dirpath() 
     2here = py.path.local(__file__).dirpath() 
    33py.std.sys.path.append(str(here.dirpath())) 
    44 
     
    160160 
    161161def test_attr_remove_xmlns(): 
    162     py.test.skip('done by parser nowadays - write test there') 
    163     node = templessnode('foo', {'xmlns:t': 'foo'}, None, 't') 
     162    #py.test.skip('done by parser nowadays - write test there') 
     163    node = parse_from_xml( 
     164        '<foo xmlns:t="http://johnnydebris.net/xmlns/templess" />', 'utf-8') 
    164165    s = xmlserializer(node) 
    165166    s.convert({}) 
     
    168169def test_attr_remove_xmlns_leave_other(): 
    169170    node = templessnode('foo', {'xmlns:q': 'foo'}, None, {}) 
     171    node = parse_from_xml( 
     172        '<foo xmlns:t="http://johnnydebris.net/xmlns/templess" ' 
     173        'xmlns:q="foo" />', 'utf-8') 
    170174    s = xmlserializer(node) 
    171175    s.convert({}) 
     
    444448    assert s == '<foo><bar>1</bar><bar>2</bar>34</foo>' 
    445449    assert s == s2 
     450 
     451def test_double_replace_textnode(): 
     452    t = templess.template( 
     453        '<foo xmlns:t="http://johnnydebris.net/xmlns/templess">' 
     454        '<bar t:content="bar"><t:tag t:replace="baz" /> ' 
     455        '<t:tag t:replace="qux" /></bar></foo>') 
     456    g = xmlgenerator(t) 
     457    s = ''.join(g.convert_generate({'bar': [{'baz': 1, 'qux': 2}]})) 
     458    assert s == '<foo><bar>1 2</bar></foo>' 
     459 
     460def test_double_replace_elnode(): 
     461    t = templess.template( 
     462        '<foo xmlns:t="http://johnnydebris.net/xmlns/templess">' 
     463        '<bar t:content="bar"><t:tag t:replace="baz" />' 
     464        '<span t:replace="qux" />' 
     465        '<t:tag t:replace="quux" /></bar></foo>') 
     466    g = xmlgenerator(t) 
     467    s = ''.join(g.convert_generate({'bar': [{'baz': 1, 'qux': 2, 'quux': 3}]})) 
     468    assert s == '<foo><bar>123</bar></foo>' 
  • trunk/test/test_templess_functional.py

    r139 r140  
    22# -*- coding: UTF-8 -*- 
    33import py 
    4 here = py.magic.autopath().dirpath() 
     4here = py.path.local(__file__).dirpath() 
    55py.std.sys.path.append(here.dirpath().strpath) 
    66 
     
    4444 
    4545def setup_module(mod): 
    46     t = (py.magic.autopath().dirpath() / 
     46    t = (py.path.local(__file__).dirpath() / 
    4747                    'templates/testtemplate.html').open() 
    4848    template = templess.template(t) 
     
    154154        'includedata2': 'bar', 
    155155    } 
    156     fp = (py.magic.autopath().dirpath() / 'templates/testtemplate.html').open() 
     156    fp = py.path.local(__file__).dirpath().join( 
     157        'templates/testtemplate.html').open() 
    157158    try: 
    158159        data = fp.read() 
     
    196197    edoc = etree.fromstring(rendered) 
    197198    xpe = etree.XPathEvaluator(edoc) 
    198     xpe.registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml') 
     199    try: 
     200        # required for older versions of lxml 
     201        xpe.registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml') 
     202    except: 
     203        # newer version 
     204        pass 
    199205         
    200     rngdoc = etree.parse(str(py.magic.autopath().dirpath() / 'templess.rng')) 
     206    rngdoc = etree.parse( 
     207        str(py.path.local(__file__).dirpath().join('templess.rng'))) 
    201208    # if this fails, you might not have the xhtml (and modules) schema 
    202209    # available 
    203210    rng = etree.RelaxNG(rngdoc) 
    204     t1 = open(str(py.magic.autopath().dirpath() / 
    205                     'templates/testtemplate.html')) 
     211    t1 = open( 
     212        str(py.path.local(__file__).dirpath().join( 
     213            'templates/testtemplate.html'))) 
    206214    t1doc = etree.parse(t1) 
    207215    assert rng.validate(t1doc) 
    208     rngdoc = etree.parse(str(py.magic.autopath().dirpath() / 'xhtml.rng')) 
     216    rngdoc = etree.parse( 
     217        str(py.path.local(__file__).dirpath().join('xhtml.rng'))) 
    209218    rng = etree.RelaxNG(rngdoc) 
    210219    assert rng.validate(edoc)