caramelize 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7fe435304327d466829f0dcbe0ab9ed23978da90c0c992f1464d123cffa3965
4
- data.tar.gz: f89cdef42b840eff1869081e813cb37f93172fea6a5c7446ffba2685b34aae88
3
+ metadata.gz: 794ae829880cb349361e52ec4ca6a313e08c228aee66816e1be297b55dcc21f5
4
+ data.tar.gz: a755af756c4a6b450166ecbb8ebd23b4dd24a9e840728ddb40d2b8e6e214f04b
5
5
  SHA512:
6
- metadata.gz: 2b1c74be41c73bd7e0f35e4f9441f9bc96a5a6f04e994502b70fec73fda7444e8d7e8e4fb8868d5822d4333e4f3a37b2348f954d8d37064674ee68046e8d6c58
7
- data.tar.gz: 3b7a59b339ef5779ab86be0ee4a054f0772f58483db5edee3479d736f355ad4f04bfac06e46fda39319fc431c2003885687666abc0da854b080631484f3bcd10
6
+ metadata.gz: 9a3b6071991c74dbc86218e7646a8cd09c90aba0e51708a7f698a0b38e3338f3ea95580822e316ddd3c7ad8ba28ee3ae8874bc3c6e3c65ca2838fd7943d44e43
7
+ data.tar.gz: 8f6de4f36f2aca5a6b08c230a02f0a56e51bfb3f0e3cf1b57e04d052ee3ecd963d09845c0416b27b89b99a3f8ffafbfe4b43e1c04ceb5b596575be7d01f9eecd
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ before_install:
5
+ - gem install bundler
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at public@danielsenff.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # caramelize
1
+ # Caramelize
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)
2
4
 
3
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.
4
6
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'bundler/gem_tasks'
4
4
  # Default directory to look in is `/specs`
5
5
  # Run with `rake spec`
6
6
  RSpec::Core::RakeTask.new(:spec) do |task|
7
- task.rspec_opts = ['--color', '--format', 'nested']
7
+ task.rspec_opts = ['--color', '--format', 'documentation']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task :default => :spec
@@ -6,7 +6,7 @@ require 'commander/import'
6
6
  # :name is optional, otherwise uses the basename of this executable
7
7
  program :name, 'caramelize'
8
8
  program :version, Caramelize::VERSION
9
- program :description, 'TODO'
9
+ program :description, 'With Caramelize you can migrate any wiki to git-based Gollum wiki repositories.'
10
10
  program :help, 'Author', 'Daniel Senff <public@danielsenff.de>'
11
11
 
12
12
  default_command :run
@@ -25,7 +25,7 @@ command :new do |c|
25
25
  options.default({ config: 'caramel.rb' })
26
26
  FileUtils.cp(File.dirname(__FILE__) + '/../lib/caramelize/caramel.rb',
27
27
  options.config)
28
- say "Created new configuration file: #{optinos.config}"
28
+ say "Created new configuration file: #{options.config}"
29
29
  end
30
30
  end
31
31
  alias_command :create, :new
@@ -39,12 +39,19 @@ command :run do |c|
39
39
  c.example 'Run transfer for "config.rb"', 'caramelize run --config config.rb'
40
40
  c.action do |args, options|
41
41
  time_start = Time.now
42
- options.default({ config: 'caramel.rb' })
43
- puts options.inspect
42
+ options.default({ config: 'caramel.rb', target: 'wiki-export' })
44
43
 
45
44
  instance_eval(File.read(options.config))
46
45
 
47
- wiki_options = input_wiki.options.merge(verbose: options.verbose)
46
+ target = options.target
47
+
48
+ if File.exists?(target)
49
+ answer = agree("#{target} already exists. Overwrite with fresh repository?")
50
+ FileUtils.rm_rf(target) if answer
51
+ end
52
+
53
+ wiki_options = input_wiki.options.merge(verbose: options.verbose,
54
+ target: options.target)
48
55
  Caramelize::ContentTransferer.new(input_wiki, wiki_options).execute
