Commits

Anonymous committed 56b4ce6

Allow jQuery URL to be overridden (for local offline testing.)

Comments (0)

Files changed (3)

src/chrysoberyl/commands.py

     """Render all nodes to a set of HTML5 files.
 
     """
+    optparser.add_option("--jquery-url",
+                         dest="jquery_url", metavar='URL',
+                         default='http://code.jquery.com/jquery-1.8.1.min.js',
+                         help="URL from which rendered pages grab jQuery")
     optparser.add_option("--node-dir",
                          dest="node_dir", metavar='DIR',
                          default='../catseye.tc/node',
         json.dump(transform_dates(data), file, encoding='utf-8',
                   default=unicode)
     convert_chrysoberyl_data(data)
-    r = Renderer(data, 'templates', options.node_dir)
+    r = Renderer(data, 'templates', options.node_dir,
+                 jquery_url=options.jquery_url)
     r.render_chrysoberyl_data()
     for filename in ['chrysoberyl.js', 'chrysoberyl-query.js']:
         shutil.copy(os.path.join('static', filename),

src/chrysoberyl/renderer.py

     """Object which renders Chrysoberyl data as HTML pages.
 
     """
-    def __init__(self, data, template_dir, output_dir):
+    def __init__(self, data, template_dir, output_dir,
+                 jquery_url=None):
         self.data = data
         self.template_dir = template_dir
         self.output_dir = output_dir
         self.loader = jinja2.FileSystemLoader(self.template_dir,
                                               encoding='utf-8')
         self.env = jinja2.Environment(loader=self.loader)
+        self.jquery_url = jquery_url
 
     def render(self, template, output_filename, context):
         """Low-level method to render a given template."""
         context['data'] = self.data
         context['key'] = key
         context['filekey'] = filekey
+        context['jquery_url'] = self.jquery_url
 
         # Context functions.  Being nested functions of render_node lets
         # them easily access (close over) the current node and its key.

templates/base.html

   <title>{{ key }} | Cat's Eye Technologies</title>
   <link rel="shortcut icon" type="image/x-icon" href="../../favicon.ico" />
   <link rel="stylesheet" type="text/css" href="../stylesheet/chrysoberyl.css" />
-  <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
+  <script src="{{ jquery_url }}"></script>
   <script type="text/javascript" src="../scripts/chrysoberyl.js"></script>
   {% block extra_head %}{% endblock extra_head %}
 </head>