twiki2markdown 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.project +18 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/twiki2markdown +78 -0
- data/bin/twiki2markdown.jar +0 -0
- data/lib/twiki2markdown.rb +109 -0
- data/pom.xml +38 -0
- data/src/main/java/com/zaubersoftware/labs/twiki2markdown/App.java +44 -0
- data/src/test/java/com/zaubersoftware/labs/twiki2markdown/test/TwikiToMarkdownTest.java +43 -0
- data/test/helper.rb +18 -0
- data/test/test_gollum/Home.md +5 -0
- data/test/test_gollum/images/Home/baboon.png +0 -0
- data/test/test_twiki/data/sample_wiki/WebHome.txt +5 -0
- data/test/test_twiki/data/sample_wiki/WebInfo.txt +0 -0
- data/test/test_twiki/pub/sample_wiki/WebHome/baboon.jpg,v +0 -0
- data/test/test_twiki/pub/sample_wiki/WebHome/baboon.png +0 -0
- data/test/test_twiki2markdown.rb +70 -0
- data/twiki2markdown.gemspec +75 -0
- metadata +131 -0
data/.document
ADDED
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>twiki2markdown</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
<nature>com.aptana.projects.webnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Add dependencies to develop your gem here.
|
4
|
+
# Include everything needed to run rake, tests, features, etc.
|
5
|
+
group :development do
|
6
|
+
gem "shoulda"
|
7
|
+
gem 'shoulda-context'
|
8
|
+
gem "bundler"
|
9
|
+
gem "jeweler"
|
10
|
+
gem "rcov"
|
11
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.9.2.2)
|
10
|
+
rcov (0.9.11)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
shoulda-context (1.0.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler
|
19
|
+
jeweler
|
20
|
+
rcov
|
21
|
+
shoulda
|
22
|
+
shoulda-context
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Cristian Pereyra
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= twiki2markdown
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to twiki2markdown
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Cristian Pereyra. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "twiki2markdown"
|
18
|
+
gem.homepage = "http://github.com/kshmir/twiki2markdown"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Gem for migrating a TWiki-based wiki to a github wiki with markdown syntax"
|
21
|
+
gem.description = "This gem handles the migration and commit of a TWiki project to a github wiki, uses java in the backend to parse the files"
|
22
|
+
gem.email = "cristianpereyra@zaubersoftware.com"
|
23
|
+
gem.authors = ["Cristian Pereyra"]
|
24
|
+
gem.executables = [ "twiki2markdown", "twiki2markdown.jar" ]
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
test.rcov_opts << '--exclude "gems/*"'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "twiki2markdown #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/twiki2markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'twiki2markdown'
|
5
|
+
|
6
|
+
# This hash will hold all of the options
|
7
|
+
# parsed from the command-line by
|
8
|
+
# OptionParser.
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
optparse = OptionParser.new do|opts|
|
12
|
+
# Set a banner, displayed at the top
|
13
|
+
# of the help screen.
|
14
|
+
opts.banner = "twiki2markdown - Migrate TWiki to Github"
|
15
|
+
|
16
|
+
options[:branch] = 'master'
|
17
|
+
opts.on( '-b', '--branch name', 'Branch for pushing to the repository, master by default' ) do |name|
|
18
|
+
options[:branch] = name
|
19
|
+
end
|
20
|
+
|
21
|
+
options[:remote] = 'origin'
|
22
|
+
opts.on( '-r', '--remote name', 'Name of the git remote' ) do |name|
|
23
|
+
options[:remote] = name
|
24
|
+
end
|
25
|
+
|
26
|
+
options[:commit] = 'twiki2markdown migration'
|
27
|
+
opts.on( '-c', '--commit message', 'Message of the update commit' ) do |message|
|
28
|
+
options[:commit] = message
|
29
|
+
end
|
30
|
+
|
31
|
+
options[:push] = nil
|
32
|
+
opts.on( '-p', '--push', 'Push the content to the server, true to push' ) do
|
33
|
+
options[:push] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
options[:repo] = nil
|
38
|
+
opts.on( '-u', '--repo URL', 'Repo URL' ) do |url|
|
39
|
+
options[:repo] = url
|
40
|
+
end
|
41
|
+
|
42
|
+
# Define the options, and what they do
|
43
|
+
options[:verbose] = false
|
44
|
+
opts.on( '-v', '--verbose', 'Output more information' ) do
|
45
|
+
options[:verbose] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
options[:logfile] = "/dev/null"
|
49
|
+
opts.on( '-l', '--logfile FILE', 'Write log to FILE. Use /dev/stdout to get output for everything' ) do|file|
|
50
|
+
options[:logfile] = file
|
51
|
+
end
|
52
|
+
|
53
|
+
options[:from] = nil
|
54
|
+
opts.on( '-f', '--from PATH', 'Path to twiki_root/data/folder_to_migrate' ) do|file|
|
55
|
+
options[:from] = file
|
56
|
+
end
|
57
|
+
|
58
|
+
options[:to] = nil
|
59
|
+
opts.on( '-t', '--to PATH', 'Path to migration folder' ) do|file|
|
60
|
+
options[:to] = file
|
61
|
+
end
|
62
|
+
|
63
|
+
# This displays the help screen, all programs are
|
64
|
+
# assumed to have this option.
|
65
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
66
|
+
puts opts
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Parse the command-line. Remember there are two forms
|
72
|
+
# of the parse method. The 'parse' method simply parses
|
73
|
+
# ARGV, while the 'parse!' method parses ARGV and removes
|
74
|
+
# any options found there, as well as any parameters for
|
75
|
+
# the options. What's left is the list of files to resize.
|
76
|
+
optparse.parse!
|
77
|
+
|
78
|
+
Twiki2Markdown.do_migration(options)
|
Binary file
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# A script that will pretend to resize a number of images
|
3
|
+
require 'fileutils'
|
4
|
+
require 'iconv'
|
5
|
+
|
6
|
+
class Twiki2Markdown
|
7
|
+
def self.do_migration(args)
|
8
|
+
|
9
|
+
location = File.expand_path "#{File.dirname(__FILE__)}/../bin/"
|
10
|
+
|
11
|
+
if (not args[:from] or not args[:to])
|
12
|
+
puts "twiki2markdown --help for usage info"
|
13
|
+
else
|
14
|
+
args[:branch] ||= "master"
|
15
|
+
args[:remote] ||= "origin"
|
16
|
+
args[:logfile] ||= "/dev/null"
|
17
|
+
args[:commit] ||= "migrating with twiki2markdown"
|
18
|
+
|
19
|
+
added_files = []
|
20
|
+
|
21
|
+
start_dir = args[:from]
|
22
|
+
last_dir = args[:from].split(/\//).last
|
23
|
+
to_dir = args[:to]
|
24
|
+
image_dir = File.expand_path "#{args[:from]}/../../pub/#{last_dir}"
|
25
|
+
|
26
|
+
FileUtils.mkdir to_dir unless File.exists? to_dir
|
27
|
+
FileUtils.mkdir "#{to_dir}/images" unless File.exists? "#{to_dir}/images"
|
28
|
+
|
29
|
+
dir = Dir.open(start_dir)
|
30
|
+
dir.each do |file|
|
31
|
+
added_files.push file if file.match(/^.*\.txt$/)
|
32
|
+
end
|
33
|
+
|
34
|
+
if not File.exists? to_dir
|
35
|
+
Dir.mkdir to_dir
|
36
|
+
end
|
37
|
+
|
38
|
+
added_files = Iconv.open("utf8","iso8859-1") { |cd|
|
39
|
+
added_files.collect { |s| cd.iconv(s) }
|
40
|
+
}
|
41
|
+
|
42
|
+
added_files.each do |file|
|
43
|
+
|
44
|
+
if file.match(/Web[A-Z]+[a-z0-9]+/) and not file.match(/WebHome/)
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
if (file.match(/(á|ñ|í|ó|ú|é)/))
|
49
|
+
new_file = file.gsub /(á|ñ|í|ó|ú|é)/, ""
|
50
|
+
FileUtils.mv "#{start_dir}/#{file}", "#{start_dir}/#{new_file}"
|
51
|
+
file = new_file
|
52
|
+
end
|
53
|
+
|
54
|
+
destination = File.new(to_dir + "/" + file.gsub(/\.txt/,".md"), "w+")
|
55
|
+
|
56
|
+
if args[:verbose]
|
57
|
+
puts "Parsing #{file}"
|
58
|
+
else
|
59
|
+
print "."
|
60
|
+
STDOUT.flush
|
61
|
+
end
|
62
|
+
|
63
|
+
simple_name = file.gsub(/\.txt/,"")
|
64
|
+
|
65
|
+
if File.exists? "#{image_dir}/#{simple_name}"
|
66
|
+
unless File.exists? "#{to_dir}/images/#{simple_name.gsub(/WebHome/, "Home")}"
|
67
|
+
FileUtils.mkdir "#{to_dir}/images/#{simple_name.gsub(/WebHome/, "Home")}"
|
68
|
+
end
|
69
|
+
Dir.open("#{image_dir}/#{simple_name}/").entries.each do |entry|
|
70
|
+
next if entry.match(/^\.{1,2}$/)
|
71
|
+
unless entry.match /\,v/
|
72
|
+
FileUtils.cp("#{image_dir}/#{simple_name}/#{entry}", "#{to_dir}/images/#{simple_name.gsub(/WebHome/, "Home")}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
`java -jar #{location}/twiki2markdown.jar #{start_dir}/#{file} | iconv -f iso-8859-1 -t utf8 > #{destination.path}`
|
78
|
+
end
|
79
|
+
|
80
|
+
FileUtils.mv "#{to_dir}/WebHome.md", "#{to_dir}/Home.md"
|
81
|
+
if File.exists? "#{to_dir}/images/WebHome"
|
82
|
+
FileUtils.mv "#{to_dir}/images/WebHome","#{to_dir}/images/Home"
|
83
|
+
end
|
84
|
+
|
85
|
+
old_pwd = Dir.pwd
|
86
|
+
|
87
|
+
Dir.chdir args[:to]
|
88
|
+
|
89
|
+
if args[:repo]
|
90
|
+
`git init > #{ args[:logfile] }`
|
91
|
+
`git remote add #{ args[:remote] } #{ args[:repo] } > #{ args[:logfile] }`
|
92
|
+
`git pull #{args[:remote]} #{args[:branch]}`
|
93
|
+
end
|
94
|
+
|
95
|
+
if File.exists? ".git"
|
96
|
+
puts "Adding files to git and commiting..." if args[:verbose]
|
97
|
+
`git add . > #{ args[:logfile] }`
|
98
|
+
`git commit -m "#{ args[:commit] }"`
|
99
|
+
end
|
100
|
+
|
101
|
+
if args[:push] == true
|
102
|
+
puts "Pushing..." if args[:verbose]
|
103
|
+
`git push #{args[:remote]} #{args[:branch]} > #{ args[:logfile] }`
|
104
|
+
end
|
105
|
+
|
106
|
+
Dir.chdir old_pwd
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/pom.xml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
2
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
|
5
|
+
<parent>
|
6
|
+
<artifactId>bare</artifactId>
|
7
|
+
<groupId>com.zaubersoftware.maven.poms</groupId>
|
8
|
+
<version>1.0.10</version>
|
9
|
+
</parent>
|
10
|
+
<artifactId>twiki2docbook</artifactId>
|
11
|
+
<groupId>com.zaubersoftware.labs.twiki2docbook</groupId>
|
12
|
+
<version>1.0-SNAPSHOT</version>
|
13
|
+
|
14
|
+
<dependencies>
|
15
|
+
|
16
|
+
<dependency>
|
17
|
+
<groupId>org.apache.maven.doxia</groupId>
|
18
|
+
<artifactId>doxia-module-docbook-simple</artifactId>
|
19
|
+
<version>1.3-SNAPSHOT</version>
|
20
|
+
</dependency>
|
21
|
+
<dependency>
|
22
|
+
<groupId>org.apache.maven.doxia</groupId>
|
23
|
+
<artifactId>doxia-module-twiki</artifactId>
|
24
|
+
<version>1.3-SNAPSHOT</version>
|
25
|
+
</dependency>
|
26
|
+
<dependency>
|
27
|
+
<groupId>org.apache.maven.doxia</groupId>
|
28
|
+
<artifactId>doxia-module-markdown</artifactId>
|
29
|
+
<version>1.3-SNAPSHOT</version>
|
30
|
+
</dependency>
|
31
|
+
|
32
|
+
<dependency>
|
33
|
+
<groupId>junit</groupId>
|
34
|
+
<artifactId>junit</artifactId>
|
35
|
+
<version>4.10</version>
|
36
|
+
</dependency>
|
37
|
+
</dependencies>
|
38
|
+
</project>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2011 Zauber S.A. -- All rights reserved
|
3
|
+
*/
|
4
|
+
package com.zaubersoftware.labs.twiki2markdown;
|
5
|
+
|
6
|
+
import java.io.FileNotFoundException;
|
7
|
+
import java.io.FileReader;
|
8
|
+
import java.io.IOException;
|
9
|
+
import java.io.StringWriter;
|
10
|
+
import java.io.UnsupportedEncodingException;
|
11
|
+
|
12
|
+
import org.apache.maven.doxia.module.markdown.MarkdownSink;
|
13
|
+
import org.apache.maven.doxia.module.twiki.TWikiParser;
|
14
|
+
import org.apache.maven.doxia.parser.ParseException;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Script for migrating TWiki to Markdown.
|
18
|
+
*
|
19
|
+
* @author Cristian Pereyra
|
20
|
+
* @since Dec 26, 2011
|
21
|
+
*/
|
22
|
+
public final class App {
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Creates the App.
|
26
|
+
*/
|
27
|
+
private App() {}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @param args
|
31
|
+
* @throws IOException
|
32
|
+
* @throws ParseException
|
33
|
+
* @throws FileNotFoundException
|
34
|
+
* @throws UnsupportedEncodingException
|
35
|
+
*/
|
36
|
+
public static void main(final String[] args) throws ParseException, IOException {
|
37
|
+
FileReader reader = new FileReader(args[0]);
|
38
|
+
TWikiParser parser = new TWikiParser();
|
39
|
+
StringWriter writer = new StringWriter();
|
40
|
+
parser.parse(reader, new MarkdownSink(writer));
|
41
|
+
System.out.print(writer.getBuffer().toString());
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
package com.zaubersoftware.labs.twiki2markdown.test;
|
2
|
+
|
3
|
+
import java.io.StringReader;
|
4
|
+
import java.io.StringWriter;
|
5
|
+
|
6
|
+
import junit.framework.Assert;
|
7
|
+
|
8
|
+
import org.apache.maven.doxia.module.markdown.MarkdownSink;
|
9
|
+
import org.apache.maven.doxia.module.twiki.TWikiParser;
|
10
|
+
import org.apache.maven.doxia.parser.ParseException;
|
11
|
+
|
12
|
+
/*
|
13
|
+
* Copyright (c) 2011 Zauber S.A. -- All rights reserved
|
14
|
+
*/
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Tests compatibility between the Twiki parser and the Markdown Sink
|
18
|
+
* @author Cristian Pereyra
|
19
|
+
* @since Dec 26, 2011
|
20
|
+
*/
|
21
|
+
public class TwikiToMarkdownTest {
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Parser to test against
|
25
|
+
*/
|
26
|
+
final TWikiParser parser = new TWikiParser();
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Checks the parse as expected
|
30
|
+
* @param from String to parse
|
31
|
+
* @param expected Result desired
|
32
|
+
* @throws ParseException
|
33
|
+
*/
|
34
|
+
public final void assertParse(final String from, final String expected) throws ParseException {
|
35
|
+
|
36
|
+
StringReader reader = new StringReader(from);
|
37
|
+
StringWriter writer = new StringWriter();
|
38
|
+
parser.parse(reader, new MarkdownSink(writer));
|
39
|
+
Assert.assertEquals(expected, writer.getBuffer().toString());
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
}
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda/context'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'twiki2markdown'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
Binary file
|
File without changes
|
File without changes
|
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class TestTwiki2markdown < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "Output a TWiki file to STDOUT" do
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
context "Migrate a TWiki to Gollum" do
|
12
|
+
|
13
|
+
setup do
|
14
|
+
if File.exists? "test_gollum"
|
15
|
+
FileUtils.rm_rf "test_gollum"
|
16
|
+
end
|
17
|
+
|
18
|
+
@from_path = "test/test_twiki/data/sample_wiki"
|
19
|
+
@to_path = "test/test_gollum"
|
20
|
+
|
21
|
+
Twiki2Markdown.do_migration :from => @from_path,
|
22
|
+
:to => @to_path,
|
23
|
+
:verbose => false # Change for debugging
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
should "parse the files from one folder to another" do
|
28
|
+
from_files = Dir.open(@from_path).collect
|
29
|
+
to_files = Dir.open(@to_path).collect
|
30
|
+
|
31
|
+
from_files = from_files.map { |file| file.gsub(/\.txt/,".md").gsub(/WebHome/,"Home") }
|
32
|
+
from_files = from_files.select { |file| not (file.match(/Web[A-Z]+[a-z0-9]+/) and not file.match(/WebHome/)) }
|
33
|
+
|
34
|
+
from_files.push "images" unless from_files.include? "images"
|
35
|
+
to_files.push "images" unless to_files.include? "images"
|
36
|
+
|
37
|
+
assert_equal from_files.sort, to_files.sort
|
38
|
+
end
|
39
|
+
|
40
|
+
should "copy the images to the /images/ folder" do
|
41
|
+
from_files = Dir.open(@from_path).collect
|
42
|
+
|
43
|
+
from_files.each do |file|
|
44
|
+
next if file.match(/^\.{1,2}$/)
|
45
|
+
|
46
|
+
image_urls = []
|
47
|
+
match = nil
|
48
|
+
|
49
|
+
f = File.open("#{@from_path}/#{file}")
|
50
|
+
f.lines.each do |line|
|
51
|
+
image_urls.push match.captures.last if (match = line.match(/(<img[^<]*)src="%ATTACHURLPATH%(.*)"/))
|
52
|
+
end
|
53
|
+
f.close
|
54
|
+
|
55
|
+
|
56
|
+
image_urls.each do |image_url|
|
57
|
+
assert_equal true, File.exists?("#{@to_path}/images/#{file.gsub(/\.txt/,"").gsub(/WebHome/,"Home")}/#{image_url}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
should "not include any versioning file" do
|
63
|
+
Dir.open("#{@to_path}/images/").entries.each do |folder|
|
64
|
+
assert_equal true, (Dir.glob("#{@to_path}/images/#{folder}/*.*,v").size == 0)
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_equal true, (Dir.glob("#{@to_path}/*.*,v").size == 0)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "twiki2markdown"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Cristian Pereyra"]
|
12
|
+
s.date = "2012-01-05"
|
13
|
+
s.description = "This gem handles the migration and commit of a TWiki project to a github wiki, uses java in the backend to parse the files"
|
14
|
+
s.email = "cristianpereyra@zaubersoftware.com"
|
15
|
+
s.executables = ["twiki2markdown", "twiki2markdown.jar"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".project",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/twiki2markdown",
|
30
|
+
"bin/twiki2markdown.jar",
|
31
|
+
"lib/twiki2markdown.rb",
|
32
|
+
"pom.xml",
|
33
|
+
"src/main/java/com/zaubersoftware/labs/twiki2markdown/App.java",
|
34
|
+
"src/test/java/com/zaubersoftware/labs/twiki2markdown/test/TwikiToMarkdownTest.java",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_gollum/Home.md",
|
37
|
+
"test/test_gollum/images/Home/baboon.png",
|
38
|
+
"test/test_twiki/data/sample_wiki/WebHome.txt",
|
39
|
+
"test/test_twiki/data/sample_wiki/WebInfo.txt",
|
40
|
+
"test/test_twiki/pub/sample_wiki/WebHome/baboon.jpg,v",
|
41
|
+
"test/test_twiki/pub/sample_wiki/WebHome/baboon.png",
|
42
|
+
"test/test_twiki2markdown.rb",
|
43
|
+
"twiki2markdown.gemspec"
|
44
|
+
]
|
45
|
+
s.homepage = "http://github.com/kshmir/twiki2markdown"
|
46
|
+
s.licenses = ["MIT"]
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = "1.8.10"
|
49
|
+
s.summary = "Gem for migrating a TWiki-based wiki to a github wiki with markdown syntax"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<shoulda-context>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
62
|
+
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
63
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
64
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
69
|
+
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
70
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
71
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twiki2markdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cristian Pereyra
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: &24646340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *24646340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: shoulda-context
|
27
|
+
requirement: &24645740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *24645740
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &24645160 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *24645160
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &24644460 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *24644460
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rcov
|
60
|
+
requirement: &24643580 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *24643580
|
69
|
+
description: This gem handles the migration and commit of a TWiki project to a github
|
70
|
+
wiki, uses java in the backend to parse the files
|
71
|
+
email: cristianpereyra@zaubersoftware.com
|
72
|
+
executables:
|
73
|
+
- twiki2markdown
|
74
|
+
- twiki2markdown.jar
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.rdoc
|
79
|
+
files:
|
80
|
+
- .document
|
81
|
+
- .project
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- VERSION
|
88
|
+
- bin/twiki2markdown
|
89
|
+
- bin/twiki2markdown.jar
|
90
|
+
- lib/twiki2markdown.rb
|
91
|
+
- pom.xml
|
92
|
+
- src/main/java/com/zaubersoftware/labs/twiki2markdown/App.java
|
93
|
+
- src/test/java/com/zaubersoftware/labs/twiki2markdown/test/TwikiToMarkdownTest.java
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_gollum/Home.md
|
96
|
+
- test/test_gollum/images/Home/baboon.png
|
97
|
+
- test/test_twiki/data/sample_wiki/WebHome.txt
|
98
|
+
- test/test_twiki/data/sample_wiki/WebInfo.txt
|
99
|
+
- test/test_twiki/pub/sample_wiki/WebHome/baboon.jpg,v
|
100
|
+
- test/test_twiki/pub/sample_wiki/WebHome/baboon.png
|
101
|
+
- test/test_twiki2markdown.rb
|
102
|
+
- twiki2markdown.gemspec
|
103
|
+
homepage: http://github.com/kshmir/twiki2markdown
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -4111081070517834628
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.10
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Gem for migrating a TWiki-based wiki to a github wiki with markdown syntax
|
131
|
+
test_files: []
|