49
56
  say "Time required: #{Time.now - time_start} s"
50
57
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["mail@danielsenff.de"]
12
12
  spec.homepage = "http://github.com/Dahie/caramelize"
13
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.}
14
+ spec.description = %q{With Caramelize you can migrate any wiki to git-based Gollum wiki repositories.}
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency('mysql2')
22
22
  spec.add_dependency('commander')
23
- spec.add_dependency('docile')
24
23
  spec.add_dependency('ruby-progressbar')
25
- spec.add_dependency('gollum-lib', '>= 1.0.0') # grit dependency implicit through gollum
24
+ spec.add_dependency('gollum-lib')
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.6"
28
27
  spec.add_development_dependency "rake"
@@ -1,6 +1,5 @@
1
1
  require 'caramelize/version'
2
2
  require 'caramelize/page'
3
- require 'caramelize/ext'
4
3
  require 'caramelize/content_transferer'
5
4
  require 'caramelize/filter_processor'
6
5
  require 'caramelize/database_connector'
@@ -10,3 +9,5 @@ require 'caramelize/input_wiki/wiki'
10
9
  require 'caramelize/input_wiki/redmine_wiki'
11
10
  require 'caramelize/input_wiki/wikkawiki'
12
11
 
12
+ Encoding.default_external = Encoding::UTF_8
13
+ Encoding.default_internal = Encoding::UTF_8
@@ -1,11 +1,8 @@
1
- require 'gollum-lib'
2
- require 'grit'
3
1
  require 'ruby-progressbar'
4
2
 
5
3
  module Caramelize
6
4
 
7
5
  require 'caramelize/page'
8
- require 'caramelize/ext'
9
6
  require 'caramelize/content_transferer'
10
7
  require 'caramelize/database_connector'
11
8
  require 'caramelize/output_wiki/gollum'
@@ -15,12 +12,13 @@ module Caramelize
15
12
  class ContentTransferer
16
13
  attr_reader :input_wiki, :options, :filter_processor
17
14
 
15
+ DEFAULT_GOLLUM_HOME_TITLE = 'Home'.freeze
16
+
18
17
  def initialize(input_wiki, options)
19
18
  @input_wiki = input_wiki
20
19
  @options = options
21
20
 
22
21
  options[:default_author] = options.fetch(:default_author, "Caramelize")
23
- options[:target_directory] = './wiki-export'
24
22
  options[:markup] = target_markup
25
23
  end
26
24
 
@@ -39,6 +37,8 @@ module Caramelize
39
37
 
40
38
  puts 'Create Namespace Overview' if verbose?
41
39
  create_overview_page_of_namespaces if options[:create_namespace_overview]
40
+
41
+ rename_home_page
42
42
  end
43
43
 
44
44
  private
@@ -57,7 +57,7 @@ module Caramelize
57
57
  end
58
58
 
59
59
  def output_wiki
60
- @output_wiki ||= OutputWiki::Gollum.new(options[:target_directory])
60
+ @output_wiki ||= OutputWiki::Gollum.new(options[:target])
61
61
  end
62
62
 
63
63
  def filter_processor
@@ -72,51 +72,65 @@ module Caramelize
72
72
  revisions.count
73
73
  end
74
74
 
75
+ def latest_revisions_count
76
+ input_wiki.latest_revisions.count
77
+ end
78
+
75
79
  def create_overview_page_of_namespaces
76
80
  output_wiki.commit_namespace_overview(input_wiki.namespaces)
77
81
  end
78
82
 
79
- def migrate_markup_of_latest_revisions
80
- progress_bar = ProgressBar.create(title: "Markup filters",
81
- total: revisions_count)
83
+ def migrate_markup_progress_bar
84
+ @migrate_markup_progress_bar ||=
85
+ ProgressBar.create(title: "Markup filters",
86
+ total: latest_revisions_count)
87
+ end
82
88
 
