caramelize 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +25 -13
  5. data/README.md +2 -3
  6. data/Rakefile +3 -1
  7. data/bin/caramelize +6 -5
  8. data/caramelize.gemspec +23 -19
  9. data/lib/caramelize/caramel.rb +26 -30
  10. data/lib/caramelize/content_transferer.rb +48 -29
  11. data/lib/caramelize/database_connector.rb +8 -8
  12. data/lib/caramelize/filter_processor.rb +2 -0
  13. data/lib/caramelize/filters/camel_case_to_wiki_links.rb +26 -0
  14. data/lib/caramelize/filters/remove_table_tab_line_endings.rb +3 -2
  15. data/lib/caramelize/filters/swap_wiki_links.rb +5 -3
  16. data/lib/caramelize/filters/wikka_to_markdown.rb +26 -20
  17. data/lib/caramelize/health_check.rb +6 -68
  18. data/lib/caramelize/health_checks/home_page_check.rb +23 -0
  19. data/lib/caramelize/health_checks/orphaned_pages_check.rb +56 -0
  20. data/lib/caramelize/health_checks/page.rb +28 -0
  21. data/lib/caramelize/input_wiki/redmine_wiki.rb +14 -13
  22. data/lib/caramelize/input_wiki/wiki.rb +8 -2
  23. data/lib/caramelize/input_wiki/wikkawiki.rb +22 -13
  24. data/lib/caramelize/output_wiki/gollum.rb +10 -10
  25. data/lib/caramelize/page.rb +13 -9
  26. data/lib/caramelize/services/page_builder.rb +11 -8
  27. data/lib/caramelize/version.rb +3 -1
  28. data/lib/caramelize.rb +5 -0
  29. data/spec/lib/caramelize/content_transferer_spec.rb +3 -1
  30. data/spec/lib/caramelize/filter_processor_spec.rb +5 -2
  31. data/spec/lib/caramelize/filters/add_newline_on_page_end_spec.rb +27 -0
  32. data/spec/lib/caramelize/filters/camel_case_to_wiki_links_spec.rb +44 -0
  33. data/spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb +14 -9
  34. data/spec/lib/caramelize/filters/swap_wiki_links_spec.rb +16 -13
  35. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +123 -58
  36. data/spec/lib/caramelize/input_wiki/wiki_spec.rb +15 -14
  37. data/spec/lib/caramelize/output_wiki/gollum_spec.rb +31 -31
  38. data/spec/lib/caramelize/page_spec.rb +34 -26
  39. data/spec/lib/caramelize/services/page_builder_spec.rb +41 -0
  40. data/spec/spec_helper.rb +4 -2
  41. metadata +48 -27
  42. data/.travis.yml +0 -5
  43. data/spec/lib/caramelize/services/page_builder.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d6068cd942a85fdcb01d1ebbeb4ce0099ed42d39fd1bd6945979d25766aeecc
4
- data.tar.gz: dfedd3d78aaa4dde06807bdd8df064f044830b5caa0e2579ada4c7e6a170ddaf
3
+ metadata.gz: cb93f32560a4999584cc9e883655f867ed7f02bdffc4ef9a7088a5c44e68b29b
4
+ data.tar.gz: a3ae3187dc3a45c831daa833e991692f7c7108c8967da53efcafb2a4330dbadc
5
5
  SHA512:
6
- metadata.gz: f2c84686c76e783a8c782e5cf4fbfd27cb0e971a17dc306c04b5d35990418d8a97d1e24a20a51e83949d315b2e1915c38d21940bae9605823ed0eb9716300926
7
- data.tar.gz: efc71348b1350752111fb4770997589489ced69d84e4b8714e38d31e0bd668df9ae3d917ff8c73abbaa0842b297acf09485ec1bbe30b02096c65baaa239826cc
6
+ metadata.gz: 0da855d0680a06673e8ad2b98734ee8fe4d04063ebd40e5b5a3b37cd1f7446fd4ea10502e349dfc1e27787b8f395b976f870595e7622e1524a2504f9676000a4
7
+ data.tar.gz: 886e63abc962ee8e830d12efc632bd832000ca70951081e9cfb185fabba1f40711db6574ef2df40b2c8c946f5ae61ef06f51877a66288eef9f9ef431c4237937
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ Exclude:
8
+ - 'vendor/**/*'
9
+ - 'spec/fixtures/**/*'
10
+ - 'tmp/**/*'
11
+ - '.git/**/*'
12
+ - 'bin/*'
13
+ - '*.cmlz'
14
+ TargetRubyVersion: 3.1
15
+ SuggestExtensions: false
16
+
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
21
+
22
+ Metrics/BlockLength:
23
+ Enabled: false
24
+
25
+ Layout/LineLength:
26
+ Enabled: false
27
+
28
+ RSpec/NestedGroups:
29
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in testgem.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- caramelize (1.1.1)
4
+ caramelize (1.2.0)
5
5
  commander
