Author: nick Date: 2006-06-22 15:11:27 +0100 (Thu, 22 Jun 2006) New Revision: 813
Modified: trunk/lib/OpenGuides/Feed.pm Log: Add method for generating a feed from an arbitary list of nodes
Modified: trunk/lib/OpenGuides/Feed.pm =================================================================== --- trunk/lib/OpenGuides/Feed.pm 2006-06-22 13:53:46 UTC (rev 812) +++ trunk/lib/OpenGuides/Feed.pm 2006-06-22 14:11:27 UTC (rev 813) @@ -56,6 +56,17 @@ $self; }
+=item B<make_feed> +Produce one of the standard feeds, in the requested format. + + +my $feed_contents = feeds->make_feed( + feed_type => 'rss', + feed_listing => 'recent_changes' + ); + +Passes additional arguments through to the underlying Wiki::Toolkit::Feed +=cut sub make_feed { my ($self, %args) = @_;
@@ -82,6 +93,41 @@ } }
+=item B<build_feed_for_nodes> +For the given feed type, build a feed from the supplied list of nodes. +Will figure out the feed timestamp from the newest node, and output a + last modified header based on this. + +my @nodes = $wiki->fetch_me_nodes_I_like(); +my $feed_contents = $feed->build_feed_for_nodes("rss", @nodes); +=cut +sub build_feed_for_nodes { + my ($self, $format, @nodes) = @_; + + # Grab our feed maker + my $maker = $self->fetch_maker($format); + + # Find our newest node, so we can use that for the feed timestamp + my $newest_node; + foreach my $node (@nodes) { + if($node->{last_modified}) { + if((!$newest_node) || $node->{last_modified} < $newest_node->{last_modified}) { + $newest_node = $node; + } + } + } + + # Grab the timestamp, and do our header + my $timestamp = $maker->feed_timestamp($newest_node); + + my $feed = "Last-Modified: ".$timestamp."\n\n"; + + # Generate the feed itself + $feed .= $maker->generate_node_list_feed($timestamp, @nodes); + + return $feed; +} + =item B<fetch_maker> For the given feed type, identify and return the maker routine for feeds of that type.
openguides-commits@lists.openguides.org