From 967e0cefb06e0c7d4eae46ad6844380693392881 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 13 Jun 2011 16:29:58 +0200 Subject: import old gitmap to new stargit repo Signed-off-by: franck cuny --- lib/StarGit.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lib/StarGit.pm') diff --git a/lib/StarGit.pm b/lib/StarGit.pm index 161e4a7..72933da 100644 --- a/lib/StarGit.pm +++ b/lib/StarGit.pm @@ -1,10 +1,48 @@ package StarGit; use Dancer ':syntax'; +use StarGit::Graph; + our $VERSION = '0.1'; +set serializer => 'JSON'; + get '/' => sub { template 'index'; }; +get '/graph/local/:name' => sub { + my $name = params->{'name'}; + + my $graph = StarGit::Graph->new( name => $name ); + $graph->neighbors( $name, 1 ); + $graph->remove_leaves(); + + return _finalize($graph); +}; + +get '/graph/query' => sub { + my $language = params->{language}; + + my $graph = StarGit::Graph->new( language => $language ); + $graph->build_from_query(); + + return _finalize($graph); +}; + +get '/graph/attributes' => sub { + my $graph_settings = setting('graph'); + my $attributes = $graph_settings->{attributes}; + return { attributes => $attributes }; +}; + +sub _finalize { + my $graph = shift; + + my @nodes = values %{ $graph->nodes }; + my @edges = values %{ $graph->edges }; + + return { nodes => \@nodes, edges => \@edges, }; +} + true; -- cgit v1.2.3