89
+ def commit_history_progress_bar
90
+ @commit_history_progress_bar ||=
91
+ ProgressBar.create(title: "Revisions",
92
+ total: revisions_count)
93
+ end
94
+
95
+ def migrate_markup_of_latest_revisions
83
96
  input_wiki.latest_revisions.each do |revision|
84
- migrate_markup_of_revision(revision, progress_bar)
97
+ migrate_markup_of_revision(revision)
85
98
  end
86
99
  end
87
100
 
88
101
  def commit_history
89
- puts revisions_count
90
- progress_bar = ProgressBar.create(title: "Revisions",
91
- total: revisions_count)
92
-
93
102
  output_wiki.commit_history(revisions, options) do |page, index|
94
103
  if verbose?
95
104
  puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
96
105
  else
97
- progress_bar.increment
106
+ commit_history_progress_bar.increment
98
107
  end
99
108
  end
100
109
  end
101
110
 
102
- def migrate_markup_of_revision(revision, progress_bar)
111
+ def migrate_markup_of_revision(revision)
103
112
  if verbose?
104
113
  puts "Filter source: #{revision.title} #{revision.time}"
105
114
  else
106
- progress_bar.increment
115
+ migrate_markup_progress_bar.increment
107
116
  end
108
117
 
109
118
  body_new = filter_processor.run(revision.body)
110
119
 
111
120
  unless body_new == revision.body
112
121
  revision.body = body_new
113
- revision.author_name = target_markup
122
+ revision.author_name = 'Caramelize'
114
123
  revision.time = Time.now
115
124
  revision.author = nil
125
+ revision.message = "Markup of '#{revision.title}' converted to #{target_markup}"
116
126
 
117
127
  # commit as latest page revision
118
128
  output_wiki.commit_revision(revision, options[:markup])
119
129
  end
120
130
  end
131
+
132
+ def rename_home_page
133
+ output_wiki.rename_page(options[:home_page_title], DEFAULT_GOLLUM_HOME_TITLE)
134
+ end
121
135
  end
122
136
  end
@@ -1,5 +1,4 @@
1
1
  require 'gollum-lib'
2
- require 'grit'
3
2
  require 'ruby-progressbar'
4
3
 
5
4
  module Caramelize
@@ -16,7 +15,7 @@ module Caramelize
16
15
  def run(body)
17
16
  body_new = body
18
17
  filters.each do |filter|
19
- body_new = filter.run(body_new)
18
+ body_new = filter.new(body_new).run
20
19
  end
21
20
  body_new
22
21
  end
@@ -1,9 +1,13 @@
1
1
  module Caramelize
2
2
  class RemoveTableTabLineEndings
3
3
 
4
+ def initialize(body)
5
+ @body = body
6
+ end
7
+
4
8
  # take an input stream and convert all wikka syntax to markdown syntax
5
- def run body
6
- migrated_body = body.dup
9
+ def run
10
+ migrated_body = @body.dup
7
11
  migrated_body.gsub!(/\|[\t ]*\r?[\n]/, "|\n")
8
12
  migrated_body
9
13
  end
@@ -1,9 +1,13 @@
1
1
  module Caramelize
2
2
  class SwapWikiLinks
3
3
 
4
+ def initialize(body)
5
+ @body = body
6
+ end
7
+
4
8
  # take an input stream and convert all wikka syntax to markdown syntax
5
- def run body
6
- migrated_body = body.dup
9
+ def run
10
+ migrated_body = @body.dup
7
11
 
8
12
  migrated_body.gsub!(/\[\[(\S+)\|(.+?)\]\]/, '[[\2|\1]]')
9
13
  migrated_body.gsub!(/\[\[([\w\s\.]*)\]\]/) do |s|
@@ -1,39 +1,67 @@
1
1
  module Caramelize
