Edgewall Software
Modify

Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#10163 closed enhancement (fixed)

Allow pure xml file format in trac.env_index_template (site.html)

Reported by: dawuid@… Owned by: dawuid@…
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 .xml file in the trac.env_index_template WSGI variable (see TracInterfaceCustomization).

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)

10163-xml-project-index-r11111.patch (806 bytes ) - added by Remy Blank 12 years ago.
Allow XML for project index template.

Download all attachments as: .zip

Change History (13)

comment:1 by Christian Boos, 14 years ago

Milestone: 0.13
Owner: set to Christian Boos

I suppose you meant the opposite patch ;-) (diff <old> <new>) You also have some tabs inside your file, seeing how else: is badly indented. Finally, the temporary variable use_xml being used only once, it doesn't improve readability; just directly write if ... endswith ....

I also just verified that we send text/xml content as text/xml; charset=utf-8, so all seems fine.

You should tidy up the patch, but nevertheless thanks for contributing!

comment:2 by dawuid@…, 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 Christian Boos, 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.

comment:4 by Remy Blank, 12 years ago

Milestone: 1.01.0-triage

Preparing for 1.0.

comment:5 by Christian Boos, 12 years ago

Milestone: next-stable-1.0.x1.0

Will finish for 1.0.

by Remy Blank, 12 years ago

Allow XML for project index template.

comment:6 by Remy Blank, 12 years ago

Owner: changed from Christian Boos to Remy Blank

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 dawuid@…, 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 Remy Blank, 12 years ago

Fair enough. Can you please test the patch, and let us know if it works for you?

comment:9 by dawuid@…, 12 years ago

Tested and working like a charm. Thank you!

comment:10 by Remy Blank, 12 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Thanks for testing. Patch applied in [11119].

comment:11 by Remy Blank, 12 years ago

Owner: changed from Remy Blank to dawuid@…

comment:12 by Ryan J Ollos, 11 years ago

Keywords: site-customization added; site.html removed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain dawuid@….
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from dawuid@… to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.