Class: Precious::Views::Compare
- Defined in:
- lib/gollum/frontend/views/compare.rb
Instance Attribute Summary collapse
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Attributes inherited from Layout
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
- #left_diff_line_number(id, line) ⇒ Object
-
#line_class(line) ⇒ Object
private.
- #lines ⇒ Object
- #path ⇒ Object
- #right_diff_line_number(id, line) ⇒ Object
- #show_revert ⇒ Object
- #title ⇒ Object
Methods inherited from Layout
Instance Attribute Details
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
4 5 6 |
# File 'lib/gollum/frontend/views/compare.rb', line 4 def diff @diff end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/gollum/frontend/views/compare.rb', line 4 def @message end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'lib/gollum/frontend/views/compare.rb', line 4 def page @page end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
4 5 6 |
# File 'lib/gollum/frontend/views/compare.rb', line 4 def versions @versions end |
Instance Method Details
#after ⇒ Object
18 19 20 |
# File 'lib/gollum/frontend/views/compare.rb', line 18 def after @versions[1][0..6] end |
#before ⇒ Object
14 15 16 |
# File 'lib/gollum/frontend/views/compare.rb', line 14 def before @versions[0][0..6] end |
#left_diff_line_number(id, line) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gollum/frontend/views/compare.rb', line 52 def left_diff_line_number(id, 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 |
#line_class(line) ⇒ Object
private
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gollum/frontend/views/compare.rb', line 39 def line_class(line) if line =~ /^@@/ 'gc' elsif line =~ /^\+/ 'gi' elsif line =~ /^\-/ 'gd' else '' end end |
#lines ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gollum/frontend/views/compare.rb', line 22 def lines lines = [] @diff.diff.split("\n")[2..-1].each_with_index do |line, line_index| lines << { :line => line, :class => line_class(line), :ldln => left_diff_line_number(0, line), :rdln => right_diff_line_number(0, line) } end if @diff lines end |
#path ⇒ Object
10 11 12 |
# File 'lib/gollum/frontend/views/compare.rb', line 10 def path @page.path end |
#right_diff_line_number(id, line) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gollum/frontend/views/compare.rb', line 73 def right_diff_line_number(id, 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 |
#show_revert ⇒ Object
33 34 35 |
# File 'lib/gollum/frontend/views/compare.rb', line 33 def show_revert !@message end |
#title ⇒ Object
6 7 8 |
# File 'lib/gollum/frontend/views/compare.rb', line 6 def title "Comparison of #{@page.title}" end |