6
6
  gollum-lib
7
7
  mysql2
@@ -13,10 +13,10 @@ GEM
13
13
  ast (2.4.2)
14
14
  byebug (11.1.3)
15
15
  coderay (1.1.3)
16
- commander (4.6.0)
17
- highline (~> 2.0.0)
16
+ commander (5.0.0)
17
+ highline (~> 3.0.0)
18
18
  crass (1.0.6)
19
- diff-lcs (1.5.0)
19
+ diff-lcs (1.5.1)
20
20
  ffi (1.16.3)
21
21
  formatador (1.1.0)
22
22
  gemojione (4.3.3)
@@ -47,7 +47,7 @@ GEM
47
47
  guard (~> 2.1)
48
48
  guard-compat (~> 1.1)
49
49
  rspec (>= 2.99.0, < 4.0)
50
- highline (2.0.3)
50
+ highline (3.0.1)
51
51
  json (2.7.1)
52
52
  language_server-protocol (3.17.0.3)
53
53
  listen (3.8.0)
@@ -58,20 +58,20 @@ GEM
58
58
  nokogiri (>= 1.12.0)
59
59
  lumberjack (1.2.10)
60
60
  method_source (1.0.0)
61
- mime-types (3.5.1)
61
+ mime-types (3.5.2)
62
62
  mime-types-data (~> 3.2015)
63
63
  mime-types-data (3.2023.1205)
64
64
  mini_portile2 (2.8.5)
65
65
  mysql2 (0.5.5)
66
66
  nenv (0.3.0)
67
- nokogiri (1.15.5)
67
+ nokogiri (1.16.0)
68
68
  mini_portile2 (~> 2.8.2)
69
69
  racc (~> 1.4)
70
70
  notiffany (0.1.3)
71
71
  nenv (~> 0.1)
72
72
  shellany (~> 0.0)
73
- parallel (1.23.0)
74
- parser (3.2.2.4)
73
+ parallel (1.24.0)
74
+ parser (3.3.0.5)
75
75
  ast (~> 2.4.1)
76
76
  racc
77
77
  pry (0.14.2)
@@ -83,7 +83,7 @@ GEM
83
83
  rb-fsevent (0.11.2)
84
84
  rb-inotify (0.10.1)
85
85
  ffi (~> 1.0)
86
- regexp_parser (2.8.3)
86
+ regexp_parser (2.9.0)
87
87
  rexml (3.2.6)
88
88
  rouge (3.30.0)
89
89
  rspec (3.12.0)
@@ -99,11 +99,11 @@ GEM
99
99
  diff-lcs (>= 1.2.0, < 2.0)
100
100
  rspec-support (~> 3.12.0)
101
101
  rspec-support (3.12.1)
102
- rubocop (1.58.0)
102
+ rubocop (1.60.2)
103
103
  json (~> 2.3)
104
104
  language_server-protocol (>= 3.17.0)
105
105
  parallel (~> 1.10)
106
- parser (>= 3.2.2.4)
106
+ parser (>= 3.3.0.2)
107
107
  rainbow (>= 2.2.2, < 4.0)
108
108
  regexp_parser (>= 1.8, < 3.0)
109
109
  rexml (>= 3.2.5, < 4.0)
@@ -112,6 +112,16 @@ GEM
112
112
  unicode-display_width (>= 2.4.0, < 3.0)
113
113
  rubocop-ast (1.30.0)
114
114
  parser (>= 3.2.1.0)
115
+ rubocop-capybara (2.20.0)
116
+ rubocop (~> 1.41)
117
+ rubocop-factory_bot (2.25.1)
118
+ rubocop (~> 1.41)
119
+ rubocop-rake (0.6.0)
120
+ rubocop (~> 1.0)
121
+ rubocop-rspec (2.26.1)
122
+ rubocop (~> 1.40)
123
+ rubocop-capybara (~> 2.17)
124
+ rubocop-factory_bot (~> 2.22)
115
125
  ruby-progressbar (1.13.0)
