Skip to content

Commit

Permalink
Implemented basic timeline with the last 10 entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
afilina committed Sep 19, 2011
1 parent a769dc1 commit ddeb7ac
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/gollum/frontend/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ class App < Sinatra::Base
@versions = @page.versions :page => @page_num
mustache :history
end

get '/timeline' do
@name = 'timeline'
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@entries = wiki.entries
mustache :timeline
end

post '/compare/:name' do
@versions = params[:versions] || []
Expand Down
2 changes: 2 additions & 0 deletions lib/gollum/frontend/templates/page.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{{/editable}}
<li class="minibutton"><a href="/history/{{escaped_name}}"
class="action-page-history">Page History</a></li>
<li class="minibutton"><a href="/timeline"
class="action-wiki-history">Wiki History</a></li>
</ul>
{{>searchbar}}
</div>
Expand Down
38 changes: 38 additions & 0 deletions lib/gollum/frontend/templates/timeline.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div id="wiki-wrapper" class="history">
<div id="head">
<h1>{{title}}</h1>
{{>searchbar}}
</div>
<div id="wiki-history">

<table>
<tbody>
{{#commits}}
<tr>
<td class="author">
<a href="javascript:void(0)">
<img src="http://www.gravatar.com/avatar/{{gravatar}}?s=16"
alt="avatar: {{author}}" class="mini-gravatar">
<span class="username">{{author}}</span>
</a>
</td>
<td class="commit-name">
<span class="time-elapsed">{{date}}:</span>&nbsp;
{{message}}
[<a href="/{{page_link}}" title="View page">{{page_name}}</a>]
</td>
</tr>
{{/commits}}

</tbody>
</table>

</div>
<div id="footer">
<ul class="actions">
<!-- only show this button if we have more than 20 revisions -->
<li class="minibutton"><a href="#"
class="action-back-to-top">Back to Top</a></li>
</ul>
</div>
</div>
50 changes: 50 additions & 0 deletions lib/gollum/frontend/views/timeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Precious
module Views
class Timeline < Layout
attr_reader :page, :page_num

def title
"Timeline"
end

def commits
commits = []
@entries.each do |v|
file_name = v.show[0].b_path.split('/').pop()
page_name = Gollum::Page.canonicalize_filename(file_name)
page_link = Gollum::Page.cname(page_name)
commits.push(
{ :id => v.id,
:id7 => v.id[0..6],
:author => v.author.name,
:message => v.message,
:page_name=> page_name,
:page_link=> page_link,
:date => v.committed_date.strftime("%B %d, %Y"),
:gravatar => Digest::MD5.hexdigest(v.author.email) }
)
end

return commits
end

def previous_link
label = "&laquo; Previous"
if @page_num == 1
%(<span class="disabled">#{label}</span>)
else
%(<a href="/timeline?page=#{@page_num-1}" hotkey="h">#{label}</a>)
end
end

def next_link
label = "Next &raquo;"
if @versions.size == Gollum::Page.per_page
%(<a href="/timeline?page=#{@page_num+1}" hotkey="l">#{label}</a>)
else
%(<span class="disabled">#{label}</span>)
end
end
end
end
end
12 changes: 12 additions & 0 deletions lib/gollum/wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ def tree_list(ref)
[]
end
end

# Fill an array with a list of entries in chronological order.
#
# max_count - The number of entries to retrieve.
#
# Returns a flat Array of commit entries.
def entries(max_count = 10)
options = {:pretty => 'raw', :max_count => max_count}
args = [@page_file_dir]
log = repo.git.native "log", options, "--", args
return Grit::Commit.list_from_string(repo, log)
end

# Creates a reverse diff for the given SHAs on the given Gollum::Page.
#
Expand Down

0 comments on commit ddeb7ac

Please sign in to comment.