Christian Boos wrote:
...
One approach would be to encode the format elsewhere, e.g.
[raw-source:trunk/test.html test.html], which would translate to the URL
/YourTracEnv/raw-source/trunk/test.html

The request dispatcher of the browser module could be adapted to
extract the format argument from there.

I also had a need for this, so I wrote it :)

How to apply the patch:
$ cd trunk
$ patch -p1 < raw-browser-r3570.patch

Use it as explained above (only difference, the URL will be raw_browser).

-- Christian

diff -r 7cf3a3bff105 trac/versioncontrol/web_ui/browser.py
--- a/trac/versioncontrol/web_ui/browser.py     Tue Jul 25 19:29:49 2006 +0200
+++ b/trac/versioncontrol/web_ui/browser.py     Tue Jul 25 19:45:20 2006 +0200
@@ -77,10 +77,13 @@ class BrowserModule(Component):
 
     def match_request(self, req):
         import re
-        match = re.match(r'/(browser|file)(?:(/.*))?', req.path_info)
+        match = re.match(r'/(raw[-_])?(browser|file)(?:(/.*))?', req.path_info)
         if match:
-            req.args['path'] = match.group(2) or '/'
-            if match.group(1) == 'file':
+            req.args['path'] = match.group(3) or '/'
+            raw = match.group(1)
+            if raw:
+                req.args['format'] = 'raw'
+            if match.group(2) == 'file':
                 req.redirect(req.href.browser(req.args.get('path'),
                                               rev=req.args.get('rev'),
                                               format=req.args.get('format')),
@@ -274,6 +277,8 @@ class BrowserModule(Component):
 
     def get_link_resolvers(self):
         return [('repos', self._format_link),
+                ('raw-source', self._format_link),
+                ('raw-browser', self._format_link),
                 ('source', self._format_link),
                 ('browser', self._format_link)]
 
@@ -282,5 +287,9 @@ class BrowserModule(Component):
         fragment = ''
         if line is not None:
             fragment = '#L%d' % line
+        if 'raw' in ns:
+            href = formatter.href.raw_browser
+        else:
+            href = formatter.href.browser
         return html.A(label, class_='source',
-                      href=formatter.href.browser(path, rev=rev) + fragment)
+                      href=href(path, rev=rev) + fragment)
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac

Reply via email to