diff2xml 0.0.2
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/CHANGELOG +3 -0
- data/README +3 -0
- data/Rakefile +85 -0
- data/bin/diff2xml +167 -0
- data/lib/diff2xml.rb +1 -0
- data/lib/diff2xml/diff2html.rb +158 -0
- data/lib/diff2xml/diff2rss20.rb +118 -0
- data/lib/diff2xml/handler.rb +57 -0
- data/lib/diff2xml/parser.rb +77 -0
- data/lib/diff2xml/version.rb +36 -0
- data/lib/diff2xml/xmltool.rb +51 -0
- data/test/diff2xml_test.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +70 -0
data/CHANGELOG
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
include FileUtils
|
11
|
+
require File.join(File.dirname(__FILE__), 'lib', 'diff2xml', 'version')
|
12
|
+
|
13
|
+
AUTHOR = "xoinu"
|
14
|
+
EMAIL = "xoinu@mac.com"
|
15
|
+
DESCRIPTION = "Generate xml (xhtml, rss, etc.) from unified diff. This package contains diff2xml command-line tool and reusable diff-parser framework."
|
16
|
+
RUBYFORGE_PROJECT = "diff2xml"
|
17
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
18
|
+
BIN_FILES = %w(diff2xml)
|
19
|
+
|
20
|
+
|
21
|
+
NAME = "diff2xml"
|
22
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
|
+
VERS = ENV['VERSION'] || (Diff2Xml::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
24
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
|
+
RDOC_OPTS = ['--quiet', '--title', "diff2xml documentation",
|
26
|
+
"--opname", "index.html",
|
27
|
+
"--line-numbers",
|
28
|
+
"--main", "README",
|
29
|
+
"--inline-source"]
|
30
|
+
|
31
|
+
desc "Packages up diff2xml gem."
|
32
|
+
task :default => [:test]
|
33
|
+
task :package => [:clean]
|
34
|
+
|
35
|
+
Rake::TestTask.new("test") { |t|
|
36
|
+
t.libs << "test"
|
37
|
+
t.pattern = "test/**/*_test.rb"
|
38
|
+
t.verbose = true
|
39
|
+
}
|
40
|
+
|
41
|
+
spec =
|
42
|
+
Gem::Specification.new do |s|
|
43
|
+
s.name = NAME
|
44
|
+
s.version = VERS
|
45
|
+
s.platform = Gem::Platform::RUBY
|
46
|
+
s.has_rdoc = true
|
47
|
+
s.extra_rdoc_files = ["README", "CHANGELOG"]
|
48
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
49
|
+
s.summary = DESCRIPTION
|
50
|
+
s.description = DESCRIPTION
|
51
|
+
s.author = AUTHOR
|
52
|
+
s.email = EMAIL
|
53
|
+
s.homepage = HOMEPATH
|
54
|
+
s.executables = BIN_FILES
|
55
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
56
|
+
s.bindir = "bin"
|
57
|
+
s.require_path = "lib"
|
58
|
+
s.autorequire = "diff2xml"
|
59
|
+
|
60
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
61
|
+
#s.required_ruby_version = '>= 1.8.2'
|
62
|
+
|
63
|
+
s.files = %w(README CHANGELOG Rakefile) +
|
64
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
65
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
66
|
+
Dir.glob("examples/**/*.rb") +
|
67
|
+
Dir.glob("tools/*.rb")
|
68
|
+
|
69
|
+
# s.extensions = FileList["ext/**/extconf.rb"].to_a
|
70
|
+
end
|
71
|
+
|
72
|
+
Rake::GemPackageTask.new(spec) do |p|
|
73
|
+
p.need_tar = true
|
74
|
+
p.gem_spec = spec
|
75
|
+
end
|
76
|
+
|
77
|
+
task :install do
|
78
|
+
name = "#{NAME}-#{VERS}.gem"
|
79
|
+
sh %{rake package}
|
80
|
+
sh %{sudo gem install pkg/#{name}}
|
81
|
+
end
|
82
|
+
|
83
|
+
task :uninstall => [:clean] do
|
84
|
+
sh %{sudo gem uninstall #{NAME}}
|
85
|
+
end
|
data/bin/diff2xml
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
# -*- Ruby -*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006, xoinu
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
15
|
+
# be used to endorse or promote products derived from this software
|
16
|
+
# without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
#
|
29
|
+
require 'optparse'
|
30
|
+
require 'diff2xml.rb'
|
31
|
+
|
32
|
+
module Diff2Xml
|
33
|
+
def print_version(os)
|
34
|
+
os << <<PRINT_VERSION
|
35
|
+
diff2xml version #{VERSION::STRING}, (c) 2006-2007 Junnosuke Yamazaki
|
36
|
+
PRINT_VERSION
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_usage
|
40
|
+
STDERR.print <<USAGE
|
41
|
+
Usage: diff2xml input_file [-s css_name] [-g] [-o html_name] ...
|
42
|
+
-d, --desc=description specify <description> field of rss
|
43
|
+
-f, --format=html 'html', 'rss20' (default: html)
|
44
|
+
-g, --generate-css generate a css file for html
|
45
|
+
-h, --help show this help
|
46
|
+
-l, --lang=en-us specify language (default: en-us)
|
47
|
+
-o, --output=html_name ouput file name
|
48
|
+
-s, --style=css_name specify stylesheet file name for html
|
49
|
+
-t, --title=title_name specify <title> field for rss
|
50
|
+
-u, --url=url_name specify the base url for rss
|
51
|
+
-v, --verbose show more information
|
52
|
+
-V, --version show version
|
53
|
+
|
54
|
+
Example: % diff2xml -g # generate css
|
55
|
+
% svn diff | diff2xml > diff_result.html # generate html
|
56
|
+
% diff2xml -f rss20 diff.txt -u 'http://xoi.nu/' > diff.rss # generate rss
|
57
|
+
USAGE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
include Diff2Xml
|
62
|
+
|
63
|
+
css_name = 'diff2html.css'
|
64
|
+
options = Hash.new
|
65
|
+
|
66
|
+
#
|
67
|
+
# Parse options
|
68
|
+
#
|
69
|
+
OptionParser.new do |opt|
|
70
|
+
begin
|
71
|
+
opt.on('-d VAL', '--desc=VAL') {|v| options[:d] = v }
|
72
|
+
opt.on('-f VAL', '--format=VAL') {|v| options[:f] = v }
|
73
|
+
opt.on('-g', '--generate-css') {|v| options[:g] = v }
|
74
|
+
opt.on('-h', '--help') {|v| options[:h] = v }
|
75
|
+
opt.on('-l VAL', '--lang=VAL') {|v| options[:l] = v }
|
76
|
+
opt.on('-o VAL', '--output=VAL') {|v| options[:o] = v }
|
77
|
+
opt.on('-s VAL', '--style=VAL') {|v| options[:s] = v }
|
78
|
+
opt.on('-t VAL', '--title=VAL') {|v| options[:t] = v }
|
79
|
+
opt.on('-v VAL', '--verbose') {|v| options[:e] = v }
|
80
|
+
opt.on('-V', '--version') {|v| options[:v] = v }
|
81
|
+
opt.parse!(ARGV)
|
82
|
+
rescue
|
83
|
+
STDERR.puts 'ERROR: Invalid option was passed.'
|
84
|
+
print_usage
|
85
|
+
exit 0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Evalueate -h, --help
|
91
|
+
#
|
92
|
+
if options[:h]
|
93
|
+
print_version(STDERR) if options[:v]
|
94
|
+
print_usage
|
95
|
+
exit 0
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Evaluate -V, --version
|
100
|
+
#
|
101
|
+
if options[:v]
|
102
|
+
print_version(STDERR)
|
103
|
+
exit 0
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# Evaluate -s, --style
|
108
|
+
#
|
109
|
+
css_name = options[:s] if options[:s]
|
110
|
+
|
111
|
+
#
|
112
|
+
# Evaluate -g, --generate-css
|
113
|
+
#
|
114
|
+
if options[:g]
|
115
|
+
File.open(css_name, 'w') {|f| Diff2Html::print_default_css(f) }
|
116
|
+
puts "#{css_name} was written."
|
117
|
+
exit 0
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Evaluate -f, --format
|
122
|
+
#
|
123
|
+
options[:f] = 'html' if !options[:f]
|
124
|
+
|
125
|
+
case options[:f]
|
126
|
+
when 'html'
|
127
|
+
handler = Diff2Html.new
|
128
|
+
handler.css_name = css_name
|
129
|
+
when 'rss20'
|
130
|
+
#
|
131
|
+
# Evaluate -t, -d, -l, -u
|
132
|
+
#
|
133
|
+
handler = Diff2Rss20.new
|
134
|
+
handler.title = options[:t] if options[:t]
|
135
|
+
handler.desc = options[:d] if options[:d]
|
136
|
+
handler.lang = options[:l] if options[:l]
|
137
|
+
handler.url = options[:u] if options[:u]
|
138
|
+
#
|
139
|
+
# Evaluate -v, --verbose
|
140
|
+
#
|
141
|
+
if options[:e]
|
142
|
+
STDERR << <<VERBOSE
|
143
|
+
url: #{app.url}
|
144
|
+
language: #{app.lang}
|
145
|
+
title: #{app.title}
|
146
|
+
description: #{app.desc}
|
147
|
+
VERBOSE
|
148
|
+
end
|
149
|
+
else
|
150
|
+
end
|
151
|
+
|
152
|
+
begin
|
153
|
+
#
|
154
|
+
# evaluate -o, --output
|
155
|
+
#
|
156
|
+
istream = ARGV.size > 0 ? File.open(ARGV[0], 'r') : STDIN
|
157
|
+
ostream = options[:o] ? File.open(options[:o], 'w') : STDOUT
|
158
|
+
|
159
|
+
handler.ostream = ostream
|
160
|
+
Parser.new(handler).parse(istream)
|
161
|
+
rescue
|
162
|
+
STDERR.puts 'ERROR: Invalid option was passed.'
|
163
|
+
print_usage
|
164
|
+
ensure
|
165
|
+
istream.close if istream && istream != STDIN
|
166
|
+
ostream.close if ostream && ostream != STDOUT
|
167
|
+
end
|
data/lib/diff2xml.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'diff2xml/**/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
require File.dirname(__FILE__) + '/parser'
|
29
|
+
require File.dirname(__FILE__) + '/handler'
|
30
|
+
require File.dirname(__FILE__) + '/xmltool'
|
31
|
+
|
32
|
+
module Diff2Xml
|
33
|
+
class Diff2Html
|
34
|
+
include Handler
|
35
|
+
include XmlTool
|
36
|
+
|
37
|
+
attr_writer :ostream
|
38
|
+
attr_accessor :css_name
|
39
|
+
|
40
|
+
@file_count
|
41
|
+
@diff_count
|
42
|
+
@next_block
|
43
|
+
|
44
|
+
def self.print_default_css(os)
|
45
|
+
os << <<STYLE
|
46
|
+
a:link { color:#000; cursor:point; text-decoration:none }
|
47
|
+
a:hover { cursor:point; text-decoration:none }
|
48
|
+
a:visited { color:#000; cursor:point; text-decoration:none }
|
49
|
+
body { margin:0px; font-family:\"Verdana\",Serif; background-color:#fff }
|
50
|
+
h4.title { margin:20px 0px 10px 10px }
|
51
|
+
table { padding:0px; margin:0px; border-collapse:collapse; }
|
52
|
+
th.title { border-width:8px 0px 8px 0px; border-color:Green; border-style:solid; font-family:\"Verdana\"; font-size:1.25em; text-align:left; padding:10px 10px 10px 20px; background-color:#fff }
|
53
|
+
th, td { font-family:\"Courier New\",Monospace; font-size:.9em; padding-left:20px }
|
54
|
+
td.del { background-color:#888 }
|
55
|
+
td.add { font-weight:bold; font-size:.9em; background-color:#ff0 }
|
56
|
+
td.blank { background-color:DarkGray }
|
57
|
+
td.same,td.omit { color:#444; background-color:#ccc }
|
58
|
+
td.omit { font-weight:bold; padding:20px }
|
59
|
+
span.c, span.g, span.m { color:#f00 }
|
60
|
+
span.a, span.u, span.p { color:#00f }
|
61
|
+
span.d { color:#880 }
|
62
|
+
p.timestamp { font-size:.8em; margin-right:20px }
|
63
|
+
p.result { text-align:center; font-weight:bold; font-size:.8em; margin-right:20px }
|
64
|
+
p.diff2html-header { padding:10px; margin:0px }
|
65
|
+
STYLE
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(os = STDOUT, inline_css = false, css = 'diff2html.css')
|
69
|
+
@file_count = 0
|
70
|
+
@diff_count = 0
|
71
|
+
@next_block = false
|
72
|
+
@ostream = os
|
73
|
+
@inline_css = inline_css
|
74
|
+
@css_name = css
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Override
|
79
|
+
#
|
80
|
+
|
81
|
+
def start_parse
|
82
|
+
@ostream << <<HEAD
|
83
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
84
|
+
<html>
|
85
|
+
<head>
|
86
|
+
<title>diff2html result</title>
|
87
|
+
HEAD
|
88
|
+
|
89
|
+
if @inline_css
|
90
|
+
@ostream.puts '<style>'
|
91
|
+
Diff2Html.print_default_css(@ostream)
|
92
|
+
@ostream.puts '</style>'
|
93
|
+
else
|
94
|
+
@ostream.puts "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{@css_name}\" />"
|
95
|
+
end
|
96
|
+
|
97
|
+
@ostream << <<HEAD
|
98
|
+
</head>
|
99
|
+
<body>
|
100
|
+
<p class="diff2html-header">Created on #{Time.now}</p>
|
101
|
+
<table cellspacing=\"0\" cellpadding=\"0\">
|
102
|
+
HEAD
|
103
|
+
end
|
104
|
+
|
105
|
+
def end_parse
|
106
|
+
@ostream.puts "</table>\n</body>\n</html>"
|
107
|
+
end
|
108
|
+
|
109
|
+
def start_document(source, target)
|
110
|
+
source = sanitize(source)
|
111
|
+
target = sanitize(target)
|
112
|
+
title = ""
|
113
|
+
if source == target then
|
114
|
+
title = source
|
115
|
+
else
|
116
|
+
title = "Source: #{source}<br/>Target: #{target}"
|
117
|
+
end
|
118
|
+
@ostream.puts "<tr><th class=\"title\"><a name=\"file_#{@file_count}\"/><a name=\"#{source}\"/><a href=\"#file_#{@file_count+1}\">#{title}</a></th></tr>"
|
119
|
+
@file_count = @file_count + 1
|
120
|
+
end
|
121
|
+
|
122
|
+
def end_document
|
123
|
+
end
|
124
|
+
|
125
|
+
def start_block(source_base, source_length, target_base, target_length)
|
126
|
+
@ostream.puts "<tr><td class=\"omit\">(From line #{source_base} to #{source_base.to_i+source_length.to_i})</td></tr>"
|
127
|
+
@next_block = true
|
128
|
+
end
|
129
|
+
|
130
|
+
def source_line(line)
|
131
|
+
line = sanitize(line)
|
132
|
+
if @next_block then
|
133
|
+
@diff_count = @diff_count + 1
|
134
|
+
@next_block = false
|
135
|
+
@ostream.puts "<tr><td class=\"del\"><a name=\"diff_#{@diff_count}\"/><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
|
136
|
+
else
|
137
|
+
@ostream.puts "<tr><td class=\"del\"><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def target_line(line)
|
142
|
+
line = sanitize(line)
|
143
|
+
if @next_block then
|
144
|
+
@diff_count = @diff_count + 1
|
145
|
+
@next_block = false
|
146
|
+
@ostream.puts "<tr><td class=\"add\"><a name=\"diff_#{@diff_count}\"/><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
|
147
|
+
else
|
148
|
+
@ostream.puts "<tr><td class=\"add\"><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def common_line(line)
|
153
|
+
line = sanitize(line)
|
154
|
+
@ostream.puts "<tr><td class=\"same\">#{line}</td></tr>"
|
155
|
+
@next_block = true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
require 'kconv'
|
29
|
+
require 'diff2xml/parser'
|
30
|
+
require 'diff2xml/handler'
|
31
|
+
require 'diff2xml/xmltool'
|
32
|
+
|
33
|
+
module Diff2Xml
|
34
|
+
class Diff2Rss20
|
35
|
+
include XmlTool
|
36
|
+
include Handler
|
37
|
+
|
38
|
+
attr_accessor :title, :desc, :lang, :url
|
39
|
+
attr_writer :ostream
|
40
|
+
|
41
|
+
@now
|
42
|
+
@str_buffer
|
43
|
+
|
44
|
+
def initialize(os = STDOUT, url = 'http://localhost/', title = 'Diff2Xml', desc = 'Diff RSS', lang = 'en-us')
|
45
|
+
@ostream = os
|
46
|
+
@url = url
|
47
|
+
@title = title
|
48
|
+
@desc = desc
|
49
|
+
@lang = lang
|
50
|
+
@now = Time.now
|
51
|
+
@str_buffer = ''
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Override
|
56
|
+
#
|
57
|
+
|
58
|
+
def start_parse
|
59
|
+
@str_buffer << <<HEAD
|
60
|
+
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
61
|
+
<rss version=\"2.0\">
|
62
|
+
<channel>
|
63
|
+
<title>#{@title}</title>
|
64
|
+
<description>#{@desc}</description>
|
65
|
+
<language>#{@lang}/language>
|
66
|
+
HEAD
|
67
|
+
end
|
68
|
+
|
69
|
+
def end_parse
|
70
|
+
@str_buffer << "</channel>\n</rss>"
|
71
|
+
@str_buffer = Kconv.toutf8(@str_buffer)
|
72
|
+
@ostream.print @str_buffer
|
73
|
+
end
|
74
|
+
|
75
|
+
def start_document(source, target)
|
76
|
+
@str_buffer << <<HEADER
|
77
|
+
<item>
|
78
|
+
<title>#{source}</title>
|
79
|
+
<link>#{@url}##{source}</link>
|
80
|
+
<author>Diff2Xml::Diff2Rss20</author>
|
81
|
+
<pubDate>#{@now}</pubDate>
|
82
|
+
<description>
|
83
|
+
<![CDATA[
|
84
|
+
HEADER
|
85
|
+
@now = @now.succ
|
86
|
+
end
|
87
|
+
|
88
|
+
def end_document
|
89
|
+
@str_buffer << "]]>\n</description>\n</item>"
|
90
|
+
end
|
91
|
+
|
92
|
+
def start_block(sourceBase, sourceLength, targetBase, targetLength)
|
93
|
+
@str_buffer << <<BLOCK
|
94
|
+
<h3>From #{sourceBase} to #{sourceBase.to_i+sourceLength.to_i}</h3>
|
95
|
+
<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">
|
96
|
+
BLOCK
|
97
|
+
end
|
98
|
+
|
99
|
+
def end_block
|
100
|
+
@str_buffer << "</table>"
|
101
|
+
end
|
102
|
+
|
103
|
+
def source_line(line)
|
104
|
+
line = sanitize(line)
|
105
|
+
@str_buffer << "<tr><td bgcolor=\"#aaaaaa\"><tt>#{line}</tt></td></tr>"
|
106
|
+
end
|
107
|
+
|
108
|
+
def target_line(line)
|
109
|
+
line = sanitize(line)
|
110
|
+
@str_buffer << "<tr><td bgcolor=\"#ffff00\"><tt>#{line}</tt></td></tr>"
|
111
|
+
end
|
112
|
+
|
113
|
+
def common_line(line)
|
114
|
+
line = sanitize(line)
|
115
|
+
@str_buffer << "<tr><td bgcolor=\"#dddddd\"><tt>#{line}</tt></td></tr>"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
module Diff2Xml
|
29
|
+
module Handler
|
30
|
+
def start_parse
|
31
|
+
end
|
32
|
+
|
33
|
+
def end_parse
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_document(source, target)
|
37
|
+
end
|
38
|
+
|
39
|
+
def end_document
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_block(sourceBase, sourceLength, targetBase, targetLength)
|
43
|
+
end
|
44
|
+
|
45
|
+
def end_block
|
46
|
+
end
|
47
|
+
|
48
|
+
def source_line(line)
|
49
|
+
end
|
50
|
+
|
51
|
+
def target_line(line)
|
52
|
+
end
|
53
|
+
|
54
|
+
def common_line(line)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
module Diff2Xml
|
29
|
+
class Parser
|
30
|
+
@source
|
31
|
+
@started
|
32
|
+
@block_started
|
33
|
+
@handler
|
34
|
+
|
35
|
+
def initialize(handler)
|
36
|
+
@source = ""
|
37
|
+
@started = false
|
38
|
+
@block_started = false
|
39
|
+
@handler = handler
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse(istream)
|
43
|
+
@handler.start_parse
|
44
|
+
istream.each do |line|
|
45
|
+
if /^\-\-\-[\t\s]*([\w+\.\/\\\:]+)/.match(line) then
|
46
|
+
@source = $1
|
47
|
+
elsif /^\+\+\+[\t\s]*([\w+\.\/\\\:]+)/.match(line) then
|
48
|
+
target = $1
|
49
|
+
if @started then
|
50
|
+
@handler.end_document
|
51
|
+
end
|
52
|
+
@handler.start_document(@source, target)
|
53
|
+
@started = true
|
54
|
+
elsif /^\-(.*)/.match(line) then
|
55
|
+
@handler.source_line($1)
|
56
|
+
elsif /^\+(.*)/.match(line) then
|
57
|
+
@handler.target_line($1)
|
58
|
+
elsif /^\s(.*)/.match(line) then
|
59
|
+
@handler.common_line($1)
|
60
|
+
elsif /^@@\s\-(\d+),(\d+)\s\+(\d+),(\d+)\s@@/.match(line) then
|
61
|
+
if @block_started then
|
62
|
+
@handler.end_block
|
63
|
+
end
|
64
|
+
@handler.start_block($1, $2, $3, $4)
|
65
|
+
@block_started = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if @block_started then
|
69
|
+
@handler.end_block
|
70
|
+
end
|
71
|
+
if @started then
|
72
|
+
@handler.end_document
|
73
|
+
end
|
74
|
+
@handler.end_parse
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
module Diff2Xml #:nodoc:
|
29
|
+
module VERSION #:nodoc:
|
30
|
+
MAJOR = 0
|
31
|
+
MINOR = 0
|
32
|
+
TINY = 2
|
33
|
+
|
34
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006, xoinu
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of the Xoinu nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
module Diff2Xml
|
29
|
+
module XmlTool
|
30
|
+
def convert_illegal_characters(str)
|
31
|
+
ret = str.chomp
|
32
|
+
ret.gsub!( '&', '&' )
|
33
|
+
ret.gsub!('\'', ''')
|
34
|
+
ret.gsub!('"', '"')
|
35
|
+
ret.gsub!( '<', '<' )
|
36
|
+
ret.gsub!( '>', '>' )
|
37
|
+
ret.gsub!("\t", ' ')
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
|
41
|
+
def convert_space(str)
|
42
|
+
ret = str.gsub(' ', ' ')
|
43
|
+
0 == ret.length ? ' ' : ret
|
44
|
+
end
|
45
|
+
|
46
|
+
def sanitize(str)
|
47
|
+
ret = convert_illegal_characters(str)
|
48
|
+
ret = convert_space(ret)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: diff2xml
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-08-14 00:00:00 -07:00
|
8
|
+
summary: Generate xml (xhtml, rss, etc.) from unified diff. This package contains diff2xml command-line tool and reusable diff-parser framework.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: xoinu@mac.com
|
12
|
+
homepage: http://diff2xml.rubyforge.org
|
13
|
+
rubyforge_project: diff2xml
|
14
|
+
description: Generate xml (xhtml, rss, etc.) from unified diff. This package contains diff2xml command-line tool and reusable diff-parser framework.
|
15
|
+
autorequire: diff2xml
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- xoinu
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- CHANGELOG
|
34
|
+
- Rakefile
|
35
|
+
- bin/diff2xml
|
36
|
+
- test/diff2xml_test.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
- lib/diff2xml
|
39
|
+
- lib/diff2xml.rb
|
40
|
+
- lib/diff2xml/diff2html.rb
|
41
|
+
- lib/diff2xml/diff2rss20.rb
|
42
|
+
- lib/diff2xml/handler.rb
|
43
|
+
- lib/diff2xml/parser.rb
|
44
|
+
- lib/diff2xml/version.rb
|
45
|
+
- lib/diff2xml/xmltool.rb
|
46
|
+
test_files: []
|
47
|
+
|
48
|
+
rdoc_options:
|
49
|
+
- --quiet
|
50
|
+
- --title
|
51
|
+
- diff2xml documentation
|
52
|
+
- --opname
|
53
|
+
- index.html
|
54
|
+
- --line-numbers
|
55
|
+
- --main
|
56
|
+
- README
|
57
|
+
- --inline-source
|
58
|
+
- --exclude
|
59
|
+
- ^(examples|extras)/
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README
|
62
|
+
- CHANGELOG
|
63
|
+
executables:
|
64
|
+
- diff2xml
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
dependencies: []
|
70
|
+
|