#10163 closed enhancement (fixed)
Allow pure xml file format in trac.env_index_template (site.html)
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.0 |
Component: | rendering | Version: | 0.12.2 |
Severity: | minor | Keywords: | site-customization |
Cc: | Branch: | ||
Release Notes: |
Allow generating XML for the site index, by specifying an |
||
API Changes: | |||
Internal Changes: |
Description
In current stable version (0.12.2), 'site.html' (actually trac.env_index_template) can be in 2 formats:
- cs (ClearSilver): template is a file that ends with '.cs'
- xhtml (Genshi): anyother file
This propose of enhancement ask to allow use pure xml files in trac.env_index_template (as well as the other formats). In current trunk ClearSilver format has been eliminated, and all templates are rendered with Genshi in xhtml format. Genshi can easy render other formats.
The propose include an easy patch to allow to use pure xml files by checking file extension (similar to 0.12.2 code with .cs).
Index: trunk/trac/web/main.py =================================================================== --- a/trunk/trac/web/main.py +++ b/trunk/trac/web/main.py @@ -655,14 +655,9 @@ default_encoding='utf-8') tmpl = loader.load(template) stream = tmpl.generate(**data) - use_xml = template.endswith('.xml') - if use_xml: - output = stream.render('xml') - req.send(output, 'text/xml') - else: - output = stream.render('xhtml', doctype=DocType.XHTML_STRICT, - encoding='utf-8') - req.send(output, 'text/html') + output = stream.render('xhtml', doctype=DocType.XHTML_STRICT, + encoding='utf-8') + req.send(output, 'text/html') except RequestDone: pass
Attachments (1)
Change History (13)
comment:1 by , 14 years ago
Milestone: | → 0.13 |
---|---|
Owner: | set to |
comment:2 by , 14 years ago
Thanks for your corrections! (I'm afraid I have not read really well the guide about create enhancement requests).
Patch corrected:
Index: trunk/trac/web/main.py =================================================================== --- a/trunk/trac/web/main.py +++ b/trunk/trac/web/main.py @@ -655,9 +655,13 @@ default_encoding='utf-8') tmpl = loader.load(template) stream = tmpl.generate(**data) - output = stream.render('xhtml', doctype=DocType.XHTML_STRICT, - encoding='utf-8') - req.send(output, 'text/html') + if template.endswith('.xml'): + output = stream.render('xml') + req.send(output, 'text/xml; charset=utf-8') + else: + output = stream.render('xhtml', doctype=DocType.XHTML_STRICT, + encoding='utf-8') + req.send(output, 'text/html') except RequestDone: pass
comment:3 by , 14 years ago
Great! When I said above that I verified we actually send text/xml
content as text/xml; charset=utf-8
, I meant that when we do req.send(output, 'text/xml')
, we actually add the charset=utf-8
optional parameter and the header sent is the expected Content-Type: text/xml; charset=utf-8
, so the way you did it in the first patch was correct. Sorry for the confusion. I'll fix and apply.
by , 12 years ago
Attachment: | 10163-xml-project-index-r11111.patch added |
---|
Allow XML for project index template.
comment:6 by , 12 years ago
Owner: | changed from | to
---|
Full patch in 10163-xml-project-index-r11111.patch. But I have to wonder: what's the use of this? In what situation is an XML project index better than XHTML?
comment:7 by , 12 years ago
In our case, we list server resources avalaible in xml (Trac projects, svn repositories, webdav stores, etc.) and apply a corporative stylesheet. We often change that stylesheet. For the rest of resources xml index template is applied but with Trac we needed to mantain a separate xhtml with same style that corporative stylesheet (not only css but components distribution). With trac projects listings in xml we can do that easily.
comment:8 by , 12 years ago
Fair enough. Can you please test the patch, and let us know if it works for you?
comment:10 by , 12 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Thanks for testing. Patch applied in [11119].
comment:11 by , 12 years ago
Owner: | changed from | to
---|
comment:12 by , 11 years ago
Keywords: | site-customization added; site.html removed |
---|
I suppose you meant the opposite patch ;-) (
diff <old> <new>
) You also have some tabs inside your file, seeing howelse:
is badly indented. Finally, the temporary variableuse_xml
being used only once, it doesn't improve readability; just directly writeif ... endswith ...
.I also just verified that we send
text/xml
content astext/xml; charset=utf-8
, so all seems fine.You should tidy up the patch, but nevertheless thanks for contributing!