Changeset 817


Ignore:
Timestamp:
Jul 6, 2006, 5:09:18 PM (15 years ago)
Author:
nick
Message:

Shift the content type method
Add mini feed method
Start to do urls, names etc for feeds properly
New tests

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r814 r817  
    682682                                    );
    683683
    684     my $content_type;
    685    
    686     if ($feed_type eq 'rss') {
    687         $content_type = "application/rdf+xml";
    688     }
    689     elsif ($feed_type eq 'atom') {
    690         $content_type = "application/atom+xml";
    691     }
    692     else {
    693         croak "Unknown feed type given: $feed_type";
    694     }
     684    my $content_type = $feed->default_content_type($feed_type);
    695685
    696686    return ($feed, $content_type);
  • trunk/lib/OpenGuides/Feed.pm

    r813 r817  
    104104sub build_feed_for_nodes {
    105105    my ($self, $format, @nodes) = @_;
     106    return $self->render_feed_for_nodes($format, undef, 1, @nodes);
     107}
     108=item B<build_mini_feed_for_nodes>
     109For the given feed type, build a mini feed (name and distance) from the
     110 supplied list of nodes.
     111Will figure out the feed timestamp from the newest node, and output a
     112 last modified header based on this.
     113
     114my @nodes = $wiki->search_near_here();
     115my $feed_contents = $feed->build_mini_feed_for_nodes("rss", @nodes);
     116=cut
     117sub build_mini_feed_for_nodes {
     118    my ($self, $format, @nodes) = @_;
     119    return $self->render_feed_for_nodes($format, undef, 0, @nodes);
     120}
     121
     122=item B<render_feed_for_nodes>
     123Normally internal method to perform the appropriate building of a feed
     124 based on a list of nodes.
     125=cut
     126sub render_feed_for_nodes {
     127    my ($self, $format, $html_url, $is_full, @nodes) = @_;
    106128
    107129    # Grab our feed maker
     
    124146
    125147    # Generate the feed itself
    126     $feed .= $maker->generate_node_list_feed($timestamp, @nodes);
     148    if($is_full) {
     149        $feed .= $maker->generate_node_list_feed($timestamp, @nodes);
     150    } else {
     151        $feed .= $maker->generate_node_name_distance_feed($timestamp, @nodes);
     152    }
    127153
    128154    return $feed;
     155}
     156
     157=item B<default_content_type>
     158For the given feed type, return the default content type for that feed.
     159
     160my $content_type = $feed->default_content_type("rss");
     161=cut
     162sub default_content_type {
     163    my ($self,$feed_type) = @_;
     164
     165    my $content_type;
     166
     167    if ($feed_type eq 'rss') {
     168        $content_type = "application/rdf+xml";
     169    }
     170    elsif ($feed_type eq 'atom') {
     171        $content_type = "application/atom+xml";
     172    }
     173    else {
     174        croak "Unknown feed type given: $feed_type";
     175    }
     176
     177    return $content_type;
    129178}
    130179
     
    162211            site_description    => $self->{site_description},
    163212            make_node_url       => $self->{make_node_url},
    164             recent_changes_link => $self->{config}->script_url . '?action=rc',
     213            html_equiv_link    => $self->{config}->script_url . '?action=rc',
    165214            atom_link           => $self->{config}->script_url . '?action=rc&format=atom',
    166215            software_name       => 'OpenGuides',
     
    183232            site_description    => $self->{site_description},
    184233            make_node_url       => $self->{make_node_url},
    185             recent_changes_link => $self->{config}->script_url . '?action=rc',
     234            html_equiv_link    => $self->{config}->script_url . '?action=rc',
    186235            software_name       => 'OpenGuides',
    187236            software_homepage   => 'http://openguides.org/',
  • trunk/t/22_feed_recent_changes.t

    r808 r817  
    2222# Which feed types do we test?
    2323my @feed_types = qw( rss atom );
    24 plan tests => 8 * scalar @feed_types;
     24plan tests => 9 * scalar @feed_types;
    2525
     26my %content_types = (rss=>'application/rdf+xml', atom=>'application/atom+xml');
    2627
    2728foreach my $feed_type (@feed_types) {
     
    5051    my $feed = OpenGuides::Feed->new( wiki   => $wiki,
    5152                                      config => $config );
     53    is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" );
    5254
    5355    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
Note: See TracChangeset for help on using the changeset viewer.