Author: kake Date: 2012-04-18 12:05:13 +0100 (Wed, 18 Apr 2012) New Revision: 1350
Added: trunk/templates/json_index.tt Modified: trunk/Build.PL trunk/Changes trunk/MANIFEST trunk/t/95_multiple_index.t Log: Fixed the JSON output for action=index
Modified: trunk/Build.PL =================================================================== --- trunk/Build.PL 2012-04-17 22:01:28 UTC (rev 1349) +++ trunk/Build.PL 2012-04-18 11:05:13 UTC (rev 1350) @@ -314,12 +314,14 @@ 'File::Spec::Functions' => 0, 'File::Temp' => 0, 'HTML::Entities' => 0, + 'JSON' => 0, # W::T::P::JSON uses anyway 'LWP::Simple' => 0, 'MIME::Lite' => 0, 'Parse::RecDescent' => 0, $search_module => 0, 'POSIX' => 0, 'Template' => '2.24', # for .lower vmethod + 'Template::Plugin::JSON' => 0, 'Time::Piece' => 0, 'URI::Escape' => 0, 'XML::RSS' => 0, @@ -386,6 +388,7 @@ "delete_password_wrong.tt", "differences.tt", "display_metadata.tt", + "json_index.tt", "metadata.tt", "edit_form.tt", "edit_form_actions.tt",
Modified: trunk/Changes =================================================================== --- trunk/Changes 2012-04-17 22:01:28 UTC (rev 1349) +++ trunk/Changes 2012-04-18 11:05:13 UTC (rev 1350) @@ -22,6 +22,8 @@ will automatically redirect to new-style ones. Added project metadata to Build.PL (#285). Added a basic stylesheet, installed into the static_path directory. + Fixed the JSON output for action=index (using a new dependency on + Template::Plugin::JSON).
0.66 12 April 2012 All templates now have access to the "username" TT variable.
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2012-04-17 22:01:28 UTC (rev 1349) +++ trunk/MANIFEST 2012-04-18 11:05:13 UTC (rev 1350) @@ -45,6 +45,7 @@ templates/error.tt templates/footer.tt templates/header.tt +templates/json_index.tt templates/home_node.tt templates/map_index.tt templates/map_index_leaflet.tt
Modified: trunk/t/95_multiple_index.t =================================================================== --- trunk/t/95_multiple_index.t 2012-04-17 22:01:28 UTC (rev 1349) +++ trunk/t/95_multiple_index.t 2012-04-18 11:05:13 UTC (rev 1350) @@ -1,4 +1,5 @@ use strict; +use JSON; use OpenGuides; use OpenGuides::CGI; use OpenGuides::Test; @@ -16,7 +17,7 @@ plan skip_all => "Test::HTML::Content not available."; }
-plan tests => 15; +plan tests => 18;
my $config = OpenGuides::Test->make_basic_config; my $guide = OpenGuides->new( config => $config ); @@ -105,3 +106,16 @@ qr|dc:titleCategory Pubs and Locale Waddon</dc:title>|, "Page title is correct on RDF version." );
+# Test the JSON version. +$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "json", + return_output => 1 ); +unlike( $output, qr/error/i, "JSON format invocation doesn't cause error." ); + +# Need to strip out the Content-Type: header or the decoder gets confused. +$output =~ s/^Content-Type:.*\n//s; +my $parsed = eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + decode_json( $output ); +}; +ok( !$@, "...and its output looks like JSON." ); +is( scalar @$parsed, 1, "...and has the right number of nodes." );
Added: trunk/templates/json_index.tt =================================================================== --- trunk/templates/json_index.tt (rev 0) +++ trunk/templates/json_index.tt 2012-04-18 11:05:13 UTC (rev 1350) @@ -0,0 +1 @@ +[% USE JSON %][% nodes.json %] \ No newline at end of file
openguides-commits@lists.openguides.org