csv-diff-report 0.3.5 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56cdc0f5cb3e6c6032e8cbd9de325bceede2a895
4
- data.tar.gz: 729b39b7a6373da8fd499d228930a01fbce695d0
3
+ metadata.gz: 62b8aefdb52e2872454da14a06c24fa6619f164b
4
+ data.tar.gz: 7224773cd94a741c278990ab924bb5aea3b8fbde
5
5
  SHA512:
6
- metadata.gz: 3650d3644596522ee283c80c792d3c3d35832ed630843ef02492708911e09683c1c3d58fe8023664b995e3dd5c4d46eeec347b8c991df15cf8c1006f9f82355b
7
- data.tar.gz: 1747526e29d2dd0fabe3a20bc8dbadaa405d506ab56ccb822610f516b383897c697cf3407f7ed5cd5cc5868106f621b2c4a3b2894faf95a0f60632b78435a045
6
+ metadata.gz: 881ef630cda8f08a5d766190a884b8224b12377bd507abc2a934283a4c3f678318f4ac64d194d576e361b7137f65ca5e407a4249dba8c2c86cdbf66ba532747d
7
+ data.tar.gz: fe758fdb2ee804dfa627c8b4397307e80f385aedbd34b2816683b9f0441744dcc901f80320e98b64e88234e8c1be199f2519a95f1219e487ac8dc9836c49a3a5
@@ -67,6 +67,8 @@ class CSVDiff
67
67
  short_key: 'i'
68
68
 
69
69
  usage_break 'Diff Options:'
70
+ keyword_arg :options_file, 'Path to an options file that contains settings based on file types. ' +
71
+ 'Defaults to searching for a file named .csvdiff in the FROM or current directory.'
70
72
  flag_arg :ignore_case, 'If true, field comparisons are performed without regard to case.'
71
73
  flag_arg :diff_common_fields_only, 'If true, only fields in both files are compared.',
72
74
  short_key: 'C'
@@ -90,7 +92,7 @@ class CSVDiff
90
92
  short_key: 'o'
91
93
  keyword_arg :output_fields, 'The names or indexes of the fields to include in the diff output.',
92
94
  short_key: 'O', on_parse: :parse_fields
93
- keyword_arg :include_matched, 'If true, fields that match on lines with differences are included ' +
95
+ flag_arg :include_matched, 'If true, fields that match on lines with differences are included ' +
94
96
  'in the diff output; by default, matching fields are not included in the diff output.'
95
97
 
96
98
 
@@ -1,4 +1,8 @@
1
1
  require 'cgi'
2
+ begin
3
+ require 'lcs-diff'
4
+ rescue LoadError
5
+ end
2
6
 
3
7
 
4
8
  class CSVDiff
@@ -14,11 +18,13 @@ class CSVDiff
14
18
  content << '<html>'
15
19
  content << '<head>'
16
20
  content << '<title>Diff Report</title>'
17
- content << '<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">'
21
+ content << '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
18
22
  content << html_styles
19
23
  content << '</head>'
20
24
  content << '<body>'
21
25
 
26
+ @lcs_available = !!defined?(Diff::LCS)
27
+
22
28
  html_summary(content)
23
29
  @diffs.each do |file_diff|
24
30
  html_diff(content, file_diff) if file_diff.diffs.size > 0
@@ -38,14 +44,15 @@ class CSVDiff
38
44
  def html_styles
39
45
  style = <<-EOT
40
46
  <style>
41
- @font-face {font-family: Calibri;}
47
+ @font-face {font-family: Calibri, Helvetica, sans-serif;}
42
48
 
43
- h1 {font-family: Calibri; font-size: 16pt;}
44
- h2 {font-family: Calibri; font-size: 14pt; margin: 1em 0em .2em;}
45
- h3 {font-family: Calibri; font-size: 12pt; margin: 1em 0em .2em;}
46
- body {font-family: Calibri; font-size: 11pt;}
49
+ h1 {font-family: Calibri, Helvetica, sans-serif; font-size: 16pt;}
50
+ h2 {font-family: Calibri, Helvetica, sans-serif; font-size: 14pt; margin: 1em 0em .2em;}
51
+ h3 {font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; margin: 1em 0em .2em;}
52
+ body {font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;}
47
53
  p {margin: .2em 0em;}