2
2
  class Wikka2Markdown
3
+ attr_reader :source_body
3
4
 
4
- # take an input stream and convert all wikka syntax to markdown syntax
5
- def run body
6
- body = body.dup
7
- body.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
8
- body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2
9
- body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3
10
- body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4
11
-
12
- body.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold
13
- body.gsub!(/(\/\/)(.*?)(\/\/)/) {|s| '_' + $2 + '_' } #italic
14
- #str.gsub!(/(===)(.*?)(===)/) {|s| '`' + $2 + '`'} #code
15
- body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline
16
- body.gsub!(/(---)/, ' ') #forced linebreak
17
-
18
- #body.gsub!(/(.*?)(\n\t-)(.*?)/) {|s| $1 + $3 } #list
19
-
20
- body.gsub!(/(\t-)(.*)/, '*\2') # unordered list
21
- body.gsub!(/(~-)(.*)/, '*\2') # unordered list
22
- body.gsub!(/( -)(.*)/, '*\2') # unordered list
23
- # TODO ordered lists
5
+ def initialize(source_body)
6
+ @source_body = source_body
7
+ end
24
8
 
9
+ def run
25
10
  # TODO images: ({{image)(url\=?)?(.*)(}})
11
+ # markdown: ![Tux, the Linux mascot](/assets/images/tux.png)
12
+
13
+ replace_headlines
14
+ replace_formatting
15
+ replace_lists
16
+ replace_wiki_links
17
+ replace_links
18
+ replace_code_block
19
+
20
+ target_body
21
+ end
22
+
23
+ def replace_headlines
24
+ target_body.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
25
+ target_body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2
26
+ target_body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3
27
+ target_body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4
28
+ target_body.gsub!(/(==)(.*?)(==)/) {|s| '##### ' + $2 } #h5
29
+ end
26
30
 
27
- #str.gsub!(/(----)/) {|s| '~~~~'} #seperator
31
+ def replace_formatting
32
+ target_body.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold
33
+ target_body.gsub!(/(\/\/)(.*?)(\/\/)/, '*\2*') #italic
34
+ target_body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline
35
+ target_body.gsub!(/(---)/, ' ') #forced linebreak
36
+ end
28
37
 
38
+ def replace_lists
39
+ target_body.gsub!(/(\t-\s?)(.*)/, '* \2') # unordered list
40
+ target_body.gsub!(/(~-\s?)(.*)/, '* \2') # unordered list
41
+ target_body.gsub!(/( -\s?)(.*)/, '* \2') # unordered list
29
42
 
30
- body.gsub!(/(\[\[)(\w+)\s(.+?)(\]\])/, '[[\3|\2]]')
31
- #body.gsub!(/\[\[(\w+)\s(.+)\]\]/, ' [[\1 | \2]] ')
43
+ target_body.gsub!(/(~1\)\s?)(.*)/, '1. \2') # unordered list
44
+ # TODO ordered lists
45
+ end
32
46
 
47
+ def replace_wiki_links
48
+ target_body.gsub!(/[\[]{2}(\w+)[\s|](.+?)[\]]{2}/, '[[\2|\1]]')
49
+ end
33
50
 
34
- # TODO more syntax conversion for links and images
51
+ def replace_links
52
+ target_body.gsub!(/[\[]{2}((\w+):[\S][^\| ]*)[\| ](.*)[\]]{2}/,
53
+ '[\3](\1)')
54
+ target_body.gsub!(/[\[]{2}((\w+):.*)[\]]{2}/, '<\1>')
55
+ end
56
+
57
+ def replace_code_block
58
+ target_body.gsub!(/^%%\s(.*?)%%\s?/m) do
59
+ $1.gsub(/^/, ' ')
60
+ end
61
+ end
35
62
 
36
- body
63
+ def target_body
64
+ @target_body ||= source_body.dup
37
65
  end
38
66
  end
39
67
  end