Class: Redmine::DiffTable
Overview
Class that represents a file diff
Instance Attribute Summary
-
- (Object) file_name
readonly
Returns the value of attribute file_name.
-
- (Object) line_num_l
readonly
Returns the value of attribute line_num_l.
-
- (Object) line_num_r
readonly
Returns the value of attribute line_num_r.
Instance Method Summary
-
- (Object) add_line(line)
Function for add a line of this Diff Returns false when the diff ends.
-
- (Object) escapeHTML(line)
Escape the HTML for the diff.
-
- (DiffTable) initialize(type = "inline")
constructor
Initialize with a Diff file and the type of Diff View The type view must be inline or sbs (side_by_side).
- - (Object) inspect
- - (Object) parse_line(line, type = "inline")
-
- (Boolean) sbs?(type, func)
Test if is a Side By Side type.
Methods inherited from Hash
Constructor Details
- (DiffTable) initialize(type = "inline")
Initialize with a Diff file and the type of Diff View The type view must be inline or sbs (side_by_side)
53 54 55 56 57 58 59 60 |
# File 'lib/redmine/unified_diff.rb', line 53 def initialize(type="inline") @parsing = false @nb_line = 1 @start = false @before = 'same' @second = true @type = type end |
Instance Attribute Details
- (Object) file_name (readonly)
Returns the value of attribute file_name
49 50 51 |
# File 'lib/redmine/unified_diff.rb', line 49 def file_name @file_name end |
- (Object) line_num_l (readonly)
Returns the value of attribute line_num_l
49 50 51 |
# File 'lib/redmine/unified_diff.rb', line 49 def line_num_l @line_num_l end |
- (Object) line_num_r (readonly)
Returns the value of attribute line_num_r
49 50 51 |
# File 'lib/redmine/unified_diff.rb', line 49 def line_num_r @line_num_r end |
Instance Method Details
- (Object) add_line(line)
Function for add a line of this Diff Returns false when the diff ends
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/redmine/unified_diff.rb', line 64 def add_line(line) unless @parsing if line =~ /^(---|\+\+\+) (.*)$/ @file_name = $2 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ @line_num_l = $2.to_i @line_num_r = $5.to_i @parsing = true end else if line =~ /^[^\+\-\s@\\]/ @parsing = false return false elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ @line_num_l = $2.to_i @line_num_r = $5.to_i else @nb_line += 1 if parse_line(line, @type) end end return true end |
- (Object) escapeHTML(line)
Escape the HTML for the diff
123 124 125 |
# File 'lib/redmine/unified_diff.rb', line 123 def escapeHTML(line) CGI.escapeHTML(line) end |
- (Object) inspect
87 88 89 90 91 92 93 |
# File 'lib/redmine/unified_diff.rb', line 87 def inspect puts '### DIFF TABLE ###' puts "file : #{file_name}" self.each do |d| d.inspect end end |
- (Object) parse_line(line, type = "inline")
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/redmine/unified_diff.rb', line 127 def parse_line(line, type="inline") if line[0, 1] == "+" diff = sbs? type, 'add' @before = 'add' diff.line_right = escapeHTML line[1..-1] diff.nb_line_right = @line_num_r diff.type_diff_right = 'diff_in' @line_num_r += 1 true elsif line[0, 1] == "-" diff = sbs? type, 'remove' @before = 'remove' diff.line_left = escapeHTML line[1..-1] diff.nb_line_left = @line_num_l diff.type_diff_left = 'diff_out' @line_num_l += 1 true elsif line[0, 1] =~ /\s/ @before = 'same' @start = false diff = Diff.new diff.line_right = escapeHTML line[1..-1] diff.nb_line_right = @line_num_r diff.line_left = escapeHTML line[1..-1] diff.nb_line_left = @line_num_l self[@nb_line] = diff @line_num_l += 1 @line_num_r += 1 true elsif line[0, 1] = "\\" true else false end end |
- (Boolean) sbs?(type, func)
Test if is a Side By Side type
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/redmine/unified_diff.rb', line 97 def sbs?(type, func) if @start and type == "sbs" if @before == func and @second tmp_nb_line = @nb_line self[tmp_nb_line] = Diff.new else @second = false tmp_nb_line = @start @start += 1 @nb_line -= 1 end else tmp_nb_line = @nb_line @start = @nb_line self[tmp_nb_line] = Diff.new @second = true end unless self[tmp_nb_line] @nb_line += 1 self[tmp_nb_line] = Diff.new else self[tmp_nb_line] end end |