summary refs log tree commit diff
diff options
context:
space:
mode:
-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
-rw-r--r--public/css/style.css32
-rw-r--r--views/history.tt21
6 files changed, 101 insertions, 12 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 {
diff --git a/public/css/style.css b/public/css/style.css
index e4c7cf6..3db0caa 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -104,15 +104,15 @@ ul.actions li {
 }
 
 textarea#editor-body {
-  background: #fff;
-  border: 1px solid #ddd;
-  font-size: 1.3em;
-  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
-  line-height: 1.8em;
-  margin: 1em 0 0.4em;
-  padding: 0.5em; /* I don't really like mixing pct & em here… */
-  width: 98%;
-  height: 20em;
+   background: #fff;
+   border: 1px solid #ddd;
+   font-size: 1.3em;
+   font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+   line-height: 1.8em;
+   margin: 1em 0 0.4em;
+   padding: 0.5em; /* I don't really like mixing pct & em here… */
+   width: 98%;
+   height: 20em;
 }
 
 input#editor-submit {
@@ -137,3 +137,17 @@ input#editor-submit {
   -moz-border-radius: 3px;
   -webkit-border-radius: 3px;
 }
+
+#wiki-history {
+   margin-top: 3em;
+}
+
+.history h1 {
+   color: #999;
+   font-weight: normal;
+}
+
+.history h1 strong {
+   color: #000;
+   font-weight: bold;
+}
diff --git a/views/history.tt b/views/history.tt
new file mode 100644
index 0000000..fd8ff92
--- /dev/null
+++ b/views/history.tt
@@ -0,0 +1,21 @@
+<div id="wiki-wrapper" class="history">
+
+  <div id="head">
+    <h1>History for <strong><% title %></strong></h1>
+    <ul class="actions">
+      <li class="minibutton">
+        <a href="/<% title %>" class="action-view-page">View Page</a>
+      </li>
+      <li class="minibutton">
+        <a href="/edit/<% title %>"class="action-edit-page">Edit Page</a>
+      </li>
+    </ul>
+  </div>
+
+  <div id="wiki-history">
+    <% FOREACH version IN versions %>
+       on a <% version.id %>
+    <% END %>
+  </div>
+
+</div>