Author: nick Date: 2008-10-18 15:37:04 +0100 (Sat, 18 Oct 2008) New Revision: 1227
Modified: trunk/lib/ trunk/lib/OpenGuides.pm trunk/lib/OpenGuides/ trunk/lib/OpenGuides/JSON.pm trunk/wiki.cgi Log: Start to support metadata discovery stuff
Property changes on: trunk/lib ___________________________________________________________________ Name: svn:ignore + *.swp .vimrc
Property changes on: trunk/lib/OpenGuides ___________________________________________________________________ Name: svn:ignore + *.swp .vimrc
Modified: trunk/lib/OpenGuides/JSON.pm =================================================================== --- trunk/lib/OpenGuides/JSON.pm 2008-10-18 13:56:37 UTC (rev 1226) +++ trunk/lib/OpenGuides/JSON.pm 2008-10-18 14:37:04 UTC (rev 1227) @@ -60,6 +60,9 @@ $self; }
+=item B<emit_json> +Renders the given node as JSON +=cut sub emit_json { my ( $self, %args ) = @_;
@@ -103,6 +106,14 @@ return $self->json_maker->make_json($data); }
+=item B<output_as_json> +Renders the given arbitary data as JSON +=cut +sub output_as_json { + my ( $self, %args ) = @_; + return $self->json_maker->make_json(%args); +} + sub json_maker { my $self = shift;
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2008-10-18 13:56:37 UTC (rev 1226) +++ trunk/lib/OpenGuides.pm 2008-10-18 14:37:04 UTC (rev 1227) @@ -1002,6 +1002,72 @@ print $output; }
+=item B<show_metadata> + + $guide->show_metadata(); + $guide->show_metadata(type => "category"); + $guide->show_metadata(type => "category", format => "json"); + +Lists all metadata types, or all metadata values of a given +type. Useful for programatically discovering a guide. + +As with other methods, parameters C<return_tt_vars> and +C<return_output> can be used to return these things instead of +printing the output to STDOUT. + +=cut +sub show_metadata { + my ($self, %args) = @_; + my $wiki = $self->wiki; + my $formatter = $wiki->formatter; + + my @values; + my $type; + if($args{"type"}) { + $type = $args{"type"}; + @values = $wiki->store->list_metadata_by_type($args{"type"}); + } else { + $type = "metadata_type"; + @values = $wiki->store->list_metadata_names; + } + + my %tt_vars = ( type => $type, + metadata => @values, + num_results => scalar @values, + not_deletable => 1, + deter_robots => 1, + not_editable => 1 ); + return %tt_vars if $args{return_tt_vars}; + + my $output; + my $content_type; + + if($args{"format"}) { + if($args{"format"} eq "json") { + $content_type = "text/javascript"; + my $json = OpenGuides::JSON->new( wiki => $wiki, + config => $self->config ); + $output = $json->output_as_json( + $type => @values + ); + } + } + unless($output) { + $output = OpenGuides::Template->output( + wiki => $wiki, + config => $self->config, + template=>"metadata.tt", + vars => %tt_vars, + ); + } + return $output if $args{return_output}; + + if($content_type) { + print "Content-type: $content_type\n\n"; + } + print $output; +} + =item B<list_all_versions>
$guide->list_all_versions ( id => "Home Page" );
Modified: trunk/wiki.cgi =================================================================== --- trunk/wiki.cgi 2008-10-18 13:56:37 UTC (rev 1226) +++ trunk/wiki.cgi 2008-10-18 14:37:04 UTC (rev 1227) @@ -188,9 +188,9 @@ print $q->redirect( $redir_target ); } elsif ($action eq 'about') { $guide->display_about(format => $format); - } elsif ($action eq 'metadata' && $q->param("type")) { + } elsif ($action eq 'metadata') { $guide->show_metadata( - type => $q->param("type"), + type => $q->param("type") || "", format => $format, ); } elsif ($action eq 'display') {