Skip to content

Commit

Permalink
bookmarkable compare urls
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Aug 12, 2010
1 parent 8c09e26 commit 6649dd4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
24 changes: 18 additions & 6 deletions lib/gollum/frontend/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,24 @@ class App < Sinatra::Base
end

post '/compare/:name' do
@name = params[:name]
@versions = params[:versions]
wiki = Gollum::Wiki.new($path)
@page = wiki.page(@name)
diffs = wiki.repo.diff(@versions[1], @versions[0], @page.path)
@diff = diffs.first
@versions = params[:versions] || []
if @versions.size < 2
redirect "/history/#{params[:name]}"
else
redirect "/compare/%s/%s...%s" % [
params[:name],
@versions.last,
@versions.first]
end
end

get '/compare/:name/:version_list' do
@name = params[:name]
@versions = params[:version_list].split(/\.{2,3}/)
wiki = Gollum::Wiki.new($path)
@page = wiki.page(@name)
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
@diff = diffs.first
mustache :compare
end

Expand Down
8 changes: 6 additions & 2 deletions lib/gollum/frontend/public/javascript/gollum.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ $(function(){

$('ul.inline-tabs').tabs()

var selectedRevisions = []
var selectedRevisions = [];
var baseCompareUrl = null

$('form#history input[type=checkbox]').change(function() {
var id = $(this).val()
Expand All @@ -225,7 +226,10 @@ $(function(){
$('form#history input[type=submit]').attr('disabled', true)

if (selectedRevisions.length == 2) {
$('form#history input[type=submit]').attr('disabled', false)
if(!baseCompareUrl) baseCompareUrl = $('form#history').attr('action')
var compareUrl = baseCompareUrl + "/" + selectedRevisions[1] + '...' + selectedRevisions[0]
//$('form#history').attr('action', compareUrl)
$('form#history input[type=submit]').attr('disabled', false).attr('method', 'get')
var on = false
$('form#history tr.commit').each(function() {
if (on) { $(this).addClass("selected") }
Expand Down
4 changes: 2 additions & 2 deletions lib/gollum/frontend/views/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def path
end

def before
@versions[1][0..6]
@versions[0][0..6]
end

def after
@versions[0][0..6]
@versions[1][0..6]
end

def lines
Expand Down

0 comments on commit 6649dd4

Please sign in to comment.