[Jifty-commit] r6115 - in wifty/trunk/lib/Wifty: .

Jifty commits jifty-commit at lists.jifty.org
Mon Dec 15 10:25:24 EST 2008


Author: ruz
Date: Mon Dec 15 10:25:24 2008
New Revision: 6115

Modified:
   wifty/trunk/lib/Wifty/Dispatcher.pm
   wifty/trunk/lib/Wifty/View/Feeds.pm

Log:
* rework feeds:
** headlines are default
** cover feeds for new pages
* under/on doesn't work the way it should, use just on

Modified: wifty/trunk/lib/Wifty/Dispatcher.pm
==============================================================================
--- wifty/trunk/lib/Wifty/Dispatcher.pm	(original)
+++ wifty/trunk/lib/Wifty/Dispatcher.pm	Mon Dec 15 10:25:24 2008
@@ -92,14 +92,8 @@
 # Show recent
 
 # backwards compat
-on '/recent', run {
-    redirect('/recent/changes');
-};
-
-under 'feeds/atom/recent', run {
-    set pages => recent_changes();
-};
-on qr{^/recent/(.+)}, run {
+on 'recent' => run { redirect('/recent/changes') };
+on qr{^/recent/(changes|additions)}, run {
     my $type = $1;
     if ( $type eq 'changes' ) {
         set title => _('Updated this week');
@@ -107,13 +101,32 @@
     } elsif ( $type eq 'additions' ) {
         set title => _('Created this week');
         set pages => Wifty::Model::PageCollection->recently_created;
-    } else {
-        redirect('/recent/changes');
     }
-    set( type => $type );
+    set type => $type;
     show('/recent');
 };
 
+on 'feeds/atom/recent' => run { redirect('/feeds/atom/recent/changes/headlines') };
+on qr{^/feeds/atom/recent/(changes|additions)(?:/(full|headlines|diff))?$} => run {
+    my $wikiname = Jifty->config->app('WikiName');
+    my $show = $1;
+    my $show_as = $2 || 'headlines';
+    my ($pages, $title);
+    if ( $show eq 'changes' ) {
+        $pages = Wifty::Model::PageCollection->recently_updated;
+        $title = $wikiname
+            ? _('Recently changed pages on %1 wiki', $wikiname)
+            : _('Recently changed pages on some wiki');
+    } else {
+        $pages = Wifty::Model::PageCollection->recently_created;
+        $title = $wikiname
+            ? _('Recently added pages on %1 wiki', $wikiname)
+            : _('Recently added pages on some wiki');
+    }
+    set( title => $title ); set( pages => $pages ); set( show_as => $show_as );
+    show('/feeds/atom/pages');
+};
+
 sub setup_page_nav {
     my ($prefix, $page, $rev) = @_;
 

Modified: wifty/trunk/lib/Wifty/View/Feeds.pm
==============================================================================
--- wifty/trunk/lib/Wifty/View/Feeds.pm	(original)
+++ wifty/trunk/lib/Wifty/View/Feeds.pm	Mon Dec 15 10:25:24 2008
@@ -7,30 +7,31 @@
 use XML::Atom::SimpleFeed;
 use Data::UUID;
 
-# XXX: don't know how to redispatch to private template
-# right from dispatcher
-template 'atom/recent' => sub {
-    set(type => 'full');
-    show('../atom');
-};
-
-template 'atom/recent/diff' => sub {
-    set(type => 'diff');
-    show('../../atom');
-};
+private template 'pages_links' => sub {
+    my ($title, $path) = get(qw(title path));
 
-template 'atom/recent/headlines' => sub {
-    set(type => 'headlines');
-    show('../../atom');
+    add rel "alternate",
+        type => "application/atom+xml",
+        title => $title .' '. _('(headlines)'),
+        href => "/feeds/atom/$path/headlines",
+    ;
+    add rel "alternate",
+        type => "application/atom+xml",
+        title => $title .' '. _('(full content)'),
+        href => "/feeds/atom/$path/full",
+    ;
+    add rel "alternate",
+        type => "application/atom+xml",
+        title => $title .' '. _('(diffs)'),
+        href => "/feeds/atom/$path/diffs",
+    ;
 };
 
 # XXX: id rendering is not correct
-private template 'atom' => sub {
-    my ($pages, $type) = get(qw(pages type));
-    my $wikiname = Jifty->config->app('WikiName');
-    my $title = $wikiname
-        ? _('Recently changed pages on %1 wiki', $wikiname)
-        : _('Recently changed pages on some wiki');
+# XXX: don't know how to dispatch to private template
+template 'atom/pages' => sub {
+    my ($pages, $title, $show_as) = get(qw(pages title show_as));
+    $show_as ||= 'headlines';
     my $feed = XML::Atom::SimpleFeed->new(
         title   => $title,
         link    => Jifty->web->url,
@@ -39,10 +40,10 @@
 
     while ( my $page = $pages->next ) {
         my $summary = '';
-        if ( !$type || $type eq 'full' ) {
+        if ( $show_as eq 'full' ) {
             $summary = $page->viewer->form_field('content')->wiki_content;
         }
-        elsif ( $type eq 'diff' ) {
+        elsif ( $show_as eq 'diff' ) {
             $summary = '<pre>'. $page->revisions->last->diff_from .'</pre>';
         }
 


More information about the Jifty-commit mailing list