Edgewall Software

Changeset 370


Ignore:
Timestamp:
Oct 16, 2006, 10:08:13 AM (17 years ago)
Author:
cmlenz
Message:

Reenable includes to work without an search path. Closes #63.

Location:
trunk/genshi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/genshi/plugin.py

    r369 r370  
    5252                                     max_cache_size)
    5353
    54         self.loader = TemplateLoader(search_path, auto_reload=auto_reload,
     54        self.loader = TemplateLoader(filter(None, search_path),
     55                                     auto_reload=auto_reload,
    5556                                     max_cache_size=max_cache_size)
    5657
  • trunk/genshi/template.py

    r365 r370  
    13551355
    13561356            search_path = self.search_path
     1357            isabs = False
    13571358
    13581359            if os.path.isabs(filename):
    13591360                # Bypass the search path if the requested filename is absolute
    13601361                search_path = [os.path.dirname(filename)]
     1362                isabs = True
    13611363
    13621364            elif relative_to and os.path.isabs(relative_to):
     
    13651367                dirname = os.path.dirname(relative_to)
    13661368                if dirname not in search_path:
    1367                     search_path = search_path[:] + [dirname]
     1369                    search_path = search_path + [dirname]
     1370                isabs = True
    13681371
    13691372            elif not search_path:
     
    13761379                    fileobj = open(filepath, 'U')
    13771380                    try:
     1381                        if isabs:
     1382                            # If the filename of either the included or the
     1383                            # including template is absolute, make sure the
     1384                            # included template gets an absolute path, too,
     1385                            # so that nested include work properly without a
     1386                            # search path
     1387                            filename = os.path.join(dirname, filename)
     1388                            dirname = ''
    13781389                        tmpl = cls(fileobj, basedir=dirname, filename=filename,
    13791390                                   loader=self)
  • trunk/genshi/tests/template.py

    r365 r370  
    12361236            </html>""", tmpl.generate().render())
    12371237
     1238    def test_relative_include_without_search_path_nested(self):
     1239        file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
     1240        try:
     1241            file1.write("""<div>Included</div>""")
     1242        finally:
     1243            file1.close()
     1244
     1245        file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w')
     1246        try:
     1247            file2.write("""<div xmlns:xi="http://www.w3.org/2001/XInclude">
     1248              <xi:include href="tmpl1.html" />
     1249            </div>""")
     1250        finally:
     1251            file2.close()
     1252
     1253        file3 = open(os.path.join(self.dirname, 'tmpl3.html'), 'w')
     1254        try:
     1255            file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
     1256              <xi:include href="tmpl2.html" />
     1257            </html>""")
     1258        finally:
     1259            file3.close()
     1260
     1261        loader = TemplateLoader()
     1262        tmpl = loader.load(os.path.join(self.dirname, 'tmpl3.html'))
     1263        self.assertEqual("""<html>
     1264              <div>
     1265              <div>Included</div>
     1266            </div>
     1267            </html>""", tmpl.generate().render())
     1268
    12381269    def test_relative_include_from_inmemory_template(self):
    12391270        file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
Note: See TracChangeset for help on using the changeset viewer.