Class: Protozoa::Views::Compare

Inherits:
Layout
  • Object
show all
Defined in:
lib/amiba/frontend/views/compare.rb

Instance Attribute Summary collapse

Attributes inherited from Layout

#name

Instance Method Summary collapse

Methods inherited from Layout

#edit_url, #escaped_name, #view_url

Instance Attribute Details

#diffObject (readonly)

Returns the value of attribute diff.



4
5
6
# File 'lib/amiba/frontend/views/compare.rb', line 4

def diff
  @diff
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/amiba/frontend/views/compare.rb', line 4

def message
  @message
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/amiba/frontend/views/compare.rb', line 4

def page
  @page
end

#versionsObject (readonly)

Returns the value of attribute versions.



4
5
6
# File 'lib/amiba/frontend/views/compare.rb', line 4

def versions
  @versions
end

Instance Method Details

#afterObject



18
19
20
# File 'lib/amiba/frontend/views/compare.rb', line 18

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

#beforeObject



14
15
16
# File 'lib/amiba/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/amiba/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/amiba/frontend/views/compare.rb', line 39

def line_class(line)
  if line =~ /^@@/
    'gc'
  elsif line =~ /^\+/
    'gi'
  elsif line =~ /^\-/
    'gd'
  else
    ''
  end
end

#linesObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/amiba/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

#pathObject



10
11
12
# File 'lib/amiba/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/amiba/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_revertObject



33
34
35
# File 'lib/amiba/frontend/views/compare.rb', line 33

def show_revert
  !@message
end

#titleObject



6
7
8
# File 'lib/amiba/frontend/views/compare.rb', line 6

def title
  "Comparison of #{@page.title}"
end