changeset 83:666f3051ce31

move cook_entry to its own function
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 17 Nov 2011 12:15:43 -0800
parents 9e5dd802ba95
children e5a23f5ea14e
files bitsyblog/bitsyblog.py bitsyblog/blog.py
diffstat 2 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Thu Nov 17 12:03:04 2011 -0800
+++ b/bitsyblog/bitsyblog.py	Thu Nov 17 12:15:43 2011 -0800
@@ -603,22 +603,25 @@
         data['blogs'] = blogs
         data['users'] = users
         data['date_formats'] = dict([(user, self.users[user].settings.get('Date format', self.date_format)) for user in users])
-        
+
         # render the template
         template = self.loader.load('index.html')
         return template.generate(**request.environ['data']).render()
 
-        
+    def cooked_entry(self, entry):
+        """cook the entry"""
+        if (entry.user, entry.datestamp()) not in self.cooked_bodies:
+           self.cooked_bodies[(entry.user, entry.datestamp())] = self.cooker(entry.body)
+        return self.cooked_bodies[(entry.user, entry.datestamp())]
+
     def write_blog(self, user, blog, path, n_links, request):
         """return the user's blog in HTML"""
 
-        # XXX probably should go elsewhere
+        # cook the entry
         for entry in blog:
-            if (user, entry.datestamp()) not in self.cooked_bodies:
-                self.cooked_bodies[(user, entry.datestamp())] = self.cooker(entry.body)
-            entry.cooked_body = Markup(self.cooked_bodies[(user, entry.datestamp())])
+            entry.cooked_body = Markup(self.cooked_entry(entry))
 
-        # site nav 
+        # site nav
         # XXX def site_nav() puts directly in request.environ['data']
         # should return instead
         self.site_nav(request)
--- a/bitsyblog/blog.py	Thu Nov 17 12:03:04 2011 -0800
+++ b/bitsyblog/blog.py	Thu Nov 17 12:15:43 2011 -0800
@@ -17,7 +17,7 @@
             self.user = user
 
     def title(self, characters=80):
-        
+
         if '\n' in self.body:
             lines = [i.strip() for i in self.body[:characters].split('\n')]
             if len(lines[0]) > characters:
@@ -33,7 +33,6 @@
     def snippet(self, characters=80):
         if characters:
             if len(self.body) > characters:
-                
 
                 text = ' '.join(self.body[:characters].split()[:-1])
                 if '\n' in text: