Commits

John Mulligan committed b422c10

partial implementation of feed (atom, rss) handlers

  • Participants
  • Parent commits 0478b59

Comments (0)

Files changed (4)

muyhomepage2/app/configuration.py

 from muyhomepage2.pagehandlers.tagglobal import TagGlobalHandler
 from muyhomepage2.pagehandlers.software import SoftwareHandler
 from muyhomepage2.pagehandlers.blog import BlogHandler
+from muyhomepage2.pagehandlers import feeds
 
 
 DEFAULT_HANDLERS = {
     'tagsummary': TagSummaryHandler,
     'tagglobal': TagGlobalHandler,
     'software': SoftwareHandler,
-    'atom': StandardHandler,
-    'rss2': StandardHandler,
+    'atom': feeds.AtomHandler,
+    'rss2': feeds.RssHandler,
     }
 
 
     def icontags(self):
         return {'Technology': '/~john/cruft/static/tagicon-tech.png'}
 
+    def base_url(self):
+        return 'http://karnak.nile/~john/cruft'
+
+    def site_author(self):
+        return 'John Mulligan'
+
+    def site_atom_id(self):
+        return 'tag:asynchrono.us,2006-01-02:birch-street-computing'
+

muyhomepage2/pagehandlers/feeds.py

+
+import os
+from muyhomepage2.pagehandlers import handler
+from muyhomepage2.pagehandlers import standard
+from muyhomepage2.text import wikirst
+from muyhomepage2 import page
+from muyhomepage2 import util
+
+
+class FeedEntryHandler(standard.StandardHandler):
+    pass
+    # linkto
+    # id_tag
+
+
+class BaseFeedHandler(handler.PageHandler):
+    def content(self):
+        return wikirst.format(self.page.body)
+
+    @property
+    def description(self):
+        return self.content()
+
+    def _getentries(self, website, config):
+        return []
+
+    def extension(self, website, config):
+        site_url = config.base_url()
+        entries = self._getentries(website, config)
+        if entries:
+            feed_mod = entries[0].modifiedon
+        else:
+            feed_mod = util.When(0)
+        return {
+            'site_url': site_url,
+            'self_url': os.path.join(site_url, self.finalname()),
+            'feed_updated': feed_mod,
+            'feed_author': config.site_author(),
+            'feed_id_tag': config.site_atom_id(),
+            'entries': entries,
+            }
+
+
+class AtomHandler(BaseFeedHandler):
+    def template(self):
+        return 'atom.xml'
+
+
+class RssHandler(BaseFeedHandler):
+    def template(self):
+        return 'rss2.xml'

skins/default/atom.xml

 <feed xmlns="http://www.w3.org/2005/Atom">
     <title>{{current.page.title}}</title>
     <link href="{{ext.site_url}}"></link>
-    <link rel="self" href="{{ext.atom_url}}"></link>
+    <link rel="self" href="{{ext.self_url}}"></link>
     <updated>{{ext.feed_updated}}</updated>
 
     <author>
         <published>{{entry.createdon.atomfmt}}</published>
 
         <content type="html">
-            Escaped HTML GOES HERE.
+            {{entry.content()|e}}
         </content>
 
         <id>{{entry.id_tag}}</id>

skins/default/rss2.xml

     <pubDate>{{entry.createdon.rfc822fmt}}</pubDate>
     
     <description>
-     {{entry.content|escapex}}
+     {{entry.content|e}}
     </description>
     
     <guid>{{entry.linkto}}</guid>