caramelize 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -53
  3. data/Gemfile +3 -3
  4. data/LICENSE.md +1 -1
  5. data/README.md +25 -25
  6. data/Rakefile +10 -1
  7. data/bin/caramelize +2 -9
  8. data/caramelize.gemspec +27 -23
  9. data/lib/caramelize/caramel.rb +22 -24
  10. data/lib/caramelize/cli.rb +33 -26
  11. data/lib/caramelize/cli/create_command.rb +4 -20
  12. data/lib/caramelize/content_transferer.rb +126 -68
  13. data/lib/caramelize/database_connector.rb +3 -6
  14. data/lib/caramelize/filters/remove_table_tab_line_endings.rb +11 -0
  15. data/lib/caramelize/filters/swap_wiki_links.rb +11 -9
  16. data/lib/caramelize/filters/wikka_to_markdown.rb +8 -8
  17. data/lib/caramelize/gollum_output.rb +50 -37
  18. data/lib/caramelize/page.rb +23 -10
  19. data/lib/caramelize/version.rb +1 -1
  20. data/lib/caramelize/wiki/redmine_wiki.rb +25 -32
  21. data/lib/caramelize/wiki/wiki.rb +28 -15
  22. data/lib/caramelize/wiki/wikkawiki.rb +16 -24
  23. data/spec/fixtures/markup/swap-links-input.textile +57 -0
  24. data/spec/fixtures/markup/swap-links-output.textile +57 -0
  25. data/spec/fixtures/markup/table-tab-line-endings-input.textile +145 -0
  26. data/spec/fixtures/markup/table-tab-line-endings-output.textile +145 -0
  27. data/spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb +35 -0
  28. data/spec/lib/caramelize/filters/swap_wiki_links_spec.rb +33 -0
  29. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +88 -0
  30. data/spec/lib/caramelize/gollum_output_spec.rb +64 -0
  31. data/spec/lib/caramelize/wiki/wiki_spec.rb +31 -0
  32. data/spec/spec_helper.rb +8 -0
  33. metadata +136 -33
  34. data/lib/caramelize/author.rb +0 -8
  35. data/test/helper.rb +0 -18
  36. data/test/test_caramelize.rb +0 -7
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 417340a62045209170bfee46606c4adfdde8789a
4
+ data.tar.gz: 0bc08549a912380588062337e63942a72b921bde
5
+ SHA512:
6
+ metadata.gz: 031c4e20ef8ed3bdb6f4c4afe7000e2eb7593b2e1558bb49e6c2a311b3d9f038900fe6fc4906b8e0358db530646b97d45a80797fd81727feabb16b44d925d6fe
7
+ data.tar.gz: 0dba2fc96623470e0823b5601a38f70701908a9b9fbd73514ec2579920456ae3af6e30d9307f3164037cdc1c4a5100ee3d3a924149b729ef81bd740998f2d7cd
data/.gitignore CHANGED
@@ -1,55 +1,23 @@
1
- wiki.git
2
-
3
- # rcov generated
4
- coverage
5
-
6
- # rdoc generated
7
- rdoc
8
-
9
- # yard generated
10
- doc
11
- .yardoc
12
-
13
- # bundler
1
+ *.gem
2
+ *.rbc
14
3
  .bundle
4
+ .config
5
+ .yardoc
15
6
  Gemfile.lock
