Anonymous avatar Anonymous committed 3019cd7

Add support for rendering pages with 'sleek' node links.

Comments (0)

Files changed (4)

src/chrysoberyl/commands.py

                          dest="render_docs", default=False,
                          action='store_true',
                          help="render documentation nodes as well")
+    optparser.add_option("--sleek-node-links",
+                         dest="sleek_node_links", default=False,
+                         action='store_true',
+                         help="render links to nodes using Mediawiki-ish "
+                              "URLs (requires web server that understands "
+                              "what nodes these refer to")
     options, args = optparser.parse_args(args)
     data = load_and_check(options.data_dirs.split(':'))
     json_data = {}
     convert_chrysoberyl_data(data)
     r = Renderer(data,
         options.template_dirs, options.node_dir, options.clone_dir,
-        options.render_docs
+        options.render_docs, options.sleek_node_links
     )
     r.render_chrysoberyl_data()
 

src/chrysoberyl/feed.py

 
 """Functions for generating Atom feeds from news item nodes in Chrysoberyl.
 
+Note: no support yet for 'sleek' node links.
+
 """
 
 import datetime

src/chrysoberyl/renderer.py

 from jinja2.exceptions import TemplateNotFound
 import markdown
 
-from chrysoberyl.transformer import filekey, pathname2url, markdown_contents
+from chrysoberyl.transformer import (
+    filekey, sleek_key, pathname2url, markdown_contents
+)
 
 
 class Loader(BaseLoader):
     """Object which renders Chrysoberyl data as HTML pages.
 
     """
-    def __init__(self, data, template_dirs, output_dir, clone_dir, render_docs):
+    def __init__(self, data, template_dirs, output_dir, clone_dir, render_docs,
+                 sleek_node_links):
         self.data = data
         self.template_dirs = template_dirs.split(':')
         self.output_dir = output_dir
         self.clone_dir = clone_dir
         self.render_docs = render_docs
+        self.sleek_node_links = sleek_node_links
         self.jinja2_env = Environment(loader=Loader(self.template_dirs))
 
     def render(self, template, output_filename, context):
             title_attr = ''
             if title is not None:
                 title_attr = ' title="%s"' % title
-            return '<a href="%s"%s>%s</a>' % (
-                pathname2url(filekey(key)), title_attr, link_text
-            )
+            if self.sleek_node_links:
+                href = pathname2url(sleek_key(key))
+            else:
+                href = pathname2url(filekey(key))
+            return '<a href="%s"%s>%s</a>' % (href, title_attr, link_text)
 
         # not the kind you're probably thinking of
         @expose
         template = self.get_template(key)
         filename = os.path.join(self.output_dir, filekey(key))
         self.render(template, filename, context)
+        # sideways compatibility
+        if '_' in filename:
+            filename = filename.replace('_', ' ')
+            self.render(template, filename, context)
 
     def render_chrysoberyl_data(self):
         """Render all nodes in the loaded Chrysoberyl data as HTML

src/chrysoberyl/transformer.py

     return key + ".html"
 
 
+def sleek_key(key):
+    """Convert a key into a form that can be used as a 'sleek' node link."""
+    return re.sub(r'(\/|\\| )', '_', key)
+
+
 def pathname2url(s, prefix=None):
     """Convert a filename into a form that can be used as a link in an
     HTML document.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.