diffed 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/diffed/version.rb +1 -1
- data/lib/diffed.rb +10 -2
- data/lib/models/file.rb +9 -0
- data/lib/parsers/unified.rb +22 -18
- data/spec/diffed_spec.rb +4 -4
- metadata +9 -8
data/lib/diffed/version.rb
CHANGED
data/lib/diffed.rb
CHANGED
@@ -3,9 +3,17 @@ require 'parsers/unified'
|
|
3
3
|
require 'escape_utils'
|
4
4
|
|
5
5
|
module Diffed
|
6
|
+
def self.from_lines(lines)
|
7
|
+
Diff.new(lines)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from_text(text)
|
11
|
+
Diff.new(text.split /\n/)
|
12
|
+
end
|
13
|
+
|
6
14
|
class Diff
|
7
|
-
def initialize(
|
8
|
-
parse(
|
15
|
+
def initialize(lines)
|
16
|
+
parse(lines)
|
9
17
|
end
|
10
18
|
|
11
19
|
def as_html_table(use_inline_styles = true)
|
data/lib/models/file.rb
ADDED
data/lib/parsers/unified.rb
CHANGED
@@ -13,33 +13,18 @@ module Diffed
|
|
13
13
|
|
14
14
|
@lines.each do |line|
|
15
15
|
if HeaderLineParser.is_header?(line)
|
16
|
-
unless @curr_header.nil?
|
17
|
-
raise "Found a header while still processing a section! #{line}"
|
18
|
-
end
|
19
|
-
|
20
16
|
@curr_header, @curr_lines = HeaderLineParser.new(line), []
|
21
17
|
elsif @curr_header.nil?
|
22
18
|
# Do nothing. We haven't started yet.
|
23
19
|
# puts "Ignoring line: #{line}"
|
24
20
|
elsif line =~ /\/
|
25
|
-
|
26
|
-
@sections.last.lines.last.no_newline = true
|
27
|
-
else
|
28
|
-
@curr_lines.last.no_newline = true
|
29
|
-
end
|
21
|
+
handle_missing_newline
|
30
22
|
else
|
31
|
-
|
32
|
-
@left_counter, @right_counter = line_parser.increment(@left_counter, @right_counter)
|
33
|
-
@curr_lines << line_parser.line(@left_counter, @right_counter)
|
34
|
-
|
35
|
-
if @curr_header.section_complete? @left_counter, @right_counter
|
36
|
-
@sections << Section.new(@curr_header.line, @curr_lines)
|
37
|
-
reset_section!
|
38
|
-
end
|
23
|
+
parse_code_line line
|
39
24
|
end
|
40
25
|
end
|
41
26
|
|
42
|
-
self
|
27
|
+
self # evidence that I'm a Java developer at heart?
|
43
28
|
end
|
44
29
|
|
45
30
|
def sections
|
@@ -48,6 +33,25 @@ module Diffed
|
|
48
33
|
end
|
49
34
|
|
50
35
|
private
|
36
|
+
def handle_missing_newline
|
37
|
+
if @curr_lines.empty?
|
38
|
+
@sections.last.lines.last.no_newline = true
|
39
|
+
else
|
40
|
+
@curr_lines.last.no_newline = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_code_line(line)
|
45
|
+
line_parser = LineParser.new(line)
|
46
|
+
@left_counter, @right_counter = line_parser.increment(@left_counter, @right_counter)
|
47
|
+
@curr_lines << line_parser.line(@left_counter, @right_counter)
|
48
|
+
|
49
|
+
if @curr_header.section_complete? @left_counter, @right_counter
|
50
|
+
@sections << Section.new(@curr_header.line, @curr_lines)
|
51
|
+
reset_section!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
51
55
|
def reset_section!
|
52
56
|
@curr_header, @curr_lines, @left_counter, @right_counter = nil, [], 0, 0
|
53
57
|
end
|
data/spec/diffed_spec.rb
CHANGED
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Diffed::Diff.as_html_table" do
|
4
4
|
it "produces an html table representation of a diff, with CSS styles inline" do
|
5
|
-
diff = Diffed
|
5
|
+
diff = Diffed.from_text(File.read("testdata/diff1.diff"))
|
6
6
|
output = diff.as_html_table
|
7
7
|
output.strip == File.read("testdata/diff1.styled.html").strip
|
8
8
|
end
|
9
9
|
|
10
10
|
it "produces an html table representation of the diff portions of the output of 'git show', with CSS styles inline" do
|
11
|
-
diff = Diffed
|
11
|
+
diff = Diffed.from_text(File.read("testdata/git-show.output"))
|
12
12
|
output = diff.as_html_table
|
13
13
|
output.strip == File.read("testdata/git-show.styled.html").strip
|
14
14
|
end
|
15
15
|
|
16
16
|
it "produces an html table representation of the diff portions of the output of 'p4 describe -du', with CSS styles inline" do
|
17
|
-
diff = Diffed
|
17
|
+
diff = Diffed.from_text(File.read("testdata/p4-describe.output"))
|
18
18
|
output = diff.as_html_table
|
19
19
|
output.strip == File.read("testdata/p4-describe.styled.html").strip
|
20
20
|
end
|
21
21
|
|
22
22
|
it "produces an html table representation of a diff, with CSS classes" do
|
23
|
-
diff = Diffed
|
23
|
+
diff = Diffed.from_text(File.read("testdata/diff1.diff"))
|
24
24
|
output = diff.as_html_table(false)
|
25
25
|
output.strip == File.read("testdata/diff1.classed.html").strip
|
26
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: escape_utils
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152434200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152434200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152433780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152433780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152433360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152433360
|
47
47
|
description: ! 'This is a library for creating HTML from a unified diff string, built
|
48
48
|
specifically for the diff section output by "perforce describe -du" or "git show
|
49
49
|
[commit SHA]", but with an eye towards solving a more general problem. It supports
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- diffed.gemspec
|
66
66
|
- lib/diffed.rb
|
67
67
|
- lib/diffed/version.rb
|
68
|
+
- lib/models/file.rb
|
68
69
|
- lib/models/line.rb
|
69
70
|
- lib/models/section.rb
|
70
71
|
- lib/parsers/unified.rb
|