Browse Source

misc stuff related to refactoring

Oz N Tiram 9 years ago
parent
commit
a83e628dd9
1 changed files with 17 additions and 33 deletions
  1. 17 33
      blogit/blogit.py

+ 17 - 33
blogit/blogit.py

@@ -133,11 +133,12 @@ class Entry(object):
 
 
     .. code:
     .. code:
 
 
+        ---
         title: example page
         title: example page
         public: yes
         public: yes
         kind: page
         kind: page
         template: about.html
         template: about.html
-
+        ---
         # some heading
         # some heading
 
 
         content paragraph
         content paragraph
@@ -150,6 +151,7 @@ class Entry(object):
 
 
     .. code:
     .. code:
 
 
+        ---
         title: Blog post 1
         title: Blog post 1
         author: Famous author
         author: Famous author
         published: 2015-01-11
         published: 2015-01-11
@@ -157,9 +159,8 @@ class Entry(object):
         public: yes
         public: yes
         chronological: yes
         chronological: yes
         kind: writing
         kind: writing
-        summary: |
-            This is a summry of post 1. Donec id elit non mi porta
-            ...
+        summary: This is a summry of post 1. Donec id elit non mi porta
+        ---
 
 
         This is the body of post 1. Donec id elit non mi porta gravida
         This is the body of post 1. Donec id elit non mi porta gravida
     """
     """
@@ -333,44 +334,26 @@ def _get_last_entries():
     return entries
     return entries
 
 
 
 
-def update_index():
+def update_index(entries):
     """find the last 10 entries in the database and create the main
     """find the last 10 entries in the database and create the main
     page.
     page.
     Each entry in has an eid, so we only get the last 10 eids.
     Each entry in has an eid, so we only get the last 10 eids.
 
 
     This method also updates the ATOM feed.
     This method also updates the ATOM feed.
     """
     """
-    entries = _get_last_entries()
     context = GLOBAL_TEMPLATE_CONTEXT.copy()
     context = GLOBAL_TEMPLATE_CONTEXT.copy()
     context['entries'] = entries
     context['entries'] = entries
 
 
-    for name, out in {'entry_index.html': 'index.html',
-                      'atom.xml': 'atom.xml'}.items():
-        template = jinja_env.get_template(name)
-        html = template.render(context)
-        destination = codecs.open("%s/%s" % (CONFIG['output_to'], out),
-                                  'w', CONFIG['content_encoding'])
-        destination.write(html)
-        destination.close()
-
+    map(lambda x: _render(
+        context, x[0], os.path.join(CONFIG['output_to'], x[1])),
+        (('entry_index.html', 'index.html'), ('atom.xml', 'atom.xml')))
 
 
-def new_build():
-    """
 
 
-        a. For each new post:
-        1. render html
-        2. find post tags
-        3. update atom feeds for old tags
-        4. create new atom feeds for new tags
+def build():
+    """Incremental build of the website"""
 
 
-    b. update index page
-    c. update archive page
-
-    """
-    print
-    print "Rendering website now..."
-    print
-    print " entries:"
+    print("\nRendering website now...\n")
+    print(entries:")
     tags = dict()
     tags = dict()
     root = CONFIG['content_root']
     root = CONFIG['content_root']
     for post_id, post in find_new_posts_and_pages(DB):
     for post_id, post in find_new_posts_and_pages(DB):
@@ -386,9 +369,9 @@ def new_build():
         print "updating tag %s" % name
         print "updating tag %s" % name
         to.render()
         to.render()
 
 
-    # update index
+        # update index
     print "updating index"
     print "updating index"
-    update_index()
+    update_index(_get_last_entries)
 
 
     # update archive
     # update archive
     print "updating archive"
     print "updating archive"
@@ -447,6 +430,7 @@ def new_post(GITDIRECTORY=CONFIG['output_to'],
     This function should create a template for a new post with a title
     This function should create a template for a new post with a title
     read from the user input.
     read from the user input.
     Most other fields should be defaults.
     Most other fields should be defaults.
+    TODO: update this function
     """
     """
     title = raw_input("Give the title of the post: ")
     title = raw_input("Give the title of the post: ")
     while ':' in title:
     while ':' in title:
@@ -521,7 +505,7 @@ def main():   # pragma: no coverage
     if args.clean:
     if args.clean:
         clean()
         clean()
     if args.build:
     if args.build:
-        new_build()
+        build()
     if args.dist:
     if args.dist:
         dist()
         dist()
     if args.preview:
     if args.preview: