pretty_diff 0.9.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +41 -6
  4. data/Rakefile +0 -1
  5. data/VERSION +1 -1
  6. data/lib/pretty_diff.rb +5 -6
  7. data/lib/pretty_diff/abstract_generator.rb +51 -0
  8. data/lib/pretty_diff/basic_generator.rb +72 -0
  9. data/lib/pretty_diff/chunk.rb +24 -41
  10. data/lib/pretty_diff/diff.rb +75 -41
  11. data/lib/pretty_diff/encoding.rb +30 -0
  12. data/lib/pretty_diff/line.rb +30 -51
  13. data/lib/pretty_diff/line_numbers.rb +47 -67
  14. data/pretty_diff.gemspec +33 -18
  15. data/test/abstract_generator_test.rb +65 -0
  16. data/test/basic_generator_test.rb +29 -0
  17. data/test/chunk_test.rb +13 -30
  18. data/test/diff_test.rb +50 -19
  19. data/test/encoding_test.rb +35 -0
  20. data/test/fixtures/blank.diff +0 -0
  21. data/test/fixtures/blank.diff.html +1 -0
  22. data/test/fixtures/chinese-gbk-crlf +5 -0
  23. data/test/fixtures/cp1251.diff +13 -0
  24. data/test/fixtures/csharp.diff +12 -0
  25. data/test/fixtures/csharp.diff.html +19 -0
  26. data/test/{data → fixtures}/first.diff +0 -0
  27. data/test/fixtures/first.diff.html +85 -0
  28. data/test/{data → fixtures}/second.diff +0 -0
  29. data/test/fixtures/single_line.diff +7 -0
  30. data/test/fixtures/single_line.diff.html +4 -0
  31. data/test/fixtures/text.diff +8 -0
  32. data/test/fixtures/text.diff.html +13 -0
  33. data/test/fixtures/windows-cp1251-lf +6 -0
  34. data/test/helper.rb +10 -8
  35. data/test/line_numbers_test.rb +25 -0
  36. data/test/line_test.rb +26 -37
  37. metadata +81 -75
  38. data/lib/pretty_diff/html_generators/chunk_generator.rb +0 -41
  39. data/lib/pretty_diff/html_generators/diff_generator.rb +0 -13
  40. data/lib/pretty_diff/html_generators/line_generator.rb +0 -45
  41. data/lib/pretty_diff/html_generators/line_numbers_generator.rb +0 -36
  42. data/test/html_generator_test.rb +0 -39
metadata CHANGED
@@ -1,64 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pretty_diff
3
- version: !ruby/object:Gem::Version
4
- hash: 61
5
- prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 3
10
- version: 0.9.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Ilya Sabanin
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-04-05 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- type: :development
32
- name: jeweler
33
- version_requirements: *id001
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: charlock_holmes
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
34
21
  prerelease: false
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jeweler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
45
34
  type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
46
42
  name: builder
47
- version_requirements: *id002
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
48
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
49
55
  description: |-
50
56
  PrettyDiff is a highly customizable library for creating fully featured HTML
51
57
  listings out of unified diff format strings.
52
58
  Include copy/paste-safe line numbers and built-in syntax highlighting.
53
59
  email: ilya.sabanin@gmail.com
54
60
  executables: []
55
-
56
61
  extensions: []
57
-
58
- extra_rdoc_files:
62
+ extra_rdoc_files:
59
63
  - LICENSE
60
64
  - README.rdoc
61
- files:
65
+ files:
62
66
  - .document
63
67
  - Gemfile
64
68
  - Gemfile.lock
@@ -67,55 +71,57 @@ files:
67
71
  - Rakefile
68
72
  - VERSION
69
73
  - lib/pretty_diff.rb
74
+ - lib/pretty_diff/abstract_generator.rb
75
+ - lib/pretty_diff/basic_generator.rb
70
76
  - lib/pretty_diff/chunk.rb
71
77
  - lib/pretty_diff/diff.rb
72
- - lib/pretty_diff/html_generators/chunk_generator.rb
73
- - lib/pretty_diff/html_generators/diff_generator.rb
74
- - lib/pretty_diff/html_generators/line_generator.rb
75
- - lib/pretty_diff/html_generators/line_numbers_generator.rb
78
+ - lib/pretty_diff/encoding.rb
76
79
  - lib/pretty_diff/line.rb
77
80
  - lib/pretty_diff/line_numbers.rb
78
81
  - pretty_diff.gemspec
82
+ - test/abstract_generator_test.rb
83
+ - test/basic_generator_test.rb
79
84
  - test/chunk_test.rb
80
- - test/data/first.diff
81
- - test/data/second.diff
82
85
  - test/diff_test.rb
86
+ - test/encoding_test.rb
87
+ - test/fixtures/blank.diff
88
+ - test/fixtures/blank.diff.html
89
+ - test/fixtures/chinese-gbk-crlf
90
+ - test/fixtures/cp1251.diff
91
+ - test/fixtures/csharp.diff
92
+ - test/fixtures/csharp.diff.html
93
+ - test/fixtures/first.diff
94
+ - test/fixtures/first.diff.html
95
+ - test/fixtures/second.diff
96
+ - test/fixtures/single_line.diff
97
+ - test/fixtures/single_line.diff.html
98
+ - test/fixtures/text.diff
99
+ - test/fixtures/text.diff.html
100
+ - test/fixtures/windows-cp1251-lf
83
101
  - test/helper.rb
