Commits

Luke Plant committed 0682999

Implemented HTML version of schemes page

Comments (0)

Files changed (2)

bibleverses/config.py

 # - To get data from file system
 #datareader = readers.FileReader(YAMLDIR)
 
-datawriters = {'wiki': writers.TracWikiWriter(DATABASE, AUTHOR)}
+datawriters = {
+    'wiki': writers.TracWikiWriter(DATABASE, AUTHOR),
+    'html': writers.FileWriter(OUTPUTHTMLDIR)
+}

bibleverses/update.py

 #!/usr/bin/env python
 
+from nevow import tags as T
+from nevow.flat import flatten
+import urllib2
+
 from parse import get_verses, get_topic_entries, populate_topic_tree, get_topictree, get_schemes
 from build import build_schemes
-from config import datawriters
 from StringIO import StringIO
-
-from config import TOPICSPAGENAME, SCHEMESPAGENAME, SCHEMESPAGENAMEPREFIX
+from config import TOPICSPAGENAME, SCHEMESPAGENAME, SCHEMESPAGENAMEPREFIX, datawriters
 
 # All of the 'make_x_page' functions here return a dictionary containing
 # multiple formats of the data to be written.  The 'datawriters' dict
 #    prefer the one that isn't ESV
 # The html format is for public consumption
 #  - It always outputs ESV and KJV
+# For the moment, it seems easiest to have one function that generates
+# both wiki and html.
 
 def write_page(name, data):
     for format, text in data.items():
     print "Topics: %d" % len(get_topic_entries(verses))
     print "Schemes: %d" % len(schemes)
 
+def smart_flatten(tags):
+    # Nevow seems to convert things to UTF8
+    s = flatten(tags)
+    if not isinstance(s, unicode):
+        s = s.decode("UTF-8")
+    return s
+
 def scheme_page_name(prefix, scheme):
     return prefix + scheme.name.title().replace(" ", "")
 
 def bible_entry_wiki(entry):
     return u"bible:\"%s\" -- %s\n" % (entry.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 = StringIO()
     wiki.write(u"""
 
 def make_scheme_page(scheme):
     wiki = StringIO()
+    html = []
+
     wiki.write(u"""
 = Bible Memorisation Scheme - %s =
 
 
 """ % scheme.name)
     wiki.write(scheme.description + u"\n\n")
+
+    html.extend([
+            T.h1[u" Bible Memorisation Scheme - %s" % scheme.name],
+            T.p[scheme.description]
+    ])
+
+    ul = T.ul(class_="verselist")
+    html.append(ul)
     for item in scheme.items:
+        # WIKI
         wiki.write(u"\nbible:\"%s\"\n" % item.verse.verse)
         for e in item.entries:
             wiki.write(u" * '''%s'''" % e.topic)
                 wiki.write(u" :: %s" % e.comment)
             wiki.write(u"\n")
         write_verse_text_wiki(item.verse, wiki)
+
+        # HTML
+        ul.children.append(
+            T.li(class_="verseitem")[
+                 mk_bible_link(item.verse.verse),
+                 T.ul[
+                       [T.li(class_="topicentry")[
+                           [T.span(class_="topicheading")[e.topic],
+                            (e.comment and (" :: %s" % e.comment) or "")
+                           ]                           
+                        ]
+                       for e in item.entries]
+                 ],
+                 T.br,
+                 T.div(class_=u"verse")[ 
+                       item.verse.texts['ESV'] 
+                 ],
+                 T.br
+            ]
+        )
+
     wiki.write(u"""
 
 ----
 [[AutoNav()]]
 """)
-    return {'wiki': wiki.getvalue()}
+    return {'wiki': wiki.getvalue(),
+            'html': smart_flatten(html)}
 
 def make_scheme_index_page(schemes, prefix):
     wiki = StringIO()