16
- *.gem
17
-
18
- # jeweler generated
19
- pkg/*
20
-
21
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
22
- #
23
- # * Create a file at ~/.gitignore
24
- # * Include files you want ignored
25
- # * Run: git config --global core.excludesfile ~/.gitignore
26
- #
27
- # After doing this, these files will be ignored in all your git projects,
28
- # saving you from having to 'pollute' every project you touch with them
29
- #
30
- # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
31
- #
32
- # For MacOS:
33
- #
34
- .DS_Store
35
-
36
- # For TextMate
37
- #*.tmproj
38
- #tmtags
39
-
40
- # For Komodo Edit
41
- #*.komodoproject
42
-
43
- # For emacs:
44
- #*~
45
- #\#*
46
- #.\#*
47
-
48
- # For vim:
49
- #*.swp
50
-
51
- # For redcar:
52
- #.redcar
53
-
54
- # For rubinius:
55
- #*.rbc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ wiki.git
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in caramelize.gemspec
4
- gemspec
3
+ # Specify your gem's dependencies in testgem.gemspec
4
+ gemspec
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Daniel Senff
1
+ Copyright (c) 2015 Daniel Senff
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -9,25 +9,25 @@ In the future more target wikis may be added. For the moment migration is suppor
9
9
  ### Installation
10
10
 
11
11
  $ gem install caramelize
12
-
12
+
13
13
  Install the latest release of caramelize using RubyGems.
14
14
 
15
15
  ### Use
16
16
 
17
- $ caramelize create
17
+ $ caramelize create
18
18
 
19
19
  Creates a template configuration file "caramel.rb". This includes documentation on how to use the preset Wiki-connectors and how to write addition customized connectors. More about this below.
20
20
 
21
- $ caramelize run
22
-
21
+ $ caramelize run
22
+
23
23
  Will start the wiki migration based on the configuration file. These are either found in predefined paths (./caramel.rb, ./config.rb, …), or passed as argument, as below.
24
24
 
25
25
  $ caramelize help
26
-
26
+
27
27
  Returns help information.
28
28
 
29
29
  $ caramelize version
30
-
30
+
31
31
  Returns version and release information.
32
32
 
33
33
  ### Options
@@ -42,7 +42,7 @@ Executes the given configuration.
42
42
 
43
43
  $ caramelize --verbose [command]
44
44
  $ caramelize -v [command]
45
-
45
+
46
46
  Displays more verbose output to the command line.
47
47
 
48
48
  ## Content migration
@@ -50,14 +50,14 @@ Displays more verbose output to the command line.
50
50
  ### Wiki support
51
51
 
52
52
  Caramelize comes with direct support for [WikkaWiki](wikka) and [Redmine](redmine)-Wiki.
53
- More custom wikis can be supported by creating a suitable configuration file.
53
+ More custom wikis can be supported by creating a suitable configuration file.
54
54
 
55
55
  Any imported wiki exports into a [gollum](gollum) git-repository. This is a wiki based around a git-repository. This gives you the flexibility of having all wiki pages exported as physical files, while keeping the history and having an easy and wide-supported way of access by using the wiki server gollum features.
56
56
 
57
57
  Since wiki software may have special features, that are not common among other wikis, content migration may always have a loss of style or information. Caramelize tries to support the most common features.
58
58
 
59
59
  * Page meta data
60
- * title
60
+ * title
61
61
  * content body
62
62
  * author name
63
63
  * author email address
@@ -65,7 +65,7 @@ Since wiki software may have special features, that are not common among other w
65
65
  * revisions
66
66
  * Markup conversion to markdown
67
67
  * limited to "simple" formatting, excluding complex formats such as tables
68
- * conversion using regular expressions -> somewhat easy to learn and extend
68
+ * conversion using regular expressions -> somewhat easy to learn and extend
69
69
 
70
70
  ### Configuration recipes
71
71
 
@@ -76,24 +76,24 @@ Custom import allows you to import data from wikis that are not natively support
76
76
 
77
77
  For a custom wiki you need to create a `wiki` instance object, that receives the necessary database creditials.
78
78
 
79
- wiki = Caramelize::Wiki.new({:host => "localhost",
80
- :username => "user",
81
- :database => "database_name",
82
- :password => 'monkey',
79
+ wiki = Caramelize::Wiki.new({:host => "localhost",
80
+ :username => "user",
81
+ :database => "database_name",
82
+ :password => 'monkey',
83
83
  :markup => :wikka})
84
84
 
85
- This example ignores custom markup conversion and assumes WikkaWiki-markup.
85
+ This example ignores custom markup conversion and assumes WikkaWiki-markup.
86
86
 
87
87
  Once the object is established we need to hook in a method that defines how revisions are read from the database and how they are processed.
88
88
 
89
89
  wiki.instance_eval do
90
90
  def read_pages
91
91
  sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
92
- @revisions, @titles = [], []
92
+ revisions, titles = [], []
93
93
  results = database.query(sql)
94
94
  results.each do |row|
95
- @titles << row["tag"]
96
- author = @authors[row["user"]]
95
+ titles << row["tag"]
96
+ author = authors[row["user"]]
97
97
  page = Page.new({:id => row["id"],
98
98
  :title => row["tag"],
99
99
  :body => row["body"],
@@ -103,15 +103,15 @@ Once the object is established we need to hook in a method that defines how revi
103
103
  :message => row["note"],
104
104
  :author => author,
105
105
  :author_name => row["user"]})
106
- @revisions << page
106
+ revisions << page
107
107
  end
108
108
  # titles is the list of all unique page titles contained in the wiki
109
- @titles.uniq!
109
+ titles.uniq!
110
110
  # revisions is the list of all revisions ordered by date
111
- @revisions
111
+ revisions
112
112
  end
113
113
 
114
- In the end the `wiki` instance needs the `@titles` and `@revisions` filled.
114
+ In the end the `wiki` instance needs the `titles` and `revisions` filled.
115
115
 
116
116
  Some wikis don't have all necessary metadata saved in the revision. In this case additional database queries are necessary. **The configuration recipe is pure ruby code, that is included on execution. This gives you alot of freedom in writing your configuration, but also a lot of power to break things for yourself. Be advised.**
117
117
 
@@ -127,8 +127,8 @@ Clone or fork this repository and start building.
127
127
 
128
128
  $ git clone git@github.com:Dahie/caramelize.git
129
129
  $ gem build caramelize.gemspec
130
-
131
- Now to build and package the gem do
130
+
131
+ Now to build and package the gem do
132
132
 
133
133
  $ rake build
134
134
 
@@ -139,7 +139,7 @@ or
139
139
  to install the new gem right to your system.
140
140
 
141
141
  ## Contributing to caramelize
142
-
142
+
143
143
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
144
144
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
145
145
  * Fork the project
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task :default => :spec
@@ -1,12 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # If we are given filenames, convert each file
4
-
5
3
  require 'caramelize/cli'
6
- begin
7
- Caramelize::CLI::CommandParser.new.parse
8
- rescue
9
- puts "An error has occurred:\n " + $!.message
10
- puts $!.backtrace if $DEBUG
11
- exit(-1)
12
- end
4
+
5
+ Caramelize::CLI::CommandParser.new.parse
@@ -1,29 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "caramelize/version"
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "caramelize"
7
- s.version = Caramelize::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.license = "MIT"
10
- s.authors = ["Daniel Senff"]
11
- s.email = ["mail@danielsenff.de"]
12
- s.homepage = "http://github.com/Dahie/caramelize"
13
- s.summary = %q{Flexible and modular wiki conversion tool}
14
- s.description = %q{By defining the connectors from the input wiki you can migrate any wiki to git-based Gollum wiki repositories.}
15
-
16
- s.bindir = 'bin'
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "caramelize"
8
+ spec.version = Caramelize::VERSION
9
+ spec.license = "MIT"
10
+ spec.authors = ["Daniel Senff"]
11
+ spec.email = ["mail@danielsenff.de"]
12
+ spec.homepage = "http://github.com/Dahie/caramelize"
13
+ spec.summary = %q{Flexible and modular wiki conversion tool}
14
+ spec.description = %q{By defining the connectors from the input wiki you can migrate any wiki to git-based Gollum wiki repositories.}
17
15
 
18
- s.add_dependency('mysql2')
19
- s.add_dependency('cmdparse')
20
- s.add_dependency('ruby-progressbar')
21
- s.add_dependency('gollum-lib', '>= 1.0.0') # grit dependency implicit through gollum
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
22
20
 
23
- s.rubyforge_project = "caramelize"
21
+ spec.add_dependency('mysql2')
22
+ spec.add_dependency('cmdparse')
23
+ spec.add_dependency('docile')
24
+ spec.add_dependency('ruby-progressbar')
25
+ spec.add_dependency('gollum-lib', '>= 1.0.0') # grit dependency implicit through gollum
24
26
 
25
- s.files = `git ls-files`.split("\n")
26
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
- s.require_paths = ["lib"]
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "byebug"
31
+ spec.add_development_dependency "guard"
32
+ spec.add_development_dependency "guard-rspec"
29
33
  end
@@ -1,4 +1,3 @@
1
- #Encoding: UTF-8
2
1
  require 'caramelize/wiki/wiki'
3
2
  require 'caramelize/wiki/wikkawiki'
4
3
  require 'caramelize/wiki/redmine_wiki'
@@ -9,21 +8,20 @@ require 'caramelize/wiki/redmine_wiki'
9
8
 
10
9
  # Note, if you want to activate this, you need to uncomment the line below.
11
10
  def customized_wiki
12
-
13
- # This example is a reimplementation of the WikkaWiki-Connector.
11
+
12
+ # This example is a reimplementation of the WikkaWiki-Connector.
14
13
  # To connect to WikkaWiki, I suggest to use the predefined Connector below.
15
- wiki = Caramelize::Wiki.new({:host => "localhost",
16
- :username => "user",
17
- :database => "database_name",
18
- :password => 'admin_gnihihihi',
14
+ wiki = Caramelize::Wiki.new({:host => "localhost",
15
+ :username => "user",
16
+ :database => "database_name",
17
+ :password => 'admin_gnihihihi',
19
18
  :markup => :wikka})
20
19
  wiki.instance_eval do
21
20
  def read_pages
22
21
  sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
23
- @revisions, @titles = [], []
24
22
  results = database.query(sql)
25
23
  results.each do |row|
26
- @titles << row["tag"]
24
+ titles << row["tag"]
27
25
  author = @authors[row["user"]]
28
26
  page = Page.new({:id => row["id"],
29
27
  :title => row["tag"],
@@ -34,43 +32,43 @@ def customized_wiki
34
32
  :message => row["note"],
35
33
  :author => author,
36
34
  :author_name => row["user"]})
37
- @revisions << page
35
+ revisions << page
38
36
  end
39
- @titles.uniq!
40
- @revisions
37
+ titles.uniq!
38
+ revisions
41
39
  end
42
40
  end
43
-
41
+
44
42
  wiki
45
43
  end
46
44
 
47
45
 
48
- # if you want to use one of the preset Wiki-Connectors uncomment the connector
46
+ # if you want to use one of the preset Wiki-Connectors uncomment the connector
49
47
  # and edit the database logins accordingly.
50
48
  def predefined_wiki
51
-
49
+
52
50
  # For connection to a WikkaWiki-Database use this Connector
53
- #return Caramelize::WikkaWiki.new(:host => "localhost",
51
+ #return Caramelize::WikkaWiki.new(:host => "localhost",
54
52
  # :username => "root",
55
- # :password => "root",
53
+ # :password => "root",
56
54
  # :database => "wikka")
57
-
58
-
55
+
56
+
59
57
  # For connection to a Redmine-Database use this Connector
60
58
  # Additional options:
61
- # :create_namespace_home => true/false (Default: true) - Creates a new wikipage at /home as root page for Gollum wiki
62
- return Caramelize::RedmineWiki.new(:host => "localhost",
63
- :username => "root",
59
+ # :create_namespace_overview => true/false (Default: true) - Creates a new wikipage at /home as root page for Gollum wiki
60
+ return Caramelize::RedmineWiki.new(:host => "localhost",
61
+ :username => "root",
64
62
  :password => "root",
65
63
  :database => "redmine_development")
66
64
  end
67
65
 
68
66
 
69
67
  def input_wiki
70
-
68
+
71
69
  # comment and uncomment to easily switch between predefined and costumized Wiki-connectors.
72
70
  #return customized_wiki
73
-
71
+
74
72
  return predefined_wiki
75
73
 
76
74
  end
@@ -1,16 +1,12 @@
1
- #Encoding: UTF-8
2
1
  require 'cmdparse'
3
2
  require 'caramelize/version'
4
3
 
5
4
  module Caramelize
6
- autoload :ContentTransferer, 'caramelize/content_transferer'
5
+ require 'caramelize/content_transferer'
7
6
  module CLI
8
-
9
- # Namespace for all classes that act as CLI commands.
10
- autoload :RunCommand, 'caramelize/cli/run_command'
11
- autoload :CreateCommand, 'caramelize/cli/create_command'
12
-
13
-
7
+ require 'caramelize/cli/run_command'
8
+ require 'caramelize/cli/create_command'
9
+
14
10
  # This is the command parser class used for handling the webgen command line interface. After
15
11
  # creating an instance, the inherited #parse method can be used for parsing the command line
16
12
  # arguments and executing the requested command.
@@ -20,7 +16,7 @@ module Caramelize
20
16
  attr_reader :verbosity
21
17
 
22
18
  # Create a new CommandParser class. T
23
- def initialize
19
+ def initialize
24
20
  super(true)
25
21
  @verbosity = :normal
26
22
 
@@ -44,33 +40,44 @@ module Caramelize
44
40
  possible_files |= KNOWN_CONFIG_LOCATIONS
45
41
  possible_files.detect{|f| File.exists?(f)}
46
42
  end
47
-
43
+
48
44
  # Utility method for sub-commands to transfer wiki contents
49
- def transfer_content config_file = ""
45
+ def transfer_content(config_file = "")
50
46
  time_start = Time.now
51
-
47
+
52
48
  file = detect_configuration_file config_file
53
- puts "Read config file: #{file}" if @verbosity == :verbose
54
- if file && File.exists?(file)
55
- instance_eval(File.read(file))
56
- original_wiki = input_wiki
57
-
58
- options = original_wiki.options
59
- options[:verbosity] = @verbosity
60
- ContentTransferer.execute(original_wiki, options)
61
-
62
- time_end = Time.now
63
- puts "Time required: #{time_end - time_start} s" if @verbosity == :verbose
64
- else
49
+ puts "Read config file: #{file}" if verbose?
50
+
51
+ unless file && File.exists?(file)
65
52
  puts "No config file found."
53
+ return false
66
54
  end
67
-
55
+
56
+ commence_transfer file
57
+
58
+ puts "Time required: #{Time.now - time_start} s" if verbose?
59
+ end
60
+
61
+ def commence_transfer(file)
62
+ #load file
63
+ #original_wiki = Configuration.instance.input_wiki
64
+ instance_eval(File.read(file))
65
+ original_wiki = input_wiki
66
+
67
+ options = original_wiki.options
68
+ options[:verbosity] = @verbosity
69
+ ContentTransferer.execute(original_wiki, options)
70
+ end
71
+
72
+ def verbose?
73
+ @verbosity == :verbose
68
74
  end
69
75
 
70
76
  # :nodoc:
71
77
  def parse(argv = ARGV)
72
78
  Caramelize::CLI.constants.select {|c| c =~ /.+Command$/ }.each do |c|
73
- self.add_command(Caramelize::CLI.const_get(c).new, (c.to_s == 'RunCommand' ? false : false)) # set runcommand as default
79
+ # set runcommand as default
80
+ self.add_command(Caramelize::CLI.const_get(c).new, (c.to_s == 'RunCommand' ? false : false))
74
81
  end
75
82
  super
76
83
  end