summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/ballet.pm14
-rw-r--r--lib/ballet/Git.pm24
-rw-r--r--lib/ballet/Page.pm25
3 files changed, 62 insertions, 1 deletions
diff --git a/lib/ballet.pm b/lib/ballet.pm
index 400e372..10e3a1f 100644
--- a/lib/ballet.pm
+++ b/lib/ballet.pm
@@ -1,10 +1,22 @@
 package ballet;
+
+use 5.010;
+
 use Dancer ':syntax';
+use ballet::Git;
 
 our $VERSION = '0.1';
 
+my $git = ballet::Git->new( wiki_path => setting('wiki_path') );
+
 get '/' => sub {
-    template 'index';
+    wiki_page('Home');
 };
 
+sub wiki_page {
+    my $page_name = shift;
+    my $content = $git->find_page($page_name, 'master');
+    return $content;
+}
+
 true;
diff --git a/lib/ballet/Git.pm b/lib/ballet/Git.pm
new file mode 100644
index 0000000..6ade622
--- /dev/null
+++ b/lib/ballet/Git.pm
@@ -0,0 +1,24 @@
+package ballet::Git;
+
+use Mouse;
+use Git::Repository;
+
+with 'ballet::Page';
+
+has wiki_path => (
+    is       => 'ro',
+    isa      => 'Str',
+    required => 1,
+);
+
+has git_repo => (
+    is      => 'rw',
+    isa     => 'Git::Repository',
+    lazy    => 1,
+    default => sub {
+        my $self = shift;
+        Git::Repository->new( git_dir => $self->wiki_path ),;
+    },
+);
+
+1;
diff --git a/lib/ballet/Page.pm b/lib/ballet/Page.pm
new file mode 100644
index 0000000..7eafa90
--- /dev/null
+++ b/lib/ballet/Page.pm
@@ -0,0 +1,25 @@
+package ballet::Page;
+
+use Mouse::Role;
+
+sub find_page {
+    my ($self, $name, $version) = @_;
+    $version ||= 'master';
+    my @output = $self->git_repo->run('ls-tree', $version);
+    my @page =  grep {$_ =~ /$name\./} @output;
+    if (!@page) {
+        die "blablabla";
+    }
+
+    return $self->_format_page(shift @page);
+    
+}
+
+sub _format_page {
+    my ($self, $blob) = @_;
+    my @line = split (/\s/, $blob);
+    my @content = $self->git_repo->run('cat-file', '-p', $line[2]);
+    return join("\n", @content);
+}
+
+1;