Commit 570f63daaff7ef2b7b05c83714c78755b5d07101

Authored by Dmitriy Zaporozhets
1 parent b60b7b2e

line links for commit diff, css fixed for line diff

app/assets/stylesheets/application.css
@@ -49,10 +49,3 @@ @@ -49,10 +49,3 @@
49 .no-padding { 49 .no-padding {
50 padding:0 !important; 50 padding:0 !important;
51 } 51 }
52 -  
53 -  
54 -/** COMMIT BLOCK **/  
55 -.commit-title{display: block;}  
56 -.commit-title{margin-bottom: 10px}  
57 -.commit-author{color: #999; font-weight: normal; font-style: italic;}  
58 -.commit-author strong{font-weight: bold; font-style: normal;}  
app/assets/stylesheets/commits.css.scss
@@ -27,14 +27,44 @@ @@ -27,14 +27,44 @@
27 } 27 }
28 28
29 .diff_file_content{ 29 .diff_file_content{
  30 + table {
  31 + border:none;
  32 + margin:0px;
  33 + padding:0px;
  34 + }
30 .old_line, .new_line { 35 .old_line, .new_line {
31 - background:#ECECEC;  
32 - color:#777;  
33 - width:35px;  
34 - float:left; 36 + margin:0px;
  37 + padding:0px;
  38 + border:none;
  39 + background:#F7F7F7;
  40 + color:#333;
35 padding: 0px 5px; 41 padding: 0px 5px;
36 border-right: 1px solid #ccc; 42 border-right: 1px solid #ccc;
37 text-align:right; 43 text-align:right;
  44 + min-width:35px;
  45 + max-width:35px;
  46 + width:35px;
  47 + a {
  48 + float:left;
  49 + width:35px;
  50 + font-weight:normal;
  51 + &:hover {
  52 + text-decoration:underline;
  53 + }
  54 + }
  55 + }
  56 + .line_content {
  57 + white-space:pre;
  58 + height:14px;
  59 + margin:0px;
  60 + padding:0px;
  61 + border:none;
  62 + &.new {
  63 + background: #DFD;
  64 + }
  65 + &.old {
  66 + background: #FDD;
  67 + }
38 } 68 }
39 } 69 }
40 70
@@ -45,3 +75,24 @@ pre.commit_message { @@ -45,3 +75,24 @@ pre.commit_message {
45 font-weight:bold; 75 font-weight:bold;
46 font-size:15px; 76 font-size:15px;
47 } 77 }
  78 +
  79 +/** COMMIT BLOCK **/
  80 +.commit-title{display: block;}
  81 +.commit-title{margin-bottom: 10px}
  82 +.commit-author{color: #999; font-weight: normal; font-style: italic;}
  83 +.commit-author strong{font-weight: bold; font-style: normal;}
  84 +
  85 +/** bordered list **/
  86 +ul.bordered-list {
  87 + margin:5px 0px;
  88 + padding:0px;
  89 + li {
  90 + padding: 5px;
  91 + border-bottom: 1px solid #EEE;
  92 + overflow: hidden;
  93 + display: block;
  94 + margin:0px;
  95 + }
  96 +}
  97 +
  98 +ul.bordered-list li:last-child { border:none }
app/assets/stylesheets/projects.css.scss
@@ -66,11 +66,8 @@ a { @@ -66,11 +66,8 @@ a {
66 } 66 }
67 } 67 }
68 68
69 -.view_file {  
70 - border:1px solid #CCC;  
71 - margin-bottom:1em;  
72 -  
73 - .view_file_header { 69 +.view_file .view_file_header,
  70 +.diff_file .diff_file_header {
74 background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8)); 71 background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8));
75 background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8); 72 background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8);
76 background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8); 73 background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8);
@@ -81,8 +78,13 @@ a { @@ -81,8 +78,13 @@ a {
81 text-align: left; 78 text-align: left;
82 color: #666; 79 color: #666;
83 border-bottom: 1px solid #DEE2E3; 80 border-bottom: 1px solid #DEE2E3;
84 - padding: .9em 1em;  
85 - } 81 + padding: 7px 10px;
  82 +}
  83 +
  84 +.view_file {
  85 + border:1px solid #CCC;
  86 + margin-bottom:1em;
  87 +
86 .view_file_content { 88 .view_file_content {
87 background:#fff; 89 background:#fff;
88 color:#514721; 90 color:#514721;
app/helpers/commits_helper.rb
1 module CommitsHelper 1 module CommitsHelper
2 include Utils::CharEncode 2 include Utils::CharEncode
3 - def diff_line(line, line_new = 0, line_old = 0)  
4 - full_line = html_escape(line.gsub(/\n/, ''))  
5 - color = if line[0] == "+"  
6 - full_line = "<span class=\"old_line\">&nbsp;</span><span class=\"new_line\">#{line_new}</span> " + full_line  
7 - "#DFD"  
8 - elsif line[0] == "-"  
9 - full_line = "<span class=\"old_line\">#{line_old}</span><span class=\"new_line\">&nbsp;</span> " + full_line  
10 - "#FDD"  
11 - else  
12 - full_line = "<span class=\"old_line\">#{line_old}</span><span class=\"new_line\">#{line_new}</span> " + full_line  
13 - "none"  
14 - end  
15 3
16 - raw "<div style=\"white-space:pre;background:#{color};\">#{full_line}</div>" 4 + def old_line_number(line, i)
  5 +
  6 + end
  7 +
  8 + def new_line_number(line, i)
  9 +
  10 + end
  11 +
  12 + def diff_line_class(line)
  13 + if line[0] == "+"
  14 + "new"
  15 + elsif line[0] == "-"
  16 + "old"
  17 + else
  18 + nil
  19 + end
17 end 20 end
18 21
19 def more_commits_link 22 def more_commits_link
app/views/commits/_diff.html.haml
1 .file_stats 1 .file_stats
2 = render "commits/diff_head" 2 = render "commits/diff_head"
3 3
4 -- @commit.diffs.each do |diff| 4 +- @commit.diffs.each_with_index do |diff, i|
5 - next if diff.diff.empty? 5 - next if diff.diff.empty?
6 - file = (@commit.tree / diff.b_path) 6 - file = (@commit.tree / diff.b_path)
7 - next unless file 7 - next unless file
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 %br/ 15 %br/
16 .diff_file_content 16 .diff_file_content
17 - if file.text? 17 - if file.text?
18 - = render :partial => "commits/text_file", :locals => { :diff => diff } 18 + = render :partial => "commits/text_file", :locals => { :diff => diff, :index => i }
19 - elsif file.image? 19 - elsif file.image?
20 .diff_file_content_image 20 .diff_file_content_image
21 %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} 21 %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"}
app/views/commits/_diff_head.html.haml
1 -%table  
2 - %thead  
3 - %th Files 1 +%ul.bordered-list
4 - @commit.diffs.each do |diff| 2 - @commit.diffs.each do |diff|
5 - %tr  
6 - %td  
7 - - if diff.deleted_file  
8 - %span.removed_file  
9 - %a{:href => "##{diff.a_path}"}  
10 - = diff.a_path  
11 - = image_tag "blueprint_delete.png"  
12 - - elsif diff.renamed_file  
13 - %span.moved_file  
14 - %a{:href => "##{diff.b_path}"}  
15 - = diff.a_path  
16 - = "->"  
17 - = diff.b_path  
18 - = image_tag "blueprint_notice.png"  
19 - - elsif diff.new_file  
20 - %span.new_file  
21 - %a{:href => "##{diff.b_path}"}  
22 - = diff.b_path  
23 - = image_tag "blueprint_add.png"  
24 - - else  
25 - %span.edit_file  
26 - %a{:href => "##{diff.b_path}"}  
27 - = diff.b_path  
28 - = image_tag "blueprint_info.png" 3 + %li
  4 + - if diff.deleted_file
  5 + %span.removed_file
  6 + %a{:href => "##{diff.a_path}"}
  7 + = diff.a_path
  8 + = image_tag "blueprint_delete.png"
  9 + - elsif diff.renamed_file
  10 + %span.moved_file
  11 + %a{:href => "##{diff.b_path}"}
  12 + = diff.a_path
  13 + = "->"
  14 + = diff.b_path
  15 + = image_tag "blueprint_notice.png"
  16 + - elsif diff.new_file
  17 + %span.new_file
  18 + %a{:href => "##{diff.b_path}"}
  19 + = diff.b_path
  20 + = image_tag "blueprint_add.png"
  21 + - else
  22 + %span.edit_file
  23 + %a{:href => "##{diff.b_path}"}
  24 + = diff.b_path
  25 + = image_tag "blueprint_info.png"
29 26
app/views/commits/_text_file.html.haml
1 -- line_old = 0  
2 -- line_new = 0  
3 -- lines_arr = diff.diff.lines.to_a  
4 -- lines_arr.each do |line|  
5 - - line = encode(line)  
6 - - next if line.match(/^--- \/dev\/null/)  
7 - - next if line.match(/^--- a/)  
8 - - next if line.match(/^\+\+\+ b/)  
9 - - if line.match(/^@@ -/)  
10 - - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0  
11 - - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0  
12 - - next 1 +%table
  2 + - line_old = 0
  3 + - line_new = 0
  4 + - lines_arr = diff.diff.lines.to_a
  5 + - lines_arr.each do |line|
  6 + - line = encode(line)
  7 + - next if line.match(/^--- \/dev\/null/)
  8 + - next if line.match(/^--- a/)
  9 + - next if line.match(/^\+\+\+ b/)
  10 + - if line.match(/^@@ -/)
  11 + - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
  12 + - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0
  13 + - next
13 14
14 - = diff_line(line, line_new, line_old)  
15 - - if line[0] == "+"  
16 - - line_new += 1  
17 - - elsif line[0] == "-"  
18 - - line_old += 1  
19 - - else  
20 - - line_new += 1  
21 - - line_old += 1 15 + - full_line = html_escape(line.gsub(/\n/, ''))
  16 + %tr.line_holder
  17 + %td.old_line
  18 + = link_to raw(diff_line_class(line) == "new" ? "&nbsp;" : line_old), "#OLD#{index}-#{line_old}", :id => "OLD#{index}-#{line_old}"
  19 + %td.new_line
  20 + = link_to raw(diff_line_class(line) == "old" ? "&nbsp;" : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}"
  21 + %td.line_content{:class => diff_line_class(full_line)}= raw "#{full_line} &nbsp;"
  22 + - if line[0] == "+"
  23 + - line_new += 1
  24 + - elsif line[0] == "-"
  25 + - line_old += 1
  26 + - else
  27 + - line_new += 1
  28 + - line_old += 1