caramelize 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +19 -24
  3. data/bin/caramelize +48 -2
  4. data/caramelize.gemspec +2 -1
  5. data/lib/caramelize.rb +12 -0
  6. data/lib/caramelize/caramel.rb +33 -29
  7. data/lib/caramelize/content_transferer.rb +78 -111
  8. data/lib/caramelize/filter_processor.rb +31 -0
  9. data/lib/caramelize/input_wiki/redmine_wiki.rb +97 -0
  10. data/lib/caramelize/{wiki → input_wiki}/trac_converter.rb +0 -0
  11. data/lib/caramelize/input_wiki/wiki.rb +61 -0
  12. data/lib/caramelize/input_wiki/wikkawiki.rb +57 -0
  13. data/lib/caramelize/output_wiki/gollum.rb +73 -0
  14. data/lib/caramelize/page.rb +10 -4
  15. data/lib/caramelize/services/page_builder.rb +20 -0
  16. data/lib/caramelize/version.rb +1 -1
  17. data/spec/lib/caramelize/content_transferer_spec.rb +9 -0
  18. data/spec/lib/caramelize/filter_processor_spec.rb +32 -0
  19. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +25 -13
  20. data/spec/lib/caramelize/{wiki → input_wiki}/wiki_spec.rb +30 -4
  21. data/spec/lib/caramelize/output_wiki/gollum_spec.rb +113 -0
  22. data/spec/lib/caramelize/page_spec.rb +49 -0
  23. data/spec/lib/caramelize/services/page_builder.rb +29 -0
  24. data/spec/spec_helper.rb +1 -1
  25. metadata +38 -17
  26. data/lib/caramelize/cli.rb +0 -89
  27. data/lib/caramelize/cli/create_command.rb +0 -36
  28. data/lib/caramelize/cli/run_command.rb +0 -33
  29. data/lib/caramelize/gollum_output.rb +0 -79
  30. data/lib/caramelize/wiki/redmine_wiki.rb +0 -88
  31. data/lib/caramelize/wiki/wiki.rb +0 -63
  32. data/lib/caramelize/wiki/wikkawiki.rb +0 -48
  33. data/spec/lib/caramelize/gollum_output_spec.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 417340a62045209170bfee46606c4adfdde8789a
4
- data.tar.gz: 0bc08549a912380588062337e63942a72b921bde
2
+ SHA256:
3
+ metadata.gz: f7fe435304327d466829f0dcbe0ab9ed23978da90c0c992f1464d123cffa3965
4
+ data.tar.gz: f89cdef42b840eff1869081e813cb37f93172fea6a5c7446ffba2685b34aae88
5
5
  SHA512:
6
- metadata.gz: 031c4e20ef8ed3bdb6f4c4afe7000e2eb7593b2e1558bb49e6c2a311b3d9f038900fe6fc4906b8e0358db530646b97d45a80797fd81727feabb16b44d925d6fe
7
- data.tar.gz: 0dba2fc96623470e0823b5601a38f70701908a9b9fbd73514ec2579920456ae3af6e30d9307f3164037cdc1c4a5100ee3d3a924149b729ef81bd740998f2d7cd
6
+ metadata.gz: 2b1c74be41c73bd7e0f35e4f9441f9bc96a5a6f04e994502b70fec73fda7444e8d7e8e4fb8868d5822d4333e4f3a37b2348f954d8d37064674ee68046e8d6c58
7
+ data.tar.gz: 3b7a59b339ef5779ab86be0ee4a054f0772f58483db5edee3479d736f355ad4f04bfac06e46fda39319fc431c2003885687666abc0da854b080631484f3bcd10
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # caramelize
2
2
 