116
126
  rugged (1.7.1)
117
127
  shellany (0.0.1)
@@ -135,6 +145,8 @@ DEPENDENCIES
135
145
  rake
136
146
  rspec
137
147
  rubocop
148
+ rubocop-rake
149
+ rubocop-rspec
138
150
 
139
151
  BUNDLED WITH
140
- 2.4.22
152
+ 2.5.5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Caramelize
2
2
 
3
- [![Build Status](https://travis-ci.org/dahie/caramelize.svg?branch=master)](https://travis-ci.org/dahie/caramelize) [![Maintainability](https://api.codeclimate.com/v1/badges/7fe3ef34e09ba8133424/maintainability)](https://codeclimate.com/github/Dahie/caramelize/maintainability)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7fe3ef34e09ba8133424/maintainability)](https://codeclimate.com/github/Dahie/caramelize/maintainability)
4
4
 
5
5
  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.
6
6
 
@@ -107,8 +107,7 @@ Once the object is established we need to hook in a method that defines how revi
107
107
  latest: row["latest"] == "Y",
108
108
  time: row["time"],
109
109
  message: row["note"],
110
- author: author,
111
- author_name: row["user"]})
110
+ author: author})
112
111
  revisions << page
113
112
  end
114
113
  # titles is the list of all unique page titles contained in the wiki
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
  require 'bundler/gem_tasks'
3
5
 
@@ -7,4 +9,4 @@ RSpec::Core::RakeTask.new(:spec) do |task|
7
9
  task.rspec_opts = ['--color', '--format', 'documentation']
8
10
  end
9
11
 
10
- task :default => :spec
12
+ task default: :spec
data/bin/caramelize CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'caramelize'
4
5
  require 'commander/import'
@@ -20,10 +21,10 @@ command :new do |c|
20
21
  c.option '--config STRING', String, 'The config file (default: caramel.rb)'
21
22
  c.example 'Create a fresh config file as "caramel.rb"', 'caramelize create'
22
23
  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')
24
+ c.action do |_args, options|
25
+ target_file || options.config || 'caramel.rb'
25
26
  options.default({ config: 'caramel.rb' })
26
- FileUtils.cp(File.dirname(__FILE__) + '/../lib/caramelize/caramel.rb',
27
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/caramelize/#{target_file}",
27
28
  options.config)
28
29
  say "Created new configuration file: #{options.config}"
29
30
  end
@@ -37,7 +38,7 @@ command :run do |c|
37
38
  c.option '--config STRING', String, 'The config file (default: caramel.rb)'
38
39
  c.example 'Run transfer for "caramel.rb"', 'caramelize run'
39
40
  c.example 'Run transfer for "config.rb"', 'caramelize run --config config.rb'
40
- c.action do |args, options|
41
+ c.action do |_args, options|
41
42
  time_start = Time.now
42
43
  options.default({ config: 'caramel.rb', target: 'wiki-export' })
43
44
 
@@ -63,7 +64,7 @@ command :doctor do |c|
63
64
  c.description = 'Run health-check'
64
65
  c.option '--target STRING', String, 'The target path to Gollum git repository (default: wiki-export)'
65
66
  c.example 'Run transfer for "caramel.rb"', 'caramelize doctor'
66
- c.action do |args, options|
67
+ c.action do |_args, options|
67
68
  options.default(target: 'wiki-export')
68
69
 
69
70
  if File.exist?(options.target)
data/caramelize.gemspec CHANGED
@@ -1,33 +1,37 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "caramelize/version"
5
+ require 'caramelize/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "caramelize"
8
+ spec.name = 'caramelize'
8
9
  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{With Caramelize you can migrate any wiki to git-based Gollum wiki repositories.}
10
+ spec.license = 'MIT'
11
+ spec.authors = ['Daniel Senff']
12
+ spec.email = ['mail@danielsenff.de']
13
+ spec.homepage = 'http://github.com/Dahie/caramelize'
14
+ spec.summary = 'Flexible and modular wiki conversion tool'
15
+ spec.description = 'With Caramelize you can migrate any wiki to git-based Gollum wiki repositories.'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  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"]
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 3.1'
20
21
 
21
22
  spec.add_dependency('commander')
22
23
  spec.add_dependency('gollum-lib')
23
24
  spec.add_dependency('mysql2')
24
25
  spec.add_dependency('ruby-progressbar')
25
26
 
