Commits

Luke Plant committed 0e6b92c

Implemented HTML version for topics page

Comments (0)

Files changed (3)

bibleverses/config.py

 
 datawriters = {
     'wiki': writers.TracWikiWriter(DATABASE, AUTHOR),
-    'html': writers.FileWriter(OUTPUTHTMLDIR)
+    'html': writers.FileWriter(OUTPUTHTMLDIR, ".ihtml")
 }

bibleverses/update.py

 def bible_entry_wiki(entry):
     return u"bible:\"%s\" -- %s\n" % (entry.verse, entry.comment)
 
+def bible_entry_html(entry):
+    return [mk_bible_link(entry.verse.verse), " -- " , entry.comment]
+
 def mk_bible_link(verseref):
     return T.a(class_=u"bible", href=u"http://www.gnpcb.org/esv/search/?q=%s" % urllib2.quote(verseref))[verseref]
 
 def make_topics_page(verses, topictree, extras):
+    # WIKI
     wiki = StringIO()
     wiki.write(u"""
 = Bible Memorisation Topics =
             for e in node.entries:
                 buf.write(u"%s   * %s" % (padding, bible_entry_wiki(e)))
         for n in node.nodes:
-            # This is an extra line
             print_topic_node_wiki(n, buf, indentation_level+2)
     
     # Skip the root node
         wiki.write(u" * %s\n" % k)
         for e in val:
             wiki.write(u"   * %s" % bible_entry_wiki(e))
+
+    # HTML
+    html = []
+    html.extend([
+            T.h1[ u"Bible Memorisation Topics" ],
+    ])
+
+    def get_topic_node_html(node):
+        return T.li[
+                     T.span(class_="topicheading")[node.name],
+                     (node.entries 
+                       and T.ul[ 
+                                 [ T.li[ bible_entry_html(e) ]
+                                   for e in node.entries ]
+                           ]
+                       or []),
+                     (node.nodes 
+                       and T.ul[
+                                 [ get_topic_node_html(n) 
+                                   for n in node.nodes ]
+                           ]
+                       or [])
+                   ]
+                      
+    html.append(T.ul[[get_topic_node_html(n)
+                     for n in topictree.nodes]])
+
+    html.extend([
+            T.h2[ u"Uncategorised"],
+            T.ul[
+                  [ T.li[ k,
+                          T.ul[
+                                [
+                                  T.li[ bible_entry_html(e)]
+                                  for e in val
+                                ]
+                              ]
+                        ]
+                    for k, val in extras.iteritems()]
+                ]
+    ])
+
         
-    return {'wiki': wiki.getvalue()}
+    return {'wiki': wiki.getvalue(),
+            'html': smart_flatten(html)}
 
 def make_scheme_page(scheme):
     wiki = StringIO()
     [ 
         T.h1[u"Bible Memorisation Schemes"],
         T.ul[
-              [T.li[T.a(href=FileWriter.make_html_filename(scheme_page_name(prefix, scheme)))
+              [T.li[T.a(href=FileWriter.make_html_filename(scheme_page_name(prefix, scheme), ".html"))
                        [ scheme.name ],
                     T.br,
                     T.p[ scheme.description ]

bibleverses/writers.py

     is stripped from the front of names."""
     # Implemented as a class as 'make_html_filename' is needed
     # elsewhere
-    def __init__(self, dirname):
+    def __init__(self, dirname, suffix=".html"):        
         self.dirname = dirname
+        self.suffix = suffix
 
     filenamestem = 'BibleMemorisation'
     @staticmethod
-    def make_html_filename(pagename):
+    def make_html_filename(pagename, suffix):
         stem = FileWriter.filenamestem
         assert pagename.startswith(stem)
         # we deliberately leave "/" in, allowing for subdirectories.
         # This will fail if dirs do not exist already
-        return pagename[len(stem):].lower() + ".html"
+        return pagename[len(stem):].lower() + suffix
 
     def __call__(self, name, data):
-        filename = self.make_html_filename(name)
+        filename = self.make_html_filename(name, self.suffix)
         with file(os.path.join(self.dirname, filename), "w") as f:
             f.write(data.encode("UTF-8"))