3
- Caramelize is a compact and flexible wiki content migration tool. It is intended for easily transfering content from otherwise rare supported legacy wikis. With caramelize you can create your own export configurations and migrate your data into a git-based [gollum](gollum)-wiki retaining all your history and gaining the most flexible access to your wiki content.
3
+ Caramelize is a compact and flexible wiki content migration tool. It is intended for easily transfering content from otherwise rare supported legacy wikis. With caramelize you can create your own export configurations and migrate your data into a git-based [gollum](https://github.com/github/gollum)-wiki retaining all your history and gaining the most flexible access to your wiki content.
4
4
 
5
- In the future more target wikis may be added. For the moment migration is supported for [WikkaWiki](wikka) and [Redmine](redmine)-Wiki.
5
+ In the future more target wikis may be added. For the moment migration is supported for [WikkaWiki](http://wikkawiki.org/) and [Redmine](http://www.redmine.org/)-Wiki.
6
6
 
7
7
  ## Usage
8
8
 
@@ -41,7 +41,6 @@ Creates an example configuration by the given name.
41
41
  Executes the given configuration.
42
42
 
43
43
  $ caramelize --verbose [command]
44
- $ caramelize -v [command]
45
44
 
46
45
  Displays more verbose output to the command line.
47
46
 
@@ -49,10 +48,10 @@ Displays more verbose output to the command line.
49
48
 
50
49
  ### Wiki support
51
50
 
52
- Caramelize comes with direct support for [WikkaWiki](wikka) and [Redmine](redmine)-Wiki.
51
+ Caramelize comes with direct support for [WikkaWiki](http://wikkawiki.org/) and [Redmine](http://www.redmine.org/)-Wiki.
53
52
  More custom wikis can be supported by creating a suitable configuration file.
54
53
 
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.
54
+ Any imported wiki exports into a [gollum](https://github.com/github/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
55
 
57
56
  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
57
 
@@ -76,11 +75,11 @@ Custom import allows you to import data from wikis that are not natively support
76
75
 
77
76
  For a custom wiki you need to create a `wiki` instance object, that receives the necessary database creditials.
78
77
 
79
- wiki = Caramelize::Wiki.new({:host => "localhost",
80
- :username => "user",
81
- :database => "database_name",
82
- :password => 'monkey',
83
- :markup => :wikka})
78
+ wiki = Caramelize::InputWiki::Wiki.new(host: "localhost",
79
+ username: "user",
80
+ database: "database_name",
81
+ password: 'monkey',
82
+ markup: :wikka})
84
83
 
85
84
  This example ignores custom markup conversion and assumes WikkaWiki-markup.
86
85
 
@@ -94,15 +93,15 @@ Once the object is established we need to hook in a method that defines how revi
94
93
  results.each do |row|
95
94
  titles << row["tag"]
96
95
  author = authors[row["user"]]
97
- page = Page.new({:id => row["id"],
98
- :title => row["tag"],
99
- :body => row["body"],
100
- :markup => 'wikka',
101
- :latest => row["latest"] == "Y",
102
- :time => row["time"],
103
- :message => row["note"],
104
- :author => author,
105
- :author_name => row["user"]})
96
+ page = Page.new({id: row["id"],
97
+ title: row["tag"],
98
+ body: row["body"],
99
+ markup: 'wikka',
100
+ latest: row["latest"] == "Y",
101
+ time: row["time"],
102
+ message: row["note"],
103
+ author: author,
104
+ author_name: row["user"]})
106
105
  revisions << page
107
106
  end
108
107
  # titles is the list of all unique page titles contained in the wiki
@@ -150,8 +149,4 @@ to install the new gem right to your system.
150
149
 
151
150
  ## Copyright
152
151
 
153
- Copyright (c) 2011-2013 Daniel Senff. See LICENSE.md for further details.
154
-
155
- [wikka]: http://wikkawiki.org/
156
- [gollum]: https://github.com/github/gollum
157
- [redmine]: http://www.redmine.org/
152
+ Copyright (c) 2011-2015 Daniel Senff. See LICENSE.md for further details.
@@ -1,5 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'caramelize/cli'
3
+ require 'caramelize'
4
+ require 'commander/import'
4
5
 
5
- Caramelize::CLI::CommandParser.new.parse
6
+ # :name is optional, otherwise uses the basename of this executable
7
+ program :name, 'caramelize'
8
+ program :version, Caramelize::VERSION
9
+ program :description, 'TODO'
10
+ program :help, 'Author', 'Daniel Senff <public@danielsenff.de>'
11
+
12
+ default_command :run
13
+
14
+ global_option '--verbose'
15
+
16
+ command :new do |c|
17
+ c.syntax = 'caramelize create [options]'
18
+ c.summary = 'Create new configuration'
19
+ c.description = 'Create a fresh configuration file for caramelize'
20
+ c.option '--config STRING', String, 'The config file (default: caramel.rb)'
21
+ c.example 'Create a fresh config file as "caramel.rb"', 'caramelize create'
22
+ c.example 'Create a fresh config file as "config.rb"', 'caramelize create --config config.rb'
23
+ c.action do |args, options|
24
+ target_file ||= (options.config || 'caramel.rb')
25
+ options.default({ config: 'caramel.rb' })
26
+ FileUtils.cp(File.dirname(__FILE__) + '/../lib/caramelize/caramel.rb',
27
+ options.config)
28
+ say "Created new configuration file: #{optinos.config}"
29
+ end
30
+ end
31
+ alias_command :create, :new
32
+
33
+ command :run do |c|
34
+ c.syntax = 'caramelize run [options]'
35
+ c.summary = 'Run wiki transfer'
36
+ c.description = 'Run the wiki content transfer based on the given configuration file'
37
+ c.option '--config STRING', String, 'The config file (default: caramel.rb)'
38
+ c.example 'Run transfer for "caramel.rb"', 'caramelize run'
39
+ c.example 'Run transfer for "config.rb"', 'caramelize run --config config.rb'
40
+ c.action do |args, options|
41
+ time_start = Time.now
42
+ options.default({ config: 'caramel.rb' })
43
+ puts options.inspect
44
+
45
+ instance_eval(File.read(options.config))
46
+
47
+ wiki_options = input_wiki.options.merge(verbose: options.verbose)
48
+ Caramelize::ContentTransferer.new(input_wiki, wiki_options).execute
49
+ say "Time required: #{Time.now - time_start} s"
50
+ end
51
+ end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency('mysql2')
22
- spec.add_dependency('cmdparse')
22
+ spec.add_dependency('commander')
23
23
  spec.add_dependency('docile')
24
24
  spec.add_dependency('ruby-progressbar')
25
25
  spec.add_dependency('gollum-lib', '>= 1.0.0') # grit dependency implicit through gollum
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec"
30
30
  spec.add_development_dependency "byebug"
31
+ spec.add_development_dependency "rubocop"
31
32
  spec.add_development_dependency "guard"
32
33
  spec.add_development_dependency "guard-rspec"
33
34
  end
@@ -0,0 +1,12 @@
1
+ require 'caramelize/version'
2
+ require 'caramelize/page'
3
+ require 'caramelize/ext'
4
+ require 'caramelize/content_transferer'
5
+ require 'caramelize/filter_processor'
6
+ require 'caramelize/database_connector'
7
+ require 'caramelize/output_wiki/gollum'
8
+ require 'caramelize/services/page_builder'
9
+ require 'caramelize/input_wiki/wiki'
10
+ require 'caramelize/input_wiki/redmine_wiki'
11
+ require 'caramelize/input_wiki/wikkawiki'
12
+
@@ -1,21 +1,22 @@
1
- require 'caramelize/wiki/wiki'
2
- require 'caramelize/wiki/wikkawiki'
3
- require 'caramelize/wiki/redmine_wiki'
1
+ require 'caramelize/input_wiki/wikkawiki'
2
+ require 'caramelize/input_wiki/redmine_wiki'
4
3
 
5
4
  ## Example caramelize configuration file
6
5
 
7
- # Within this method you can define your own Wiki-Connectors to Wikis not supported by default in this software
6
+ # Within this method you can define your own Wiki-Connectors to Wikis
7
+ # not supported by default in this software
8
8
 
9
9
  # Note, if you want to activate this, you need to uncomment the line below.
10
10
  def customized_wiki
11
11
 
12
12
  # This example is a reimplementation of the WikkaWiki-Connector.
13
13
  # To connect to WikkaWiki, I suggest to use the predefined Connector below.
14
- wiki = Caramelize::Wiki.new({:host => "localhost",
15
- :username => "user",
16
- :database => "database_name",
17
- :password => 'admin_gnihihihi',
18
- :markup => :wikka})
14
+ options = { host: "localhost",
15
+ username: "user",
16
+ database: "database_name",
17
+ password: 'Picard-Delta-5',
18
+ markup: :wikka}
19
+ wiki = Caramelize::InputWiki::Wiki.new(options)
19
20
  wiki.instance_eval do
20
21
  def read_pages
21
22
  sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
@@ -23,15 +24,16 @@ def customized_wiki
23
24
  results.each do |row|
24
25
  titles << row["tag"]
25
26
  author = @authors[row["user"]]
26
- page = Page.new({:id => row["id"],
27
- :title => row["tag"],
28
- :body => row["body"],
29
- :markup => 'wikka',
30
- :latest => row["latest"] == "Y",
31
- :time => row["time"],
32
- :message => row["note"],
33
- :author => author,
34
- :author_name => row["user"]})
27
+ properties = { id: row["id"],
28
+ title: row["tag"],
29
+ body: row["body"],
30
+ markup: 'wikka',
31
+ latest: row["latest"] == "Y",
32
+ time: row["time"],
33
+ message: row["note"],
34
+ author: author,
35
+ author_name: row["user"]}
36
+ page = Page.new(properties)
35
37
  revisions << page
36
38
  end
37
39
  titles.uniq!
@@ -48,27 +50,29 @@ end
48
50
  def predefined_wiki
49
51
 
50
52
  # For connection to a WikkaWiki-Database use this Connector
51
- #return Caramelize::WikkaWiki.new(:host => "localhost",
52
- # :username => "root",
53
- # :password => "root",
54
- # :database => "wikka")
53
+ #options = { host: "localhost",
54
+ # username: "root",
55
+ # password: "root",
56
+ # database: "wikka" }
57
+ #return Caramelize::InputWiki::WikkaWiki.new(options)
55
58
 
56
59
 
57
60
  # For connection to a Redmine-Database use this Connector
58
61
  # Additional options:
59
62
  # :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",
62
- :password => "root",
63
- :database => "redmine_development")
63
+ options = { host: "localhost",
64
+ username: "root",
65
+ password: "root",
66
+ database: "redmine_development" }
67
+ return Caramelize::InputWiki::RedmineWiki.new(options)
64
68
  end
65
69
 
66
70
 
67
71
  def input_wiki
72
+ # comment and uncomment to easily switch between predefined and
73
+ # costumized Wiki-connectors.
68
74
 
69
- # comment and uncomment to easily switch between predefined and costumized Wiki-connectors.
70
75
  #return customized_wiki
71
76
 
72
77
  return predefined_wiki
73
-
74
- end
78
+ end
@@ -8,148 +8,115 @@ module Caramelize
8
8
  require 'caramelize/ext'
9
9
  require 'caramelize/content_transferer'
10
10
  require 'caramelize/database_connector'
11
- require 'caramelize/gollum_output'
12
- require 'caramelize/wiki/redmine_wiki'
13
- require 'caramelize/wiki/wikkawiki'
14
- require 'caramelize/wiki/wiki'
11
+ require 'caramelize/output_wiki/gollum'
12
+ require 'caramelize/input_wiki/redmine_wiki'
13
+ require 'caramelize/input_wiki/wikkawiki'
15
14
 
16
- # Controller for the content migration
17
15
  class ContentTransferer
16
+ attr_reader :input_wiki, :options, :filter_processor
18
17
 
19
- class << self
18
+ def initialize(input_wiki, options)
19
+ @input_wiki = input_wiki
20
+ @options = options
20
21
 
21
- # Execute the content migration
22
- def execute(original_wiki, options={})
23
- @options = options
24
- @original_wiki = original_wiki
25
-
26
- options[:default_author] = "Caramelize" unless options[:default_author]
27
- # see if original wiki markup is among any gollum supported markups
28
- options[:markup] = target_markup
29
-
30
- original_wiki.read_authors
31
- initialize_page_filters
32
- commit_history
33
-
34
- # if wiki needs to convert syntax, do so
35
- if verbose?
36
- puts "From markup: #{original_wiki.markup.to_s}"
37
- puts "To markup: #{markup.to_s}"
38
- end
39
-
40
- puts "Latest revisions:" if verbose?
22
+ options[:default_author] = options.fetch(:default_author, "Caramelize")
23
+ options[:target_directory] = './wiki-export'
24
+ options[:markup] = target_markup
25
+ end
41
26
 
42
- migrate_markup_on_last_revision
43
- create_overview_page_of_namespaces if options[:create_namespace_overview]
44
- end
27
+ def execute
28
+ input_wiki.read_authors
45
29
 
46
- private
30
+ commit_history
47
31
 
48
- def target_markup
49
- output_wiki.supported_markup.index(original_wiki.markup) ? original_wiki.markup : :markdown
32
+ if verbose?
33
+ puts "From markup: #{input_wiki.markup.to_s}"
34
+ puts "To markup: #{target_markup.to_s}"
35
+ puts "Convert latest revisions:"
50
36
  end
51
37
 
52
- def revisions
53
- @revisions ||= original_wiki.read_pages
54
- end
55
-
56
- def filters
57
- @filters ||= []
58
- end
38
+ migrate_markup_of_latest_revisions
59
39
 
60
- def initialize_page_filters
61
- filters << original_wiki.filters
62
- filters.flatten!
63
- end
40
+ puts 'Create Namespace Overview' if verbose?
41
+ create_overview_page_of_namespaces if options[:create_namespace_overview]
42
+ end
64
43
 
65
- def create_overview_page_of_namespaces
66
- puts 'Create Namespace Overview' if verbose?
67
- output_wiki.create_namespace_overview(original_wiki.namespaces)
68
- end
44
+ private
69
45
 
70
- def migrate_markup_on_last_revision
71
- if original_wiki.convert_markup? markup # is wiki in target markup
46
+ def target_markup
47
+ @target_markup ||=
48
+ needs_conversion_to_target_markup? ? input_wiki.markup : :markdown
49
+ end
72
50
 
51
+ def needs_conversion_to_target_markup?
52
+ output_wiki.supported_markup.index(input_wiki.markup)
53
+ end
73
54
 
74
- end # end convert_markup?
55
+ def revisions
56
+ @revisions ||= input_wiki.read_pages
57
+ end
75
58
 
76
- create_progress_bar("Markup filters", original_wiki.latest_revisions.count) unless verbose?
77
- original_wiki.latest_revisions.each do |revision|
78
- migrate_markup_per_revision(revision)
79
- end
80
- end
59
+ def output_wiki
60
+ @output_wiki ||= OutputWiki::Gollum.new(options[:target_directory])
61
+ end
81
62
 
82
- def commit_history
83
- # setup progressbar
84
- create_progress_bar("Revisions", revisions.count) unless verbose?
85
- output_wiki.commit_history(revisions, options) do |page, index|
86
- if verbose?
87
- puts "(#{index+1}/#{revisions.count}) #{page.time} #{page.title}"
88
- else
89
- @progress_bar.increment
90
- end
91
- end
63
+ def filter_processor
64
+ @filter_processor ||= FilterProcessor.new(input_wiki)
65
+ end
92
66
 
93
- end
67
+ def verbose?
68
+ options[:verbose]
69
+ end
94
70
 
95
- def original_wiki
96
- @original_wiki
97
- end
71
+ def revisions_count
72
+ revisions.count
73
+ end
98
74
 
99
- def verbose?
100
- options[:verbosity] == :verbose
101
- end
75
+ def create_overview_page_of_namespaces
76
+ output_wiki.commit_namespace_overview(input_wiki.namespaces)
77
+ end
102
78
 
103
- def markup
104
- unless @markup
105
- # see if original wiki markup is among any gollum supported markups
106
- @markup = output_wiki.supported_markup.index(original_wiki.markup) ? original_wiki.markup : :markdown
107
- end
108
- @markup
109
- end
79
+ def migrate_markup_of_latest_revisions
80
+ progress_bar = ProgressBar.create(title: "Markup filters",
81
+ total: revisions_count)
110
82
 
111
- def options
112
- @options
83
+ input_wiki.latest_revisions.each do |revision|
84
+ migrate_markup_of_revision(revision, progress_bar)
113
85
  end
86
+ end
114
87
 
115
- def output_wiki
116
- @output_wiki ||= GollumOutput.new('./wiki-export') # TODO make wiki_path an option
117
- end
88
+ def commit_history
89
+ puts revisions_count
90
+ progress_bar = ProgressBar.create(title: "Revisions",
91
+ total: revisions_count)
118
92
 
119
- def migrate_markup_per_revision(revision)
93
+ output_wiki.commit_history(revisions, options) do |page, index|
120
94
  if verbose?
121
- puts "Filter source: #{revision.title} #{revision.time}"
95
+ puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
122
96
  else
123
- @progress_bar.increment
97
+ progress_bar.increment
124
98
  end
125
-
126
- # run filters
127
- body_new = run_filters(revision.body)
128
-
129
- unless body_new == revision.body
130
- revision.body = body_new
131
- revision.author_name = markup
132
- revision.time = Time.now
133
- revision.author = nil
134
-
135
- # commit as latest page revision
136
- output_wiki.commit_revision revision, options[:markup]
137
- end
138
-
139
99
  end
100
+ end
140
101
 
141
- def run_filters(body)
142
- body_new = body
143
- filters.each do |filter|
144
- body_new = filter.run body_new
145
- end
146
- body_new
102
+ def migrate_markup_of_revision(revision, progress_bar)
103
+ if verbose?
104
+ puts "Filter source: #{revision.title} #{revision.time}"
105
+ else
106
+ progress_bar.increment
147
107
  end
148
108
 
149
- def create_progress_bar(title, total)
150
- @progress_bar = ProgressBar.create(title: title, total: total, format: '%a %B %p%% %t')
109
+ body_new = filter_processor.run(revision.body)
110
+
111
+ unless body_new == revision.body
112
+ revision.body = body_new
113
+ revision.author_name = target_markup
114
+ revision.time = Time.now
115
+ revision.author = nil
116
+
117
+ # commit as latest page revision
118
+ output_wiki.commit_revision(revision, options[:markup])
151
119
  end
152
120
  end
153
-
154
121
  end
155
- end
122
+ end