26
- spec.add_development_dependency "bundler", "~> 2"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec"
29
- spec.add_development_dependency "byebug"
30
- spec.add_development_dependency "rubocop"
31
- spec.add_development_dependency "guard"
32
- spec.add_development_dependency "guard-rspec"
27
+ spec.add_development_dependency 'bundler', '~> 2'
28
+ spec.add_development_dependency 'byebug'
29
+ spec.add_development_dependency 'guard'
30
+ spec.add_development_dependency 'guard-rspec'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'rubocop-rake'
35
+ spec.add_development_dependency 'rubocop-rspec'
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
33
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'caramelize/input_wiki/wikkawiki'
2
4
  require 'caramelize/input_wiki/redmine_wiki'
3
5
 
@@ -8,31 +10,29 @@ require 'caramelize/input_wiki/redmine_wiki'
8
10
 
9
11
  # Note, if you want to activate this, you need to uncomment the line below.
10
12
  def customized_wiki
11
-
12
13
  # This example is a reimplementation of the WikkaWiki-Connector.
13
14
  # To connect to WikkaWiki, I suggest to use the predefined Connector below.
14
- options = { host: "localhost",
15
- username: "user",
16
- database: "database_name",
15
+ options = { host: 'localhost',
16
+ username: 'user',
17
+ database: 'database_name',
17
18
  password: 'Picard-Delta-5',
18
- markup: :wikka}
19
+ markup: :wikka }
19
20
  wiki = Caramelize::InputWiki::Wiki.new(options)
20
21
  wiki.instance_eval do
21
22
  def read_pages
22
- sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
23
+ sql = 'SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;'
23
24
  results = database.query(sql)
24
25
  results.each do |row|