84
- - test/html_generator_test.rb
102
+ - test/line_numbers_test.rb
85
103
  - test/line_test.rb
86
- has_rdoc: true
87
104
  homepage: http://github.com/isabanin/pretty_diff
88
105
  licenses: []
89
-
106
+ metadata: {}
90
107
  post_install_message:
91
108
  rdoc_options: []
92
-
93
- require_paths:
109
+ require_paths:
94
110
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
113
121
  requirements: []
114
-
115
122
  rubyforge_project:
116
- rubygems_version: 1.6.2
123
+ rubygems_version: 2.0.3
117
124
  signing_key:
118
- specification_version: 3
125
+ specification_version: 4
119
126
  summary: Library for converting unified diff format into HTML listings.
120
127
  test_files: []
121
-
@@ -1,41 +0,0 @@
1
- class PrettyDiff::ChunkGenerator
2
-
3
- attr_reader :chunk
4
-
5
- def initialize(chunk)
6
- @chunk = chunk
7
- end
8
-
9
- def generate
10
- start_html +
11
- chunk.line_numbers.to_html +
12
- code_html(content) +
13
- end_html
14
- end
15
-
16
- private
17
-
18
- def content
19
- chunk.lines.map{|l| l.to_html }.join("\n")
20
- end
21
-
22
- def wrapper_class
23
- klass = "code-viewer"
24
- klass << ' chunk' if chunk.diff.chunks.size > 1
25
- klass
26
- end
27
-
28
- def start_html
29
- %Q[<div class="#{ wrapper_class }">]
30
- end
31
-
32
- def code_html(text)
33
- %Q[<div class="code-list"><pre>
34
- #{text}</pre></div>]
35
- end
36
-
37
- def end_html
38
- %Q[</div>]
39
- end
40
-
41
- end
@@ -1,13 +0,0 @@
1
- class PrettyDiff::DiffGenerator
2
-
3
- attr_reader :diff
4
-
5
- def initialize(diff)
6
- @diff = diff
7
- end
8
-
9
- def generate
10
- diff.chunks.map{|c| c.to_html}.join('')
11
- end
12
-
13
- end
@@ -1,45 +0,0 @@
1
- class PrettyDiff::LineGenerator
2
-
3
- attr_reader :line
4
-
5
- def initialize(line)
6
- @line = line
7
- end
8
-
9
- def generate
10
- if line.added?
11
- added_html(content)
12
- elsif line.deleted?
13
- deleted_html(content)
14
- else
15
- not_modified_html(content)
16
- end
17
- end
18
-
19
- private
20
-
21
- def content
22
- @_content ||= line.format
23
- end
24
-
25
- def wrapper_html
26
- if line.diff.options[:wrap_lines]
27
- "<div> #{yield} </div>"
28
- else
29
- yield
30
- end
31
- end
32
-
33
- def added_html(text)
34
- wrapper_html { %Q[<span class="gi">#{text}</span>] }
35
- end
36
-
37
- def deleted_html(text)
38
- wrapper_html { %Q[<span class="gd">#{text}</span>] }
39
- end
40
-
41
- def not_modified_html(text)
42
- wrapper_html { %Q[#{text}] }
43
- end
44
-
45
- end
@@ -1,36 +0,0 @@
1
- class PrettyDiff::LineNumbersGenerator
2
-
3
- attr_reader :line_numbers
4
-
5
- def initialize(line_numbers)
6
- @line_numbers = line_numbers
7
- end
8
-
9
- def generate
10
- column_html(left_column) + column_html(right_column)
11
- end
12
-
13
- private
14
-
15
- def left_column
16
- empty_lines_to_whitespace(line_numbers.left_column).join("\n")
17
- end
18
-
19
- def right_column
20
- empty_lines_to_whitespace(line_numbers.right_column).join("\n")
21
- end
22
-
23
- def empty_lines_to_whitespace(numbers)
24
- result = []
25
- numbers.each do |v|
26
- result << (v.nil? ? '&nbsp;' : v)
27
- end
28
- result
29
- end
30
-
31
- def column_html(text)
32
- %Q[<div class="code-lines"><pre>
33
- #{text}</pre></div>]
34
- end
35
-
36
- end
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class HtmlGeneratorTest < Test::Unit::TestCase
4
-
5
- context "Html Generator" do
6
-
7
- context "for lines" do
8
- should "generate correct HTML for added line" do
9
- text = "+package chiro.methods.new.ones;"
10
- expected_html = %Q[<span class="gi">#{text}</span>]
11
- assert_equal expected_html, line_to_html(text)
12
- end
13
-
14
- should "generate correct HTML for deleted line" do
15
- text = '- browser.setTimeout("50000");'
16
- expected_html = %Q[<span class="gd">- browser.setTimeout("50000");</span>]
17
- assert_equal expected_html, line_to_html(text)
18
- end
19
-
20
- should "generate correct HTML for not modified line" do
21
- text = ' public static void close() {'
22
- expected_html = " public static void close() {"
23
- assert_equal expected_html, line_to_html(text)
24
- end
25
- end
26
-
27
- end
28
-
29
- private
30
-
31
- def new_line(text)
32
- PrettyDiff::Line.new(text)
33
- end
34
-
35
- def line_to_html(text)
36
- new_line(text).to_html
37
- end
38
-
39
- end