diff_json 0.1.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh MacLachlan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Diffs two JSON objects and returns a left/right diff view, similar to
14
- the command line `diff` utility
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: require_all
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Diffs two JSON objects and returns a JSON patch, or a left/right diff
28
+ view, similar to the command line `diff` utility
15
29
  email: josh.t.maclachlan@gmail.com
16
30
  executables: []
17
31
  extensions: []
@@ -19,11 +33,13 @@ extra_rdoc_files: []
19
33
  files:
20
34
  - lib/diff_json.rb
21
35
  - lib/diff_json/diff.rb
22
- - lib/diff_json/html_output.rb
23
- - lib/diff_json/undefined_value.rb
36
+ - lib/diff_json/diff/json_diffing.rb
37
+ - lib/diff_json/diff/json_mapping.rb
38
+ - lib/diff_json/output/html_output.rb
39
+ - lib/diff_json/output/undefined_value.rb
24
40
  homepage: https://github.com/jtmaclachlan/diff_json
25
41
  licenses:
26
- - GPL-2
42
+ - GPL-2.0
27
43
  metadata: {}
28
44
  post_install_message:
29
45
  rdoc_options: []
@@ -40,10 +56,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
56
  - !ruby/object:Gem::Version
41
57
  version: '0'
42
58
  requirements: []
43
- rubyforge_project:
44
- rubygems_version: 2.7.6
59
+ rubygems_version: 3.0.3
45
60
  signing_key:
46
61
  specification_version: 4
47
- summary: Diffs two JSON objects and returns a left/right diff view, similar to the
48
- command line `diff` utility
62
+ summary: Diffs two JSON objects and returns a JSON patch, or a left/right diff view,
63
+ similar to the command line `diff` utility
49
64
  test_files: []
@@ -1,98 +0,0 @@
1
- module DiffJson
2
- class HtmlOutput
3
-
4
- def initialize(diff, **opts)
5
- @diff = diff
6
- @opts = {
7
- :table_id_prefix => 'diff_json_view_0'
8
- }.merge(opts)
9
- @output = {
10
- :full_diff => {},
11
- :sub_diffs => {}
12
- }
13
-
14
- calculate
15
- end
16
-
17
- def full
18
- return @output[:full_diff][:full]
19
- end
20
-
21
- def left
22
- return @output[:full_diff][:left]
23
- end
24
-
25
- def right
26
- return @output[:full_diff][:right]
27
- end
28
-
29
- def sub_diffs
30
- return @output[:sub_diffs]
31
- end
32
-
33
- private
34
-
35
- def calculate
36
- @output[:full_diff] = table_markup(@opts[:table_id_prefix], @diff.diff)
37
-
38
- @diff.sub_diffs.each do |key, sub_diffs|
39
- sub_diffs.each do |value, diff|
40
- sub_key = "#{key}::#{value}"
41
- table_key = "#{key}_#{value}"
42
- @output[:sub_diffs][sub_key] = table_markup("#{@opts[:table_id_prefix]}_sub_diff_#{table_key}", diff)
43
- end
44
- end
45
- end
46
-
47
- def table_markup(table_id_prefix, lines)
48
- markup = {
49
- :full => "",
50
- :left => "",
51
- :right => ""
52
- }
53
-
54
- markup[:full] = "<table id=\"#{table_id_prefix}_full\" class=\"diff-json-full-view\">\n"
55
- markup[:left] = "<table id=\"#{table_id_prefix}_left\" class=\"diff-json-split-view-left\">\n"
56
- markup[:right] = "<table id=\"#{table_id_prefix}_right\" class=\"diff-json-split-view-right\">\n"
57
-
58
- (0..(lines[:old].length - 1)).each do |i|
59
- # Full, combined table output
60
- markup[:full] += " <tr class=\"diff-json-view-line\">\n"
61
- markup[:full] += " <td class=\"diff-json-view-line-operator\"><pre>#{lines[:old][i][0]}</pre></td>\n"
62
- markup[:full] += " <td class=\"diff-json-view-line-content #{content_highlight_class(:left, lines[:old][i][0])}\"><pre>#{lines[:old][i][1]}</pre></td>\n"
63
- markup[:full] += " <td class=\"diff-json-view-column-break\"></td>\n"
64
- markup[:full] += " <td class=\"diff-json-view-line-operator\"><pre>#{lines[:new][i][0]}</pre></td>\n"
65
- markup[:full] += " <td class=\"diff-json-view-line-content #{content_highlight_class(:right, lines[:new][i][0])}\"><pre>#{lines[:new][i][1]}</pre></td>\n"
66
- markup[:full] += " </tr>\n"
67
- # Split, left side output
68
- markup[:left] += " <tr class=\"diff-json-view-line\">\n"
69
- markup[:left] += " <td class=\"diff-json-view-line-operator\"><pre>#{lines[:old][i][0]}</pre></td>\n"
70
- markup[:left] += " <td class=\"diff-json-view-line-content #{content_highlight_class(:left, lines[:old][i][0])}\"><pre>#{lines[:old][i][1]}</pre></td>\n"
71
- markup[:left] += " </tr>\n"
72
- # Split, right side output
73
- markup[:right] += " <tr class=\"diff-json-view-line\">\n"
74
- markup[:right] += " <td class=\"diff-json-view-line-operator\"><pre>#{lines[:new][i][0]}</pre></td>\n"
75
- markup[:right] += " <td class=\"diff-json-view-line-content #{content_highlight_class(:right, lines[:new][i][0])}\"><pre>#{lines[:new][i][1]}</pre></td>\n"
76
- markup[:right] += " </tr>\n"
77
- end
78
-
79
- markup[:full] += "</table>\n"
80
- markup[:left] += "</table>\n"
81
- markup[:right] += "</table>\n"
82
-
83
- return markup
84
- end
85
-
86
- def content_highlight_class(side, operator)
87
- if operator == '-'
88
- return 'diff-json-content-del'
89
- elsif operator == '+'
90
- return 'diff-json-content-ins'
91
- elsif operator == 'M'
92
- return side == :left ? 'diff-json-content-del' : 'diff-json-content-ins'
93
- else
94
- return ''
95
- end
96
- end
97
- end
98
- end