summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ballet.pm18
-rw-r--r--lib/ballet/Commit.pm36
-rw-r--r--lib/ballet/Git.pm1
-rw-r--r--lib/ballet/Page.pm5
4 files changed, 57 insertions, 3 deletions
diff --git a/lib/ballet.pm b/lib/ballet.pm
index d48a3b7..4be1acc 100644
--- a/lib/ballet.pm
+++ b/lib/ballet.pm
@@ -3,13 +3,23 @@ package ballet;
 use 5.010;
 
 use Dancer ':syntax';
+#use Dancer::Plugin::Auth::Twitter;
 
 use ballet::Git;
 
 our $VERSION = '0.1';
 
+#auth_twitter_init();
+
 my $git = ballet::Git->new( wiki_path => setting('wiki_path') );
 
+# before sub {
+#     return if request->path =~ m{/auth/twitter/callback};
+#     if (not session('twitter_user')) {
+#         redirect auth_twitter_authenticate_url;
+#     }
+# };
+
 get '/' => sub { wiki_page('Home'); };
 
 get '/history/*' => sub {
@@ -17,7 +27,8 @@ get '/history/*' => sub {
 
     debug("looking history for $page_name");
 
-    my $history = $git->find_history($page_name, 'master');
+    my $versions = $git->find_history( $page_name, 'master' );
+    template 'history', {versions => $versions, title => 'Home'};
 };
 
 get '/edit/*' => sub {
@@ -49,14 +60,15 @@ sub wiki_page {
     my $page_name = shift;
 
     my $content = $git->find_page( $page_name, 'master' );
-    $content = $git->convert('textile', $content);
+    $content = $git->convert( 'textile', $content );
 
     template 'page',
       {
         title   => $page_name,
         author  => 'franck',
         date    => '10/10/10',
-        content => $content
+        content => $content,
+#        user    => session('twitter_user')->{'screen_name'},
       };
 }
 
diff --git a/lib/ballet/Commit.pm b/lib/ballet/Commit.pm
new file mode 100644
index 0000000..2836714
--- /dev/null
+++ b/lib/ballet/Commit.pm
@@ -0,0 +1,36 @@
+package ballet::Commit;
+
+use Mouse::Role;
+
+sub create_commits {
+    my ( $self, $logs_lines ) = @_;
+
+    my @commits;
+
+    while (scalar @$logs_lines) {
+        my $id     = shift @$logs_lines;
+        my $author = shift @$logs_lines;
+        my $date   = shift @$logs_lines;
+
+        shift @$logs_lines;
+
+        my $msg      = shift @$logs_lines;
+        my $messages = [];
+
+        while ( length $msg > 0) {
+            push @$messages, $msg;
+            $msg = shift @$logs_lines;
+        }
+
+        push @commits,
+          {
+            id      => $id,
+            author  => $author,
+            date    => $date,
+            message => join( "\n", @$messages )
+          };
+    }
+    \@commits;
+}
+
+1;
diff --git a/lib/ballet/Git.pm b/lib/ballet/Git.pm
index 546cdaa..8daa9d3 100644
--- a/lib/ballet/Git.pm
+++ b/lib/ballet/Git.pm
@@ -6,6 +6,7 @@ use Git::Repository;
 
 with 'ballet::Page';
 with 'ballet::Markup';
+with 'ballet::Commit';
 
 has wiki_path => (
     is       => 'ro',
diff --git a/lib/ballet/Page.pm b/lib/ballet/Page.pm
index 3d3a097..e369e4d 100644
--- a/lib/ballet/Page.pm
+++ b/lib/ballet/Page.pm
@@ -33,6 +33,11 @@ sub update_page {
 
 sub find_history {
     my ($self, $page_name, $version) = @_;
+    $version ||= 'master';
+
+    my @logs_lines = $self->git_repo->run(log => $version, '--', $page_name.'.md');
+    my $commits = $self->create_commits(\@logs_lines);
+    return $commits;
 }
 
 sub _format_page {