Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 2959:fa5410ae581d
allow use of XML templates again
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 25 Nov 2004 22:19:51 +0000 |
| parents | 4511fd6c5dbf |
| children | 68ba01244341 |
comparison
equal
deleted
inserted
replaced
| 2958:1ae91c2fa5fe | 2959:fa5410ae581d |
|---|---|
| 81 # try old-style | 81 # try old-style |
| 82 src = os.path.join(dir, filename) | 82 src = os.path.join(dir, filename) |
| 83 if os.path.exists(src): | 83 if os.path.exists(src): |
| 84 return (src, filename) | 84 return (src, filename) |
| 85 | 85 |
| 86 # try with a .html extension (new-style) | 86 # try with a .html or .xml extension (new-style) |
| 87 filename = filename + '.html' | 87 for extension in '.html', '.xml': |
| 88 src = os.path.join(dir, filename) | 88 filename = filename + extension |
| 89 if os.path.exists(src): | 89 src = os.path.join(dir, filename) |
| 90 return (src, filename) | 90 if os.path.exists(src): |
| 91 return (src, filename) | |
| 91 | 92 |
| 92 # no extension == no generic template is possible | 93 # no extension == no generic template is possible |
| 93 if not extension: | 94 if not extension: |
| 94 raise NoTemplate, 'Template file "%s" doesn\'t exist'%name | 95 raise NoTemplate, 'Template file "%s" doesn\'t exist'%name |
| 95 | 96 |
| 117 | 118 |
| 118 def precompileTemplates(self): | 119 def precompileTemplates(self): |
| 119 ''' Go through a directory and precompile all the templates therein | 120 ''' Go through a directory and precompile all the templates therein |
| 120 ''' | 121 ''' |
| 121 for filename in os.listdir(self.dir): | 122 for filename in os.listdir(self.dir): |
| 122 # skip files without ".html" extension - .css, .js etc. | |
| 123 if not filename.endswith(".html"): | |
| 124 continue | |
| 125 # skip subdirs | 123 # skip subdirs |
| 126 if os.path.isdir(filename): | 124 if os.path.isdir(filename): |
| 127 continue | 125 continue |
| 126 # skip files without ".html" or ".xml" extension - .css, .js etc. | |
| 127 for extension in '.html', '.xml': | |
| 128 if filename.endswith(extension): | |
| 129 break | |
| 130 else: | |
| 131 continue | |
| 132 | |
| 128 # remove "html" extension | 133 # remove "html" extension |
| 129 filename = filename[:-len(".html")] | 134 filename = filename[:-len(extension)] |
| 135 | |
| 130 # load the template | 136 # load the template |
| 131 if '.' in filename: | 137 if '.' in filename: |
| 132 name, extension = filename.split('.', 1) | 138 name, extension = filename.split('.', 1) |
| 133 self.get(name, extension) | 139 self.get(name, extension) |
| 134 else: | 140 else: |