25
- titles << row["tag"]
26
- author = @authors[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"]}
26
+ titles << row['tag']
27
+ author = @authors[row['user']]
28
+ properties = { id: row['id'],
29
+ title: row['tag'],
30
+ body: row['body'],
31
+ markup: 'wikka',
32
+ latest: row['latest'] == 'Y',
33
+ time: row['time'],
34
+ message: row['note'],
35
+ author: }
36
36
  page = Page.new(properties)
37
37
  revisions << page
38
38
  end
@@ -44,35 +44,31 @@ def customized_wiki
44
44
  wiki
45
45
  end
46
46
 
47
-
48
47
  # if you want to use one of the preset Wiki-Connectors uncomment the connector
49
48
  # and edit the database logins accordingly.
50
49
  def predefined_wiki
51
-
52
50
  # For connection to a WikkaWiki-Database use this Connector
53
- #options = { host: "localhost",
51
+ # options = { host: "localhost",
54
52
  # username: "root",
55
53
  # password: "root",
56
54
  # database: "wikka" }
57
- #return Caramelize::InputWiki::WikkaWiki.new(options)
58
-
55
+ # return Caramelize::InputWiki::WikkaWiki.new(options)
59
56
 
60
57
  # For connection to a Redmine-Database use this Connector
61
58
  # Additional options:
62
59
  # :create_namespace_overview => true/false (Default: true) - Creates a new wikipage at /home as root page for Gollum wiki
63
- options = { host: "localhost",
64
- username: "root",
65
- password: "root",
66
- database: "redmine_development" }
67
- return Caramelize::InputWiki::RedmineWiki.new(options)
60
+ options = { host: 'localhost',
61
+ username: 'root',
62
+ password: 'root',
63
+ database: 'redmine_development' }
64
+ Caramelize::InputWiki::RedmineWiki.new(options)
68
65
  end
69
66
 
70
-
71
67
  def input_wiki
72
68
  # comment and uncomment to easily switch between predefined and
73
69
  # costumized Wiki-connectors.
74
70
 
75
- #return customized_wiki
71
+ # return customized_wiki
76
72
 
77
- return predefined_wiki
73
+ predefined_wiki
78
74
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby-progressbar'
2
4
 
3
5
  module Caramelize
4
-
5
6
  require 'caramelize/page'
6
7
  require 'caramelize/content_transferer'
7
8
  require 'caramelize/database_connector'
@@ -12,37 +13,37 @@ module Caramelize
12
13
  class ContentTransferer
13
14
  attr_reader :input_wiki, :options
14
15
 
15
- DEFAULT_GOLLUM_HOME_TITLE = 'Home'.freeze
16
+ DEFAULT_GOLLUM_HOME_TITLE = 'Home'
17
+ DEFAULT_AUTHOR_NAME = 'Caramelize'
18
+ DEFAULT_AUTHOR_EMAIL = 'caramelize@example.com'
16
19
 
17
20
  def initialize(input_wiki, options)
18
21
  @input_wiki = input_wiki
19
22
  @options = options
20
23
 
21
- options[:default_author] = options.fetch(:default_author, "Caramelize")
24
+ options[:default_author] = options.fetch(:default_author, 'Caramelize')
22
25
  options[:markup] = target_markup
23
26
  end
24
27
 
25
28
  def execute
26
29
  input_wiki.read_authors
27
-
28
30
  commit_history
29
-
30
- if verbose?
31
- puts "From markup: #{input_wiki.markup.to_s}"
32
- puts "To markup: #{target_markup.to_s}"
33
- puts "Convert latest revisions:"
34
- end
31
+ print_meta_data if verbose?
35
32
 
36
33
  migrate_markup_of_latest_revisions
37
34
 
38
- puts 'Create Namespace Overview' if verbose?
39
35
  create_overview_page_of_namespaces if options[:create_namespace_overview]
40
36
 
41
- rename_home_page
37
+ rename_home_page if options[:home_page_title]
42
38
  end
43
39
 
44
40
  private
45
41
 
42
+ def print_meta_data
43
+ puts "From markup: #{input_wiki.markup}"
44
+ puts "To markup: #{target_markup}"
45
+ end
46
+
46
47
  def target_markup
47
48
  @target_markup ||=
48
49
  needs_conversion_to_target_markup? ? input_wiki.markup : :markdown
@@ -77,29 +78,47 @@ module Caramelize
77
78
  end
78
79
 
79
80
  def create_overview_page_of_namespaces
81
+ puts 'Create Namespace Overview' if verbose?
80
82
  output_wiki.commit_namespace_overview(input_wiki.namespaces)
81
83
  end
82
84
 
83
85
  def migrate_markup_progress_bar
84
86
  @migrate_markup_progress_bar ||=
85
- ProgressBar.create(title: "Markup filters",
87
+ ProgressBar.create(title: 'Markup filters',
86
88
  total: latest_revisions_count)
87
89
  end
88
90
 
89
91
  def commit_history_progress_bar
90
92
  @commit_history_progress_bar ||=
91
- ProgressBar.create(title: "Revisions",
93
+ ProgressBar.create(title: 'Revisions',
92
94
  total: revisions_count)
93
95
  end
94
96
 
95
97
  def migrate_markup_of_latest_revisions
98
+ puts 'Convert latest revisions:' if verbose?
96
99
  input_wiki.latest_revisions.each do |revision|
100
+ if input_wiki.excluded_pages.include?(revision.title)
101
+ puts "Exclude Page: #{revision.title}" if verbose?
102
+ next
103
+ end
104
+
105
+ if verbose?
106
+ puts "Filter source: #{revision.title} #{revision.time}"
107
+ else
108
+ migrate_markup_progress_bar.increment
109
+ end
110
+
97
111
  migrate_markup_of_revision(revision)
98
112
  end
99
113
  end
100
114
 
101
115
  def commit_history
102
116
  output_wiki.commit_history(revisions, options) do |page, index|
117
+ if input_wiki.excluded_pages.include?(page.title)
118
+ puts "Exclude Page: #{page.title}" if verbose?
119
+ next
120
+ end
121
+
103
122
  if verbose?
104
123
  puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
105
124
  else
@@ -109,27 +128,27 @@ module Caramelize
109
128
  end
110
129
 
111
130
  def migrate_markup_of_revision(revision)
112
- if verbose?
113
- puts "Filter source: #{revision.title} #{revision.time}"
114
- else
115
- migrate_markup_progress_bar.increment
116
- end
117
-
118
131
  body_new = filter_processor.run(revision.body)
119
132
 
120
- unless body_new == revision.body
121
- revision.body = body_new
122
- revision.author_name = 'Caramelize'
123
- revision.time = Time.now
124
- revision.author = nil
125
- revision.message = "Markup of '#{revision.title}' converted to #{target_markup}"
133
+ return if body_new == revision.body
126
134
 
127
- # commit as latest page revision
128
- output_wiki.commit_revision(revision, options[:markup])
129
- end
135
+ message = "Markup of '#{revision.title}' converted to #{target_markup}"
136
+
137
+ # commit as latest page revision
138
+ output_wiki.commit_revision(build_revision_metadata(revision, body_new, message), options[:markup])
139
+ end
140
+
141
+ def build_revision_metadata(revision, body_new, message)
142
+ revision.body = body_new
143
+ revision.author = { name: DEFAULT_AUTHOR_NAME, email: DEFAULT_AUTHOR_EMAIL }
144
+ revision.time = Time.now
145
+ revision.message = message
146
+
147
+ revision
130
148
  end
131
149
 
132
150
  def rename_home_page
151
+ puts "Rename page #{options[:home_page_title]} to #{DEFAULT_GOLLUM_HOME_TITLE}" if verbose?
133
152
  output_wiki.rename_page(options[:home_page_title], DEFAULT_GOLLUM_HOME_TITLE)
134
153
  end
135
154
  end
@@ -1,16 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mysql2'
2
4
 
3
5
  module Caramelize
4
6
  module DatabaseConnector
5
-
6
7
  def database
7
- socket = ["/tmp/mysqld.sock",
8
- "/tmp/mysql.sock",
9
- "/var/run/mysqld/mysqld.sock",
10
- "/opt/local/var/run/mysql5/mysqld.sock",
11
- "/var/lib/mysql/mysql.sock"].detect{|socket| File.exist?(socket) }
12
- @options[:socket] = socket
13
- @client = Mysql2::Client.new(@options) unless @client
8
+ @options[:socket] = ['/tmp/mysqld.sock',
9
+ '/tmp/mysql.sock',
10
+ '/var/run/mysqld/mysqld.sock',
11
+ '/opt/local/var/run/mysql5/mysqld.sock',
12
+ '/var/lib/mysql/mysql.sock'].detect { |socket| File.exist?(socket) }
13
+ @client ||= Mysql2::Client.new(@options)
14
14
  @client
15
15
  end
16
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
4
  class FilterProcessor
3
5
  attr_reader :filters, :input_wiki
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caramelize
4
+ class CamelCaseToWikiLinks
5
+ def initialize(body)
6
+ @body = body
7
+ end
8
+
9
+ # take an input stream and convert all wikka syntax to markdown syntax
10
+ def run
11
+ migrated_body = @body.dup
12
+
13
+ migrated_body.gsub!(/([^\[\|\w\S])([A-Z]\w+[A-Z]\w+)([^\]])/) { "#{::Regexp.last_match(1)}#{format_link(::Regexp.last_match(2))}#{::Regexp.last_match(3)}" }
14
+
15
+ migrated_body
16
+ end
17
+
18
+ private
19
+
20
+ def format_link(link)
21
+ link.gsub!(' ', '_')
22
+ link.gsub!('.', '')
23
+ "[[#{link}]]"
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
4
  class RemoveTableTabLineEndings
3
-
4
5
  def initialize(body)
5
6
  @body = body
6
7
  end
@@ -8,7 +9,7 @@ module Caramelize
8
9
  # take an input stream and convert all wikka syntax to markdown syntax
9
10
  def run
10
11
  migrated_body = @body.dup
11
- migrated_body.gsub!(/\|[\t ]*\r?[\n]/, "|\n")
12
+ migrated_body.gsub!(/\|[\t ]*\r?\n/, "|\n")
12
13
  migrated_body
13
14
  end
14
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
4
  class SwapWikiLinks
3
5
  def initialize(body)
@@ -8,8 +10,8 @@ module Caramelize
8
10
  def run
9
11
  migrated_body = @body.dup
10
12
 
11
- migrated_body.gsub!(/\[\[(\S+)\|(.+?)\]\]/) { format_link($2, $1) }
12
- migrated_body.gsub!(/\[\[([\w\s\-\.]*)\]\]/) { format_link($1, $1.dup) }
13
+ migrated_body.gsub!(/\[\[(\S+)\|(.+?)\]\]/) { format_link(::Regexp.last_match(2), ::Regexp.last_match(1)) }
14
+ migrated_body.gsub!(/\[\[([\w\s\-.]*)\]\]/) { format_link(::Regexp.last_match(1), ::Regexp.last_match(1).dup) }
13
15
 
14
16
  migrated_body
15
17
  end
@@ -19,7 +21,7 @@ module Caramelize
19
21
  def format_link(label, link)
20
22
  link.downcase!
21
23
  link.gsub!(' ', '_')
22
- link.gsub!(/\./, '')
24
+ link.gsub!('.', '')
23
25
  "[[#{label}|#{link}]]"
24
26
  end
25
27
  end