html-diff 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/html-diff +7 -0
- data/lib/html_diff.rb +123 -0
- metadata +47 -0
data/bin/html-diff
ADDED
data/lib/html_diff.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
class HtmlDiff
|
2
|
+
attr_accessor :wd, :argv
|
3
|
+
|
4
|
+
def initialize(argv=[])
|
5
|
+
@wd = `pwd`.gsub("\n", "")
|
6
|
+
@argv = argv
|
7
|
+
end
|
8
|
+
|
9
|
+
def stats_line
|
10
|
+
stats=`git diff --stat #{@argv.join(" ")}`
|
11
|
+
stats.scan(/\d+ files? changed, \d+ insertions?\(\+\), \d+ deletions?\(\-\)/).last
|
12
|
+
end
|
13
|
+
|
14
|
+
def branch
|
15
|
+
status=`git status`
|
16
|
+
status.scan(/# On branch (.*)\n/).last.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def html_diff
|
20
|
+
diff=`git diff #{@argv.join(" ")}`
|
21
|
+
diff.gsub!(/^diff \-\-git a\/([^\s]*).*\n.*$/) { "<div class='diff-file'>"+$1+"</div>" }
|
22
|
+
diff.gsub!(/^(\-\-\-\s)(a.*)$/) { "<div class='code'><span class='delete'>"+$1+" "+$2+"</span>" }
|
23
|
+
diff.gsub!(/(\n\<div class\=\'diff-file\'\>)/) { "</div>"+$1}
|
24
|
+
diff.gsub!(/^(\@\@.*)$/) { "<br><span class='at-linenums'>"+$1+"</span>"}
|
25
|
+
|
26
|
+
diff.gsub!(/^(\++)(.*)$/) { "<span class='add'>"+$1+" "+$2+"</span>" }
|
27
|
+
diff.gsub!(/^(\-+)(.*)$/) { "<span class='delete'>"+$1+" "+$2+"</span>" }
|
28
|
+
diff
|
29
|
+
end
|
30
|
+
|
31
|
+
def initial_content
|
32
|
+
'''
|
33
|
+
<!DOCTYPE html>
|
34
|
+
|
35
|
+
<html>
|
36
|
+
<head>
|
37
|
+
<title></title>
|
38
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
|
39
|
+
<style>
|
40
|
+
body {
|
41
|
+
font-family: "Lucida Console", Monaco, monospace;
|
42
|
+
font-size: 13px;
|
43
|
+
padding-bottom: 50px;
|
44
|
+
}
|
45
|
+
h2 {
|
46
|
+
text-align: center;
|
47
|
+
font-size: 1.4em;
|
48
|
+
}
|
49
|
+
.diff-file {
|
50
|
+
background: -webkit-linear-gradient(#fafafa, #eaeaea);
|
51
|
+
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#fafafa\',endColorstr=\'#eaeaea\')";
|
52
|
+
border: 1px solid #d8d8d8;
|
53
|
+
border-bottom: 0;
|
54
|
+
color: #555;
|
55
|
+
font: 14px sans-serif;
|
56
|
+
overflow: hidden;
|
57
|
+
padding: 12px 25px;
|
58
|
+
text-shadow: 0 1px 0 white;
|
59
|
+
width: 80%;
|
60
|
+
margin: 50px auto 0;
|
61
|
+
float: none;
|
62
|
+
}
|
63
|
+
.code .add {
|
64
|
+
background-color: #DDFFDD;
|
65
|
+
padding: 1px 2% 1px 10px;
|
66
|
+
margin-left: -25px;
|
67
|
+
display:inline-block;
|
68
|
+
width: 105%;
|
69
|
+
}
|
70
|
+
.code .delete {
|
71
|
+
background-color: #FFDDDD;
|
72
|
+
padding: 1px 2% 1px 10px;
|
73
|
+
margin-left: -25px;
|
74
|
+
display:inline-block;
|
75
|
+
width: 105%;
|
76
|
+
}
|
77
|
+
.code .at-linenums {
|
78
|
+
color: #9B9B99;
|
79
|
+
}
|
80
|
+
.tab {
|
81
|
+
width: 50px;
|
82
|
+
height: 13px;
|
83
|
+
display: inline-block;
|
84
|
+
}
|
85
|
+
.code {
|
86
|
+
border: 1px solid #cacaca;
|
87
|
+
line-height: 1.7em;
|
88
|
+
overflow: hidden;
|
89
|
+
-webkit-border-radius: 0 0 3px 3px;
|
90
|
+
-moz-border-radius: 0 0 3px 3px;
|
91
|
+
border-radius: 0 0 3px 3px;
|
92
|
+
-moz-background-clip: padding;
|
93
|
+
-webkit-background-clip: padding-box;
|
94
|
+
background-clip: padding-box;
|
95
|
+
background-color: #FAFAFB;
|
96
|
+
color: #393939;
|
97
|
+
padding: 5px 25px;
|
98
|
+
width: 80%;
|
99
|
+
margin: -18px auto;
|
100
|
+
}
|
101
|
+
</style>
|
102
|
+
</head>
|
103
|
+
<body>
|
104
|
+
'''
|
105
|
+
end
|
106
|
+
|
107
|
+
def content
|
108
|
+
content = initial_content
|
109
|
+
content += "<h2>" + branch + "<br>" + stats_line + "</h2>"
|
110
|
+
content += "<pre>"+html_diff
|
111
|
+
content += "</pre></body></html>"
|
112
|
+
end
|
113
|
+
|
114
|
+
def make_diff
|
115
|
+
File.open(@wd+"/mydiff.html", "wb+") do |f|
|
116
|
+
f.write(content)
|
117
|
+
end
|
118
|
+
|
119
|
+
`open #{@wd}/mydiff.html`
|
120
|
+
`sleep 5 && rm #{@wd}/mydiff.html`
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html-diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sarah Adams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A pretty, html-formatted git diff
|
15
|
+
email: sadams.codes@gmail.com
|
16
|
+
executables:
|
17
|
+
- html-diff
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/html_diff.rb
|
22
|
+
- bin/html-diff
|
23
|
+
homepage: http://rubygems.org/gems/html-diff
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.23
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: HTML git-diff
|
47
|
+
test_files: []
|