48
- table {font-family: Calibri; font-size: 10pt; line-height: 12pt; border-collapse: collapse;}
54
+ code {font-size: 8pt; white-space: pre;}
55
+ table {font-family: Calibri, Helvetica, sans-serif; font-size: 10pt; line-height: 12pt; border-collapse: collapse;}
49
56
  th {background-color: #00205B; color: white; font-size: 11pt; font-weight: bold; text-align: left;
50
57
  border: 1px solid #DDDDFF; padding: 1px 5px;}
51
58
  td {border: 1px solid #DDDDFF; padding: 1px 5px;}
@@ -69,7 +76,9 @@ class CSVDiff
69
76
  def html_summary(body)
70
77
  body << '<h2>Summary</h2>'
71
78
 
72
- body << '<p>Source Locations:</p>'
79
+ body << "<p>Diff report generated at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}.</p>"
80
+
81
+ body << '<h3>Source Locations</h3>'
73
82
  body << '<table>'
74
83
  body << '<tbody>'
75
84
  body << "<tr><th>From:</th><td>#{@left}</td></tr>"
@@ -77,7 +86,7 @@ class CSVDiff
77
86
  body << '</tbody>'
78
87
  body << '</table>'
79
88
  body << '<br>'
80
- body << '<p>Files:</p>'
89
+ body << '<h3>Files</hs>'
81
90
  body << '<table>'
82
91
  body << '<thead>'
83
92
  body << "<tr><th rowspan=2>File</th><th colspan=2 class='center'>Lines</th><th colspan=4 class='center'>Diffs</th></tr>"
@@ -160,12 +169,25 @@ class CSVDiff
160
169
  style = chg.downcase if i == 1
161
170
  elsif file_diff.options[:include_matched]
162
171
  style = 'matched'
163
- d = file_diff.right[key] && file_diff.right[key][field]
172
+ new = file_diff.right[key] && file_diff.right[key][field]
164
173
  end
165
174
  body << '<td>'
166
- body << "<span class='delete'>#{CGI.escapeHTML(old.to_s)}</span>" if old
167
- body << '<br>' if old && old.to_s.length > 10
168
- body << "<span#{style ? " class='#{style}'" : ''}>#{CGI.escapeHTML(new.to_s)}</span>"
175
+ if style == 'update' && @lcs_available && old && new && (old.to_s.lines.count > 1 || new.to_s.lines.count > 1)
176
+ body << '<code>'
177
+ Diff::LCS.diff(old.lines, new.lines).each_with_index do |chg_set, j|
178
+ body << '...' unless j == 0
179
+ chg_set.each do |lcs_diff|
180
+ body << "#{lcs_diff.position}&nbsp;&nbsp;<span class='#{
181
+ lcs_diff.action == '+' ? 'add' : 'delete'}'>#{
182
+ CGI.escapeHTML(lcs_diff.element.to_s.chomp)}</span>"
183
+ end
184
+ end
185
+ body << '</code>'
186
+ else
187
+ body << "<span class='delete'>#{CGI.escapeHTML(old.to_s)}</span>" if old
188
+ body << '<br>' if old && old.to_s.length > 10
189
+ body << "<span#{style ? " class='#{style}'" : ''}>#{CGI.escapeHTML(new.to_s)}</span>"
190
+ end
169
191
  body << '</td>'
170
192
  end
171
193
  body << '</tr>'
@@ -83,13 +83,13 @@ class CSVDiff
83
83
  echo "Performing file diff:"
84
84
  echo " From File: #{@left}"
85
85
  echo " To File: #{@right}"
86
- opt_file = load_opt_file(@left.dirname)
86
+ opt_file = load_opt_file(options.fetch(:options_file, @left.dirname))
87
87
  diff_file(@left.to_s, @right.to_s, options, opt_file)
88
88
  elsif @left.directory? && @right.directory?
89
89
  echo "Performing directory diff:"
90
90
  echo " From directory: #{@left}"
91
91
  echo " To directory: #{@right}"
92
- opt_file = load_opt_file(@left)
92
+ opt_file = load_opt_file(options.fetch(:options_file, @left))
93
93
  if fts = options[:file_types]
94
94
  file_types = find_matching_file_types(fts, opt_file)
95
95
  file_types.each do |file_type|
@@ -133,7 +133,8 @@ class CSVDiff
133
133
 
134
134
  # Loads an options file from +dir+
135
135
  def load_opt_file(dir)
136
- opt_path = Pathname(dir + '.csvdiff')
136
+ opt_path = Pathname(dir)
137
+ opt_path += '.csvdiff' if opt_path.directory?
137
138
  opt_path = Pathname('.csvdiff') unless opt_path.exist?
138
139
  if opt_path.exist?
139
140
  echo "Loading options from '#{opt_path}'"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv-diff-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Gardiner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv-diff
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.5.2
120
+ rubygems_version: 2.5.2.3
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: CSV Diff Report is a library for generating diff reports using the CSV Diff