Commits

Matthew Scott  committed 3fecbd9

+ Allow specifying 'slipper.DEFAULT.index_path' to make localhost browsing more comfortable

  • Participants
  • Parent commits f83f57b

Comments (0)

Files changed (3)

 # You can optionally override in configuration for specific repositories.
 slipper.DEFAULT.stylesheet_path = /doc/slipper.css
 
+# Specify a location to redirect to when the top-level index is requested.
+# If not specified, gives 404 NOT FOUND when top-level index is requested.
+# This is useful for browsing documentation locally.
+slipper.DEFAULT.index_path = dev/tip+/doc/
+
 # For each repository, choose a name, then specify both the location
 # of the repository on the local filesystem ('local_dir') and the base
 # URL of the hgweb or hgwebdir instance you'd like each page to link
-# to ('hgweb_url'.
+# to ('hgweb_url').
 #
-# For example, to define the repository 'myrepo':
-slipper.slipper-dev.local_dir = %(here)s
-slipper.slipper-dev.hgweb_url = http://example.com/hg/myrepo
+# For example, to define the repository 'dev':
+slipper.dev.local_dir = %(here)s
+slipper.dev.hgweb_url = http://example.com/hg/myrepo-dev
 
 # You can also override the 'rst_extension' and 'cache_dir' if you
 # like:
-slipper.slipper-dev.rst_extension = .txt
+slipper.dev.rst_extension = .txt

File slipper/app.py

 class Application(object):
 
     def __init__(self, global_conf, **local_conf):
+        self.index_path = local_conf.pop('slipper.DEFAULT.index_path', None)
         self.repo_map = repo_map_from_config(local_conf)
 
     def __call__(self, environ, start_response):
         # Determine the section to use and the file to render.
         PATH_INFO = environ['PATH_INFO'][1:]
+        if PATH_INFO == '':
+            if not self.index_path:
+                # XXX: HTTP experts: is this correct?
+                status = '404 NOT FOUND'
+                response_headers = [
+                    ('Content-Type', 'text/plain'),
+                    ]
+                start_response(status, response_headers)
+                return [status]
+            else:
+                status = '302 FOUND'
+                response_headers = [
+                    ('Content-Type', 'text/html'),
+                    ('Location', self.index_path),
+                    ]
+                start_response(status, response_headers)
+                return [status]
         parts = PATH_INFO.split('/', 2)
         if len(parts) != 3:
             # Unsupported query string; act as if a resource was requested

File slipper/config.py

         >>> sorted(repo_map.keys())
         ['repo1', 'repo2']
     """
+    config = config.copy()
     # Find default information.
     default = RepositoryInfo(
         cache_dir = config.pop('slipper.DEFAULT.cache_dir', None),