requires 'Sub::Exporter';
requires 'Syntax::Highlight::Engine::Kate';
requires 'Sys::Hostname';
-requires 'XML::Atom';
-requires 'XML::RSS';
-requires 'XML::OPML::SimpleGen';
test_requires 'Test::More' => '0.88';
test_requires 'Test::utf8' => '0.02';
use Moose;
use Moose::Autobox;
-
+use DateTime;
use Sys::Hostname qw/hostname/;
use XML::OPML::SimpleGen;
my $opml = XML::OPML::SimpleGen->new();
- $opml->head(title => lc(hostname()) . ' - ' . blessed($c)->config->{name});
-
- for my $repos ( $c->model()->repositories->flatten ) {
- $opml->insert_outline(
- text => $repos->name. ' - '. $repos->description,
- xmlUrl => $c->uri_for_action('/repository/rss', [$repos->name])->as_string,
- );
- }
+ $c->stash(
+ title => lc(hostname()) . ' - ' . blessed($c)->config->{name},
+ Repositories => $c->model()->repositories,
+ now => DateTime->now,
+ template => 'opml.tt2',
+ no_wrapper => 1,
+ );
- $c->response->body($opml->as_string);
$c->response->content_type('application/rss');
}
=cut
sub atom : Chained('find') Args(0) {
- my($self, $c) = @_;
-
- my $feed = XML::Atom::Feed->new;
-
- my $host = lc hostname();
- $feed->title($host . ' - ' . Gitalist->config->{name});
- $feed->updated(~~DateTime->now);
+ my ($self, $c) = @_;
- my $repository = $c->stash->{Repository};
- my %logargs = (
- sha1 => $repository->head_hash,
- count => Gitalist->config->{paging}{log} || 25,
- );
+ my $host = lc hostname();
+ $c->stash(
+ title => $host . ' - ' . Gitalist->config->{name},
+ updated => DateTime->now
+ );
- my $mk_title = $c->stash->{short_cmt};
- for my $commit ($repository->list_revs(%logargs)) {
- my $entry = XML::Atom::Entry->new;
- $entry->title( $mk_title->($commit->comment) );
- $entry->id($c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]));
- # XXX FIXME Needs work ...
- $entry->content($commit->comment);
- $feed->add_entry($entry);
- }
+ my $repository = $c->stash->{Repository};
+ my %logargs = (
+ sha1 => $repository->head_hash,
+ count => Gitalist->config->{paging}{log} || 25,
+ );
- $c->response->body($feed->as_xml);
- $c->response->content_type('application/atom+xml');
+ my @revs;
+ my $mk_title = $c->stash->{short_cmt};
+ for my $commit ($repository->list_revs(%logargs)) {
+ my $entry = {};
+ $entry->{title} = $mk_title->($commit->comment);
+ $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]);
+ # XXX FIXME Needs work ...
+ $entry->{content} = $commit->comment;
+ push(@revs, $entry);
+ }
+ $c->stash(
+ Commits => \@revs,
+ no_wrapper => 1,
+ );
+ $c->response->content_type('application/atom+xml');
}
=head2 rss
my $repository = $c->stash->{Repository};
- my $rss = XML::RSS->new(version => '2.0');
- $rss->channel(
+ $c->stash(
title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
- link => $c->uri_for_action('/repository/summary', [$repository->name]),
language => 'en',
- description => $repository->description,
pubDate => DateTime->now,
lastBuildDate => DateTime->now,
+ no_wrapper => 1,
);
my %logargs = (
count => Gitalist->config->{paging}{log} || 25,
# ($c->req->param('f') ? (file => $c->req->param('f')) : ())
);
+ my @revs;
my $mk_title = $c->stash->{short_cmt};
for my $commit ($repository->list_revs(%logargs)) {
# XXX FIXME Needs work ....
- $rss->add_item(
+ push(@revs, {
title => $mk_title->($commit->comment),
permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]),
description => $commit->comment,
- );
+ });
}
-
- $c->response->body($rss->as_string);
+ $c->stash(Commits => \@revs);
$c->response->content_type('application/rss+xml');
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<opml version="1.1">
+ <body>[% count = 1 %]
+ [% FOR Repository = Repositories %]
+ <outline id="[% count %]"
+ description=""
+ text="[% Repository.name | html_entity %] - [% Repository.description | html_entity %]"
+ title=""
+ type="rss"
+ version="RSS"
+ xmlUrl="[% c.uri_for_action('/repository/rss', [ Repository.name ])%]" />
+ [% SET count = count + 1; END %]
+ </body>
+ <head>
+ <dateCreated>[% now %]</dateCreated>
+ <dateModified>[% now %]</dateModified>
+ <title>[% title | html_entity %]</title>
+ </head>
+</opml>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://purl.org/atom/ns#">
+ <title>[% title | html_entity %]</title>
+ <modified>[% updated %]</modified>
+ [% FOREACH Commit = Commits %]
+ <entry>
+ <title>[% Commit.title | html_entity %]</title>
+ <id>[% Commit.id %]</id>
+ <content mode="xml">
+ <div xmlns="http://www.w3.org/1999/xhtml">[% Commit.content | html_entity %]</div>
+ </content>
+ </entry>
+ [% END %]
+</feed>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">
+
+<channel>
+<title>[% title | html_entity %]</title>
+<link>[% c.uri_for_action('/repository/summary', [Repository.name]) %]</link>
+<description>[% Repository.description | html_entity %]</description>
+<language>[% lang %]</language>
+<pubDate>[% pubDate %]</pubDate>
+<lastBuildDate>[% lastBuildDate %]</lastBuildDate>
+[% FOREACH Commit = Commits %]
+<item>
+<title>[% Commit.title | html_entity %]</title>
+<description>[% Commit.description | html_entity %]</description>
+<guid isPermaLink="true">[% Commit.permaLink %]</guid>
+</item>
+[% END %]
+</channel>
+</rss>
my $res = request('/repo1/atom');
ok $res->is_success;
-
+is $res->content_type, 'application/atom+xml';
TODO: {
local $TODO = "Does not work yet. Need similar info to RSS feed";
like $res->content, qr{link>http://localhost/repo1</link};
my $res = request('/opml');
ok $res->is_success;
+is $res->content_type, 'application/rss';
like $res->content, qr{Gitalist</title>};
like $res->content, qr{xmlUrl="http://localhost/bare.git/rss"};
like $res->content, qr{text="repo1 - some test repository"};
my $res = request('/repo1/rss');
ok $res->is_success;
-
+is $res->content_type, 'application/rss+xml';
like $res->content, qr{link>http://localhost/repo1</link};
like $res->content, qr{description>some test repository</description};
like $res->content, qr{title>add dir1/file2</title};