First attempt at a global latest changes overview.

- uses a wiki_options entry named :latest_changes_count instead of a
  constant
- lists modified pages with links
This commit is contained in:
Étienne Charignon
2014-04-10 11:49:38 -07:00
parent 1148d29439
commit 374f8f2f69
5 changed files with 184 additions and 0 deletions
+7
View File
@@ -351,6 +351,13 @@ module Precious
end
end
get '/latest_changes' do
@wiki = wiki_new
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
@versions = @wiki.latest_changes({:max_count => max_count})
mustache :latest_changes
end
post '/compare/*' do
@file = params[:splat].first
@versions = params[:versions] || []
@@ -0,0 +1,39 @@
<div id="wiki-wrapper" class="history">
<div id="head">
<h1><strong>{{title}}</strong></h1>
<ul class="actions">
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
class="action-view-page">Home</a></li>
</ul>
</div>
<div id="wiki-history">
<fieldset>
<table>
<tbody>
{{#versions}}
<tr>
<td class="author">
{{>author_template}}
</td>
<td class="commit-name">
<span class="time-elapsed" title="{{date_full}}">{{date}}:</span>&nbsp;
{{message}}
[{{id7}}]
{{#files}}
<br>
<a href="{{link}}">{{file}}</a>
{{/files}}
</td>
</tr>
{{/versions}}
</tbody>
</table>
</fieldset>
</div>
<div id="footer">
</div>
</div>
+3
View File
@@ -34,6 +34,9 @@ Mousetrap.bind(['e'], function( e ) {
<li class="minibutton jaws">
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
class="action-page-history">History</a></li>
<li class="minibutton jaws">
<li class="minibutton"><a href="{{base_url}}/latest_changes"
class="action-page-history">Latest Changes</a></li>
{{/page_exists}}
</ul>
</div>
+90
View File
@@ -0,0 +1,90 @@
module Precious
module Views
class LatestChanges < Layout
attr_reader :wiki
def title
"Latest Changes (Globally)"
end
def versions
i = @versions.size + 1
@versions.map do |v|
i -= 1
{ :id => v.id,
:id7 => v.id[0..6],
:num => i,
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
:date => v.authored_date.strftime("%B %d, %Y"),
:gravatar => Digest::MD5.hexdigest(v.author.email.strip.downcase),
:identicon => self._identicon_code(v.author.email),
:date_full => v.authored_date,
:files => v.stats.files.map { |f,*rest|
page_path = extract_renamed_path_destination(f)
page_path = remove_page_extentions(page_path)
{ :file => f,
:link => "#{page_path}/#{v.id}"
}
}
}
end
end
def remove_page_extentions(page_path)
Gollum::Markup.formats.values.each do |format|
page_path = page_path.gsub(/\.#{format[:regexp]}$/, '')
end
return page_path
end
def extract_renamed_path_destination(file)
return file.gsub(/{.* => (.*)}/, '\1').gsub(/.* => (.*)/, '\1')
end
# http://stackoverflow.com/questions/9445760/bit-shifting-in-ruby
def left_shift(int, shift)
r = ((int & 0xFF) << (shift & 0x1F)) & 0xFFFFFFFF
# 1>>31, 2**32
(r & 2147483648) == 0 ? r : r - 4294967296
end
def string_to_code(string)
# sha bytes
b = [Digest::SHA1.hexdigest(string)[0, 20]].pack('H*').bytes.to_a
# Thanks donpark's IdenticonUtil.java for this.
# Match the following Java code
# ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) |
# ((b[2] & 0xFF) << 8) | (b[3] & 0xFF)
return left_shift(b[0], 24) |
left_shift(b[1], 16) |
left_shift(b[2], 8) |
b[3] & 0xFF
end
def _identicon_code(blob)
string_to_code blob + @request.host
end
def use_identicon
@wiki.user_icons == 'identicon'
end
def partial(name)
if name == :author_template
self.class.partial("history_authors/#{@wiki.user_icons}")
else
super
end
end
def previous_link
end
def next_link
end
end
end
end
+45
View File
@@ -0,0 +1,45 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
require File.expand_path '../../lib/gollum/views/latest_changes', __FILE__
context "Precious::Views::LatestChanges" do
include Rack::Test::Methods
def app
Precious::App
end
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {:latest_changes_count => 10})
end
test "displays_latest_changes" do
get('/latest_changes')
body = last_response.body
assert body.include?('<span class="username">Charles Pence</span>'), "/latest_changes should include the Author Charles Pence"
assert body.include?('60f12f4'), "/latest_changes should include the :latest_changes_count commit"
assert !body.include?('0ed8cbe'), "/latest_changes should not include more than latest_changes_count commits"
assert body.include?('<a href="Data-Two.csv/874f597a5659b4c3b153674ea04e406ff393975e">Data-Two.csv</a>'), "/latest_changes include links to modified files in #{body}"
assert body.include?('<a href="Hobbit/874f597a5659b4c3b153674ea04e406ff393975e">Hobbit.md</a>'), "/latest_changes should include links to modified pages in #{body}"
assert body.include?('<a href="My-Precious/60f12f4254f58801b9ee7db7bca5fa8aeefaa56b">My-&lt;b&gt;Precious.md =&gt; My-Precious.md</a>'), "/latest_changes should indicate renaming action in #{body}"
end
test "extract destination file name in case of path renaming" do
view = Precious::Views::LatestChanges.new
assert_equal "newDirectoryName/fileName.md", view.extract_renamed_path_destination("{oldDirectoryName => newDirectoryName}/fileName.md")
end
test "remove page extentions" do
view = Precious::Views::LatestChanges.new
assert_equal "page", view.remove_page_extentions("page.wiki")
assert_equal "page-wiki", view.remove_page_extentions("page-wiki.md")
assert_equal "file.any_extention", view.remove_page_extentions("file.any_extention")
end
teardown do
FileUtils.rm_rf(@path)
end
end