Author: dom Date: 2007-06-20 19:54:54 +0100 (Wed, 20 Jun 2007) New Revision: 1096
Added: trunk/t/78_about.t Modified: trunk/MANIFEST trunk/lib/OpenGuides.pm Log: Add OpenSearch description (references #180)
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2007-06-20 16:34:42 UTC (rev 1095) +++ trunk/MANIFEST 2007-06-20 18:54:54 UTC (rev 1096) @@ -141,5 +141,6 @@ t/75_revert_user.t t/76_detect_spam.t t/77_send_email.t +t/78_about.t t/templates/15_test.tt wiki.cgi
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2007-06-20 16:34:42 UTC (rev 1095) +++ trunk/lib/OpenGuides.pm 2007-06-20 18:54:54 UTC (rev 1096) @@ -1123,6 +1123,14 @@ print $output; }
+=item B<display_about> + + print $guide->display_about(format => "rdf"); + +Displays static 'about' information in various format. Defaults to HTML. + +=cut + sub display_about { my ($self, %args) = @_;
@@ -1188,8 +1196,28 @@ </Project>
</rdf:RDF>}; - } - else { + } elsif ($args{format} && $args{format} eq 'opensearch') { + my $site_name = $self->config->site_name; + my $search_url = $self->config->script_url . 'search.cgi'; + my $contact_email = $self->config->contact_email; + $output = qq{Content-Type: application/opensearchdescription+xml; charset=utf-8 + +<?xml version="1.0" encoding="UTF-8"?> + +<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> + <ShortName>$site_name</ShortName> + <Description>Search the $site_name</Description> + <Tags>$site_name</Tags> + <Contact>$contact_email</Contact> + <Url type="application/atom+xml" + template="$search_url?search={searchTerms};format=atom"/> + <Url type="application/rss+xml" + template="$search_url?search={searchTerms};format=rss"/> + <Url type="text/html" + template="$search_url?search={searchTerms}"/> + <Query role="example" searchTerms="pubs"/> +</OpenSearchDescription>}; + } else { my $site_name = $self->config->{site_name}; my $script_name = $self->config->{script_name}; $output = qq{Content-Type: text/html; charset=utf-8
Added: trunk/t/78_about.t =================================================================== --- trunk/t/78_about.t (rev 0) +++ trunk/t/78_about.t 2007-06-20 18:54:54 UTC (rev 1096) @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; +use OpenGuides; +use OpenGuides::Test; + +plan tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +$config->site_name('My site'); +$config->contact_email('me@example.com'); +my $guide = OpenGuides->new(config => $config); + +my $output = $guide->display_about(return_output => 1); + +like( $output, qr|My site</a></h1>.*<h2>is powered by|ms, + "HTML about text is displayed, including the site name" ); + +$output = $guide->display_about(return_output => 1, + format => "opensearch" + ); + +like( $output, qr|OpenSearchDescription.*<Tags>My site</Tags>.*<Contact>me@example.com</Contact>|ms, + "OpenSearch about text is displayed, including the site name and contact"); + +$output = $guide->display_about(return_output => 1, + format => "rdf" + ); + +like( $output, qr|<Project rdf:ID="OpenGuides">|ms, + "RDF about text is displayed");
openguides-commits@lists.openguides.org