diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 7eb88f750..0b7a9bac1 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -107,17 +107,37 @@ class WikiController < ApplicationController if request.post? @versions = params[:versions] || [] if @versions.size < 2 - redirect_to history_project_wiki_path(@project, CGI.escape(@name)) + if @name + redirect_to history_project_wiki_path(@project, CGI.escape(@name)) + else + redirect_to history_project_wiki_index_path(@project) + end else - redirect_to compare_versions_project_wiki_path(@project, CGI.escape(@name), + if @name + redirect_to compare_versions_project_wiki_path(@project, CGI.escape(@name), sprintf('%s...%s', @versions.last, @versions.first)) + else + redirect_to compare_versions_project_wiki_index_path(@project, + sprintf('%s...%s', @versions.last, @versions.first)) + end end elsif request.get? @versions = params[:versions].split(/\.{2,3}/) - @page = @wiki.page(@name) - diffs = @wiki.repo.diff(@versions.first, @versions.last, @page.path) - @diff = diffs.first - @helper = WikiHelper::CompareHelper.new(@diff, @versions) + if @versions.size < 2 + if @name + redirect_to history_project_wiki_path(@project, CGI.escape(@name)) + else + redirect_to history_project_wiki_index_path(@project) + return + end + end + if @name + page = @wiki.page(@name) + @diff = @wiki.repo.diff(@versions.first, @versions.last, page.path).first + @diffs = [@diff] + else + @diffs = @wiki.repo.diff(@versions.first, @versions.last) + end render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -158,11 +178,14 @@ class WikiController < ApplicationController end def history - @name = params['id'] - if @page = @wiki.page(@name) - @versions = @page.versions#(:page => params['page'], :per_page => 25)#.paginate :page => params[:page] #try to use will_paginate + if @name = params['id'] + if @page = @wiki.page(@name) + @versions = @page.versions(:per_page => 1000000)#(:page => params['page'], :per_page => 25)#.paginate :page => params[:page] #try to use will_paginate + else + redirect_to :back + end else - redirect_to :back + @versions = @wiki.log(:per_page => 100000) end end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index b28a37396..0be57da56 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -1,89 +1,19 @@ module WikiHelper - class CompareHelper - def initialize(diff, versions) - @diff = diff - @versions = versions + def revert_path(project, first, second, name) + if name + revert_page_project_wiki_path(project, CGI.escape(name), first, second) + else + revert_page_project_wiki_index_path(project, first, second) end + end - def before - @versions[0][0..6] + def compare_path(project, name) + if name + compare_project_wiki_path(@project, CGI.escape(name)) + else + compare_project_wiki_index_path(@project) end - - def after - @versions[1][0..6] - end - - def lines - lines = [] - @diff.diff.split("\n")[2..-1].each do |line| - lines << { :line => line, - :class => line_class(line), - :ldln => left_diff_line_number(line), - :rdln => right_diff_line_number(line) } - end if @diff - lines - end - - def show_revert - !@message - end - - private - - def line_class(line) - if line =~ /^@@/ - 'gc' - elsif line =~ /^\+/ - 'gi' - elsif line =~ /^\-/ - 'gd' - else - '' - end - end - - @left_diff_line_number = nil - def left_diff_line_number(line) - if line =~ /^@@/ - m, li = *line.match(/\-(\d+)/) - @left_diff_line_number = li.to_i - @current_line_number = @left_diff_line_number - ret = '...' - elsif line[0] == ?- - ret = @left_diff_line_number.to_s - @left_diff_line_number += 1 - @current_line_number = @left_diff_line_number - 1 - elsif line[0] == ?+ - ret = ' ' - else - ret = @left_diff_line_number.to_s - @left_diff_line_number += 1 - @current_line_number = @left_diff_line_number - 1 - end - ret - end - - @right_diff_line_number = nil - def right_diff_line_number(line) - if line =~ /^@@/ - m, ri = *line.match(/\+(\d+)/) - @right_diff_line_number = ri.to_i - @current_line_number = @right_diff_line_number - ret = '...' - elsif line[0] == ?- - ret = ' ' - elsif line[0] == ?+ - ret = @right_diff_line_number.to_s - @right_diff_line_number += 1 - @current_line_number = @right_diff_line_number - 1 - else - ret = @right_diff_line_number.to_s - @right_diff_line_number += 1 - @current_line_number = @right_diff_line_number - 1 - end - ret - end end def gravatar_url(email) diff --git a/app/views/wiki/_compare.html.haml b/app/views/wiki/_compare.html.haml index b7e76862c..9c07a15a2 100644 --- a/app/views/wiki/_compare.html.haml +++ b/app/views/wiki/_compare.html.haml @@ -1,20 +1,25 @@ #compare-content - - if action_name != 'revert' + - if action_name != 'revert' %ul.actions %li.minibutton - = form_tag revert_page_project_wiki_path(@project, escaped_name, @helper.before, @helper.after), + = form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name), :name => "gollum-revert", :id => "gollum-revert-form" do = link_to t("layout.wiki.revert_changes"), '#', :class => "gollum-revert-button" - .data.highlight - %table{:cellpadding => "0", :cellspacing => "0"} - - @helper.lines.each do |line| - %tr - %td.line_numbers= line[:ldln] - %td.line_numbers= line[:rdln] - %td - %pre - %div{:class => line[:class]}= line[:line] + = render :partial => 'diff_data', :collection => @diffs, :as => :diff + .spacer + -# if @name + .data.highlight + %table{:cellpadding => "0", :cellspacing => "0"} + - @helper.lines.each do |line| + %tr + %td.line_numbers= line[:ldln] + %td.line_numbers= line[:rdln] + %td + %pre + %div{:class => line[:class]}= line[:line] + -# else + = debug @diffs #gollum-footer %ul.actions diff --git a/app/views/wiki/_diff_data.html.haml b/app/views/wiki/_diff_data.html.haml new file mode 100644 index 000000000..c5981d401 --- /dev/null +++ b/app/views/wiki/_diff_data.html.haml @@ -0,0 +1,6 @@ +.blob_header + .size= h(diff.a_path) + .clear + +.diff_data.highlight + = render_diff(diff) diff --git a/app/views/wiki/_history.html.haml b/app/views/wiki/_history.html.haml index 0df403266..c95db5291 100644 --- a/app/views/wiki/_history.html.haml +++ b/app/views/wiki/_history.html.haml @@ -4,7 +4,7 @@ = link_to t("layout.wiki.compare_revisions"), "javascript:void(0);", :class => "action-compare-revision" - = form_tag compare_project_wiki_path(@project, escaped_name), :name => "compare-versions", :id => "version-form" do + = form_tag compare_path(@project, @name), :name => "compare-versions", :id => "version-form" do %fieldset %table %tbody @@ -20,7 +20,10 @@ %span.time-elapsed= "#{l v.committed_date.to_date, :format => :long}:"   = v.message - = raw "[#{link_to v.id[0..6], versioned_project_wiki_path(@project, escaped_name, v.id), :title => t("layout.wiki.view_commit")}]" + - if @name + = raw "[#{link_to v.id[0..6], versioned_project_wiki_path(@project, escaped_name, v.id), :title => t("layout.wiki.view_commit")}]" + - else + = "[#{v.id[0..6]}]" #gollum-footer %ul.actions diff --git a/app/views/wiki/compare.html.haml b/app/views/wiki/compare.html.haml index 659dd6ea9..45c3687cc 100644 --- a/app/views/wiki/compare.html.haml +++ b/app/views/wiki/compare.html.haml @@ -7,18 +7,23 @@ %ul.wat-cf %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li{:class => (!@name and action_name == 'compare') ? 'active' : ''} + = link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content #wiki-wrapper.inner.compare #head %h1.title - = t("layout.wiki.history_for") - %strong= @name + - if @name + = t("layout.wiki.history_for") + %strong= @name + - else + = t("layout.wiki.wiki_history") %ul.actions - %li.minibutton= link_to t("layout.wiki.back_to_history"), history_project_wiki_path(@project, escaped_name) + %li.minibutton= link_to t("layout.wiki.back_to_history"), + @name ? history_project_wiki_path(@project, escaped_name) : history_project_wiki_index_path(@project) = render :partial => 'searchbar' #wiki-content diff --git a/app/views/wiki/edit.html.haml b/app/views/wiki/edit.html.haml index c25d92f91..d2c2e3618 100644 --- a/app/views/wiki/edit.html.haml +++ b/app/views/wiki/edit.html.haml @@ -7,7 +7,7 @@ %ul.wat-cf %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content diff --git a/app/views/wiki/history.html.haml b/app/views/wiki/history.html.haml index 8a67b5da5..27a3768ff 100644 --- a/app/views/wiki/history.html.haml +++ b/app/views/wiki/history.html.haml @@ -7,23 +7,31 @@ %ul.wat-cf %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li{:class => (!@name and action_name == 'history') ? 'active' : ''} + = link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content #wiki-wrapper.inner.history #head %h1.title - = t("layout.wiki.history_for") - %strong= @name + - if @name + = t("layout.wiki.history_for") + %strong= @name + - else + = t("layout.wiki.wiki_history") %ul.actions - %li.minibutton - = link_to t("layout.wiki.view_page"), view_path(@project, escaped_name), - :class => 'action-view-page' - %li.minibutton - = link_to t("layout.wiki.edit_page"), edit_project_wiki_path(@project, escaped_name), - :class => 'aciton-edit-page' + - if @name + %li.minibutton + = link_to t("layout.wiki.view_page"), view_path(@project, escaped_name), + :class => 'action-view-page' + %li.minibutton + = link_to t("layout.wiki.edit_page"), edit_project_wiki_path(@project, escaped_name), + :class => 'aciton-edit-page' + - else + %li.minibutton + = link_to t("layout.wiki.view_page"), project_wiki_index_path(@project) = render :partial => 'searchbar' #wiki-content diff --git a/app/views/wiki/new.html.haml b/app/views/wiki/new.html.haml index b7ec40327..f9a5a4756 100644 --- a/app/views/wiki/new.html.haml +++ b/app/views/wiki/new.html.haml @@ -7,7 +7,7 @@ %ul.wat-cf %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content diff --git a/app/views/wiki/pages.html.haml b/app/views/wiki/pages.html.haml index 2db5f2c06..d55399349 100644 --- a/app/views/wiki/pages.html.haml +++ b/app/views/wiki/pages.html.haml @@ -8,7 +8,7 @@ %li.first{:class => "#{(@name == 'Home') ? 'active' : ''}" } = link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li.active= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content diff --git a/app/views/wiki/search.html.haml b/app/views/wiki/search.html.haml index bd73ef586..856a53389 100644 --- a/app/views/wiki/search.html.haml +++ b/app/views/wiki/search.html.haml @@ -7,7 +7,7 @@ %ul.wat-cf %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content diff --git a/app/views/wiki/show.html.haml b/app/views/wiki/show.html.haml index f06ecc76f..435e0cec7 100644 --- a/app/views/wiki/show.html.haml +++ b/app/views/wiki/show.html.haml @@ -8,7 +8,7 @@ %li.first{:class => "#{(@name == 'Home') ? 'active' : ''}" } = link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.wiki_history"), '#' + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) %li= link_to t("layout.wiki.git_access"), '#' .content diff --git a/config/routes.rb b/config/routes.rb index 80f4472a3..61caabdd8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,12 +81,14 @@ Rosa::Application.routes.draw do resources :projects do resources :wiki do collection do -# Uncomment if gollum can revert page without name -# match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert, :via => :get, :constrains => {:sha1 => /[0-9a-f]{40}/, :sha2 => /[0-9a-f]{40}/} - + match '_history' => 'wiki#history', :as => :history, :via => :get + match '_access' => 'wiki#git', :as => :git, :via => :get + match '_revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => [:get, :post] + match '_compare' => 'wiki#compare', :as => :compare, :via => :post post :preview get :search get :pages + match '_compare/*versions' => 'wiki#compare', :as => :compare_versions, :via => :get end member do get :history diff --git a/public/stylesheets/git/style.css b/public/stylesheets/git/style.css index 2bb0bb398..a20748d90 100644 --- a/public/stylesheets/git/style.css +++ b/public/stylesheets/git/style.css @@ -111,6 +111,7 @@ table.blob td.blob pre { background-color: #EAEAEA; border-bottom: 1px solid #DDDDDD; font-family: Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; + font-size: 1.2em; padding: 5px; margin-top: 20px; } @@ -143,6 +144,7 @@ table.commit_stats tr { table.diff { line-height: 1.4em; + font-size: 1.2em; font-family: 'Bitstream Vera Sans Mono','Courier',monospace; border-top: 1px solid #EAEAEA; border-bottom: 1px solid #EAEAEA; @@ -153,8 +155,7 @@ table.diff tr td.line_numbers { background-color: #ECECEC; border-right: 1px solid #DDDDDD; color: #AAAAAA; - padding-left: 10px; - padding-right: 10px; + padding: 0 0.5em; text-align: right; } @@ -277,4 +278,4 @@ table.blame td.message .message { #git_submenu div a:hover { background: #ECECEC; color: #000; -} \ No newline at end of file +} diff --git a/public/stylesheets/gollum/gollum.css b/public/stylesheets/gollum/gollum.css index 1233a8198..fe6ef710c 100755 --- a/public/stylesheets/gollum/gollum.css +++ b/public/stylesheets/gollum/gollum.css @@ -449,6 +449,10 @@ width: 1%; } + #compare-content .spacer { + height: 20px; + } + .compare #compare-content ul.actions li, .compare #footer ul.actions li { margin-left: 0;