caramelize 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,44 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- caramelize (0.0.1)
4
+ caramelize (0.0.4)
5
+ cmdparse
5
6
  gollum (>= 1.3.0)
6
7
  mysql2
7
- treetop (>= 1.4.9)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
12
  albino (1.3.3)
13
13
  posix-spawn (>= 0.3.6)
14
- diff-lcs (1.1.2)
15
- github-markup (0.5.3)
16
- gollum (1.3.0)
14
+ cmdparse (2.0.3)
15
+ diff-lcs (1.1.3)
16
+ github-markup (0.7.0)
17
+ gollum (1.3.1)
17
18
  albino (~> 1.3.2)
18
19
  github-markup (>= 0.4.0, < 1.0.0)
19
20
  grit (~> 2.4.1)
20
21
  mustache (>= 0.11.2, < 1.0.0)
21
22
  nokogiri (~> 1.4)
23
+ redcarpet
22
24
  sanitize (~> 2.0.0)
23
25
  sinatra (~> 1.0)
24
26
  grit (2.4.1)
25
27
  diff-lcs (~> 1.1)
26
28
  mime-types (~> 1.15)
27
- mime-types (1.16)
29
+ mime-types (1.17.2)
28
30
  mustache (0.99.4)
29
- mysql2 (0.3.2)
30
- nokogiri (1.4.4)
31
- polyglot (0.3.1)
31
+ mysql2 (0.3.11)
32
+ nokogiri (1.5.0)
32
33
  posix-spawn (0.3.6)
33
- rack (1.3.0)
34
- sanitize (2.0.2)
35
- nokogiri (~> 1.4.4)
36
- sinatra (1.2.6)
37
- rack (~> 1.1)
38
- tilt (>= 1.2.2, < 2.0)
39
- tilt (1.3.2)
40
- treetop (1.4.9)
41
- polyglot (>= 0.3.1)
34
+ rack (1.3.5)
35
+ rack-protection (1.1.4)
36
+ rack
37
+ redcarpet (2.0.1)
38
+ sanitize (2.0.3)
39
+ nokogiri (>= 1.4.4, < 1.6)
40
+ sinatra (1.3.1)
41
+ rack (~> 1.3, >= 1.3.4)
42
+ rack-protection (~> 1.1, >= 1.1.2)
43
+ tilt (~> 1.3, >= 1.3.3)
44
+ tilt (1.3.3)
42
45
 
43
46
  PLATFORMS
44
47
  ruby
data/README.md CHANGED
@@ -8,8 +8,6 @@ In the future more target wiki system may be added. For the moment export is sup
8
8
 
9
9
  ### Building
10
10
 
11
- For the moment caramelize is not yet stable and not released to any gemsites.
12
-
13
11
  To try it you require bundler to build it.
14
12
 
15
13
  $ gem bundler install
@@ -31,21 +29,32 @@ to install the new gem right to the system.
31
29
 
32
30
  ### Use
33
31
 
34
- $ caramelize create <directory>
35
-
36
- Creates a template configuration file. This includes documentation on how to use the preset Wiki-connectors and how to write addition customized connectors.
32
+ $ caramelize create
37
33
 
34
+ 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.
38
35
 
39
36
  $ caramelize run
40
37
 
41
38
  Will execute a wiki migration based on a found configuration file. These are found in predefined paths.
42
39
 
43
40
  $ caramelize help
41
+
44
42
  Returns help information.
45
43
 
46
44
  $ caramelize version
45
+
47
46
  Returns version and release information.
48
47
 
48
+ ### Options
49
+
50
+ $ caramelize create --config my_caramel_configuration.rb
51
+
52
+ Creates an example config with the given name.
53
+
54
+ $ caramelize run --config my_caramel_configuration.rb
55
+
56
+ Executes the given configuration.
57
+
49
58
  ## Contributing to caramelize
50
59
 
51
60
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'bundler'
2
+ require 'rdoc/task'
3
+
2
4
  Bundler::GemHelper.install_tasks
5
+
6
+ Rake::RDocTask.new do |rd|
7
+ rd.main = "README.rdoc"
8
+ rd.rdoc_files.include( "lib/**/*.rb")
9
+ end
@@ -1,6 +1,8 @@
1
- require 'caramelize/wiki'
2
- require 'caramelize/wikkawiki'
3
- require 'caramelize/redmine_wiki'
1
+ require 'caramelize/wiki/wiki'
2
+ require 'caramelize/wiki/wikkawiki'
3
+ require 'caramelize/wiki/redmine_wiki'
4
+
5
+ ## Example caramelize configuration file
4
6
 
5
7
  # Within this method you can define your own Wiki-Connectors to Wikis not supported by default in this software
6
8
 
@@ -9,7 +11,11 @@ def customized_wiki
9
11
 
10
12
  # This example is a reimplementation of the WikkaWiki-Connector.
11
13
  # To connect to WikkaWiki, I suggest to use the predefined Connector below.
12
- wiki = Caramelize::Wiki.new(:host => "localhost", :username => "user", :database => "database_name", :password => 'admin_gnihihihi', :syntax => :wikka)
14
+ wiki = Caramelize::Wiki.new({:host => "localhost",
15
+ :username => "user",
16
+ :database => "database_name",
17
+ :password => 'admin_gnihihihi',
18
+ :markup => :wikka})
13
19
  wiki.instance_eval do
14
20
  def read_pages
15
21
  sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
@@ -21,7 +27,7 @@ def customized_wiki
21
27
  page = Page.new({:id => row["id"],
22
28
  :title => row["tag"],
23
29
  :body => row["body"],
24
- :syntax => 'wikka',
30
+ :markup => 'wikka',
25
31
  :latest => row["latest"] == "Y",
26
32
  :time => row["time"],
27
33
  :message => row["note"],
@@ -44,11 +50,17 @@ end
44
50
  def predefined_wiki
45
51
 
46
52
  # For connection to a WikkaWiki-Database use this Connector
47
- #return Caramelize::WikkaWiki.new(:host => "localhost", :username => "root", :database => "wikka")
53
+ #return Caramelize::WikkaWiki.new(:host => "localhost",
54
+ # :username => "root",
55
+ # :password => "root",
56
+ # :database => "wikka")
48
57
 
49
58
 
50
59
  # For connection to a Redmine-Database use this Connector
51
- return Caramelize::RedmineWiki.new(:host => "localhost", :username => "root", :database => "redmine_development")
60
+ return Caramelize::RedmineWiki.new(:host => "localhost",
61
+ :username => "root",
62
+ :password => "root",
63
+ :database => "redmine_development")
52
64
  end
53
65
 
54
66
 
@@ -1,3 +1,4 @@
1
+ #Encoding: UTF-8
1
2
  require 'cmdparse'
2
3
  require 'caramelize/version'
3
4
 
@@ -15,23 +16,18 @@ module Caramelize
15
16
  # arguments and executing the requested command.
16
17
  class CommandParser < CmdParse::CommandParser
17
18
 
18
- # The website directory. Default: the current working directory.
19
- attr_reader :directory
20
-
21
19
  # The verbosity level. Default: <tt>:normal</tt>
22
20
  attr_reader :verbosity
23
21
 
24
22
  # Create a new CommandParser class. T
25
23
  def initialize
26
24
  super(true)
27
- @directory = nil
28
25
  @verbosity = :normal
29
26
 
30
27
  self.program_name = "caramelize"
31
28
  self.program_version = Caramelize::VERSION
32
29
  self.options = CmdParse::OptionParserWrapper.new do |opts|
33
30
  opts.separator "Global options:"
34
- opts.on("--config DIR", "-d", String, "The config file (default: caramel.rb)") {|p| @directory = p}
35
31
  opts.on("--verbose", "-v", "Print more output") { @verbosity = :verbose }
36
32
  opts.on("--quiet", "-q", "No output") { @verbosity = :quiet }
37
33
  end
@@ -44,24 +40,25 @@ module Caramelize
44
40
  # Finds the configuration file, if it exists in a known location.
45
41
  def detect_configuration_file(config_path = nil)
46
42
  possible_files = KNOWN_CONFIG_LOCATIONS
43
+ possible_files << config_path if config_path
47
44
  possible_files.detect{|f| File.exists?(f)}
48
45
  end
49
46
 
50
47
  # Utility method for sub-commands to transfer wiki contents
51
- def transfer_content
52
-
48
+ def transfer_content config_file = ""
53
49
  time_start = Time.now
54
50
 
55
- file = detect_configuration_file
51
+ file = detect_configuration_file config_file
52
+ puts "Read config file: #{file}" if @verbosity == :verbose
56
53
  if file && File.exists?(file)
57
54
  instance_eval(File.read(file), file || '<eval>')
58
55
  original_wiki = input_wiki
59
56
 
60
- ContentTransferer.execute original_wiki, {:verbosity => @verbosity}
57
+ ContentTransferer.execute(original_wiki, {:verbosity => @verbosity})
61
58
 
62
59
  time_end = Time.now
63
60
 
64
- puts "Time required: #{time_end - time_start} s" if @verbosity
61
+ puts "Time required: #{time_end - time_start} s" if @verbosity == :verbose
65
62
  else
66
63
  puts "No config file found."
67
64
  end
@@ -1,5 +1,4 @@
1
1
  #Encoding: UTF-8
2
-
3
2
  require 'caramelize/cli'
4
3
 
5
4
  module Caramelize::CLI
@@ -7,48 +6,44 @@ module Caramelize::CLI
7
6
  # The CLI command for creating a caramelize config file.
8
7
  class CreateCommand < CmdParse::Command
9
8
 
9
+ # The website config-file. Default: the current working directory.
10
+ attr_reader :config_file
11
+
10
12
  def initialize #:nodoc:
11
13
  super('create', false)
12
- #self.description = Utils.format("If the verbosity level is set to verbose, the created files are listed.")
14
+ self.description = "If the verbosity level is set to verbose, the created files are listed."
13
15
  self.short_desc = 'Create a default config file for caramelize'
14
16
  self.options = CmdParse::OptionParserWrapper.new do |opts|
15
17
  opts.separator "Arguments:"
16
- opts.separator opts.summary_indent + "DIR: the directory in which the website should be created"
18
+ opts.on("--config <file>", "-f", String, "The config file (default: caramel.rb)") {|p| @config_file = p}
17
19
  end
18
20
  end
19
21
 
20
22
  def usage # :nodoc:
21
- "Usage: #{commandparser.program_name} [global options] create [options] DIR"
23
+ "Usage: #{commandparser.program_name} [global options] create [options]"
22
24
  end
23
25
 
24
- # Create a caramelize config file in the directory <tt>args[0]</tt>.
26
+ # Create a caramelize config file.
25
27
  def execute(args)
26
- if args.length == 0
27
- raise OptionParser::MissingArgument.new('DIR')
28
- else
29
- begin
30
-
31
- # TODO create dummy config file
32
-
33
- puts "Created new configuration file: caramelize.rb"
34
- #puts args[0]
35
- require 'fileutils'
36
-
37
- FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", args[0])
38
-
39
- #File.open('caremelize.rb',"w+") do |f|
40
- # f << "query_data"
41
- #end
42
-
43
- rescue
44
- #require 'fileutils'
45
- #FileUtils.rm_rf(args[0])
46
- raise
47
- end
48
- if commandparser.verbosity == :verbose
49
- puts "The following files were created in the directory #{args[0]}:"
50
- #puts paths.sort.join("\n")
51
- end
28
+ begin
29
+
30
+ # create dummy config file
31
+ target_file = @config_file.nil? ? "caramel.rb" : @config_file
32
+
33
+
34
+ #puts args[0]
35
+ require 'fileutils'
36
+
37
+ FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", target_file)
38
+
39
+ rescue
40
+ #require 'fileutils'
41
+ #FileUtils.rm_rf(args[0])
42
+ raise
43
+ end
44
+ if commandparser.verbosity == :normal
45
+ puts "Created new configuration file: #{target_file}"
46
+ #puts paths.sort.join("\n")
52
47
  end
53
48
  end
54
49
 
@@ -1,5 +1,4 @@
1
1
  #Encoding: UTF-8
2
-
3
2
  require 'caramelize/cli'
4
3
 
5
4
  module Caramelize::CLI
@@ -7,14 +6,26 @@ module Caramelize::CLI
7
6
  # The CLI command for rendering a webgen website.
8
7
  class RunCommand < CmdParse::Command
9
8
 
9
+ # The website config-file. Default: the current working directory.
10
+ attr_reader :config_file
11
+
10
12
  def initialize # :nodoc:
11
13
  super('run', false)
12
14
  self.short_desc = 'Run the wiki content transfer based on the given config file'
15
+ self.options = CmdParse::OptionParserWrapper.new do |opts|
16
+ opts.separator "Arguments:"
17
+ #opts.separator opts.summary_indent + "DIR: the directory in which the website should be created"
18
+ opts.on("--config <file>", "-f", String, "The config file (default: caramel.rb)") {|p| @config_file = p}
19
+ end
20
+ end
21
+
22
+ def usage # :nodoc:
23
+ "Usage: #{commandparser.program_name} [global options] run [options]"
13
24
  end
14
25
 
15
26
  # Transfer Wiki contents
16
27
  def execute(args)
17
- commandparser.transfer_content
28
+ commandparser.transfer_content @config_file
18
29
  end
19
30
 
20
31
  end
@@ -4,11 +4,10 @@ require 'gollum'
4
4
  require 'grit'
5
5
 
6
6
  module Caramelize
7
- autoload :Wiki, 'caramelize/wiki'
8
- autoload :WikkaWiki, 'caramelize/wikkawiki'
9
- autoload :RedmineWiki, 'caramelize/redmine_wiki'
7
+ autoload :Wiki, 'caramelize/wiki/wiki'
8
+ autoload :WikkaWiki, 'caramelize/wiki/wikkawiki'
9
+ autoload :RedmineWiki, 'caramelize/wiki/redmine_wiki'
10
10
  autoload :GollumOutput, 'caramelize/gollum_output'
11
- autoload :Wikka2MarkdownConverter, 'wikka2markdown_converter'
12
11
  autoload :Author, 'caramelize/author'
13
12
  autoload :Page, 'caramelize/page'
14
13
 
@@ -16,7 +15,10 @@ module Caramelize
16
15
  class ContentTransferer
17
16
 
18
17
  # Execute the content migration
19
- def self.execute original_wiki, options={}
18
+ def self.execute(original_wiki, options={})
19
+
20
+ options[:markup] = :markdown if !options[:markup]
21
+ options[:default_author] = "Caramelize" if !options[:default_author]
20
22
 
21
23
  # read page revisions from wiki
22
24
  # store page revisions
@@ -25,32 +27,46 @@ module Caramelize
25
27
  @revisions = original_wiki.read_pages
26
28
 
27
29
  # initiate new wiki
30
+ output_wiki = GollumOutput.new('wiki.git') # TODO make wiki_path an option
28
31
 
29
- output_wiki = GollumOutput.new('wiki.git')
30
-
32
+ # TODO ask if we should replace existing paths
33
+
31
34
  # commit page revisions to new wiki
35
+ output_wiki.commit_history @revisions, options
32
36
 
33
- output_wiki.commit_history @revisions
34
-
35
- # if wiki needs to convert sytax, do so
36
- if original_wiki.convert_syntax?
37
- puts "latest revisions:"
37
+ # if wiki needs to convert syntax, do so
38
+ puts "From markup: " + original_wiki.markup.to_s if options[:verbosity] == :verbose
39
+ puts "To markup: " + options[:markup].to_s if options[:verbosity] == :verbose
40
+ if original_wiki.convert_markup? options[:markup] # is wiki in target markup
41
+
42
+ puts "Latest revisions:" if options[:verbosity] == :verbose
38
43
  # take each latest revision
39
44
  for rev in original_wiki.latest_revisions
40
- puts "Updated syntax: #{rev.title} #{rev.time}"
45
+ puts "Updated syntax: #{rev.title} #{rev.time}" if options[:verbosity] == :verbose
46
+
41
47
  # parse markup & convert to new syntax
42
- body_new = original_wiki.convert2markdown rev.body
43
- unless body_new == rev.body
48
+ if options[:markup] == :markdown
49
+ body_new = original_wiki.to_markdown rev.body
50
+ else
51
+ body_new = original_wiki.to_textile rev.body
52
+ end
53
+
54
+ if body_new.start_with?('Einige interessante')
55
+ puts rev.body
56
+ puts body_new
57
+ end
58
+
59
+ unless body_new.eql? rev.body
44
60
  rev.body = body_new
45
- rev.author_name = "Caramelize"
61
+ rev.author_name = options[:markup]
46
62
  rev.time = Time.now
47
63
  rev.author = nil
48
64
 
49
65
  # commit as latest page revision
50
- output_wiki.commit_revision rev
66
+ output_wiki.commit_revision rev, options[:markup]
51
67
  end
52
68
  end
53
69
  end
54
- end
70
+ end # end execute
55
71
  end
56
72
  end
@@ -3,6 +3,10 @@
3
3
  module Caramelize
4
4
  class GollumOutput
5
5
 
6
+ def supported_markup
7
+ [:markdown, :textile]
8
+ end
9
+
6
10
  # Initialize a new gollum-wiki-repository at the given path.
7
11
  def initialize wiki_path
8
12
  # TODO use sanitized name as wiki-repository-title
@@ -11,12 +15,12 @@ module Caramelize
11
15
  end
12
16
 
13
17
  # Commit the given page into the gollum-wiki-repository.
14
- def commit_revision page
15
- gollum_page = @gollum.page(page.title)
18
+ # Make sure the target markup is correct before calling this method.
19
+ def commit_revision(page, markup)
16
20
  message = page.message.empty? ? "Edit in page #{page.title}" : page.message
17
-
21
+
18
22
  if page.author
19
- author = page.author
23
+ author = page.author
20
24
  else
21
25
  author = Author.new
22
26
  author.name = page.author_name
@@ -29,43 +33,26 @@ module Caramelize
29
33
  :authored_date => page.time,
30
34
  :committed_date => page.time
31
35
  }
36
+
37
+ gollum_page = @gollum.page(page.title)
32
38
  if gollum_page
33
39
  @gollum.update_page(gollum_page, gollum_page.name, gollum_page.format, page.body, commit)
34
40
  else
35
- # OPTIMIZE support not just markdown
36
- @gollum.write_page(page.title, :markdown, page.body, commit)
41
+ @gollum.write_page(page.title, markup, page.body, commit)
37
42
  end
38
43
  end
39
44
 
40
45
  # Commit all revisions of the given history into this gollum-wiki-repository.
41
- def commit_history revisions
46
+ def commit_history(revisions, options={})
47
+ options[:markup] = :markdown if options[:markup].nil? # target markup
42
48
  revisions.each_with_index do |page, index|
43
- puts "(#{index+1}/#{revisions.count}) #{page.time} #{page.title}"
44
-
45
- gollum_page = @gollum.page(page.title)
46
- message = page.message.empty? ? "Edit in page #{page.title}" : page.message
47
-
48
- if page.author
49
- author = page.author
50
- else
51
- author = Author.new
52
- author.name = page.author_name
53
- author.email = "mail@example.com"
49
+ if options[:verbosity] == :normal || options[:verbosity] == :verbose
50
+ puts "(#{index+1}/#{revisions.count}) #{page.time} #{page.title}"
54
51
  end
55
52
 
56
- commit = {:message => message,
57
- :name => author.name,
58
- :email => author.email,
59
- :authored_date => page.time,
60
- :committed_date => page.time
61
- }
62
- if gollum_page
63
- @gollum.update_page(gollum_page, gollum_page.name, gollum_page.format, page.body, commit)
64
- else
65
- # OPTIMIZE support not just markdown
66
- @gollum.write_page(page.title, :markdown, page.body, commit)
67
- end
53
+ commit_revision(page, options[:markup])
68
54
  end
69
55
  end
56
+
70
57
  end
71
58
  end
@@ -1,13 +1,13 @@
1
1
  module Caramelize
2
2
  class Page
3
3
 
4
- attr_accessor :title, :body, :id, :syntax, :latest, :time, :message, :author, :author_name
4
+ attr_accessor :title, :body, :id, :markup, :latest, :time, :message, :author, :author_name
5
5
 
6
6
  def initialize page={}
7
7
  @id = page[:id]
8
8
  @title = page[:title]
9
9
  @body = page[:body]
10
- @syntax = page[:syntax]
10
+ @syntax = page[:markup]
11
11
  @latest = page[:latest]
12
12
  @time = page[:time]
13
13
  @message = page[:message]
@@ -1,3 +1,3 @@
1
1
  module Caramelize
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,7 +1,6 @@
1
1
  #Encoding: UTF-8
2
2
  module Caramelize
3
3
  autoload :DatabaseConnector, 'caramelize/database_connector'
4
- autoload :Wikka2MarkdownConverter, 'caramelize/wikka2markdown_converter'
5
4
 
6
5
  class RedmineWiki < Wiki
7
6
  include DatabaseConnector
@@ -24,7 +23,7 @@ module Caramelize
24
23
  page = Page.new({:id => row_content["id"],
25
24
  :title => title,
26
25
  :body => row_content["data"],
27
- :syntax => 'textile',
26
+ :markup => :textile,
28
27
  :latest => false,
29
28
  :time => row_content["updated_on"],
30
29
  :message => row_content["comments"],
@@ -44,11 +43,6 @@ module Caramelize
44
43
  @revisions
45
44
  end
46
45
 
47
- def convert_syntax?
48
- # TODO
49
- false
50
- end
51
-
52
46
  def read_authors
53
47
  sql = "SELECT id, login, mail FROM users;"
54
48
  @authors = {}
@@ -0,0 +1,82 @@
1
+ module Caramelize
2
+ module TracConverter
3
+
4
+ # take an input stream and convert all wikka syntax to markdown syntax
5
+ # taken from 'trac_wiki_to_textile' at
6
+ def to_textile str
7
+ body = body.dup
8
+ body.gsub!(/\r/, '')
9
+ body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '@\1@')
10
+ body.gsub!(/\{\{\{\n#!([^\n]+?)(.+?)\}\}\}/m, '<pre><code class="\1">\2</code></pre>')
11
+ body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre>\1</pre>')
12
+ # macro
13
+ body.gsub!(/\[\[BR\]\]/, '')
14
+ body.gsub!(/\[\[PageOutline.*\]\]/, '{{toc}}')
15
+ body.gsub!(/\[\[Image\((.+?)\)\]\]/, '!\1!')
16
+ # header
17
+ body.gsub!(/=====\s(.+?)\s=====/, "h5. #{'\1'} \n\n")
18
+ body.gsub!(/====\s(.+?)\s====/, "h4. #{'\1'} \n\n")
19
+ body.gsub!(/===\s(.+?)\s===/, "h3. #{'\1'} \n\n")
20
+ body.gsub!(/==\s(.+?)\s==/, "h2. #{'\1'} \n\n")
21
+ body.gsub!(/=\s(.+?)\s=[\s\n]*/, "h1. #{'\1'} \n\n")
22
+ # table
23
+ body.gsub!(/\|\|/, "|")
24
+ # link
25
+ body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, ' "\2":\1' )
26
+ body.gsub!(/\[([^\s]+)\s(.+)\]/, ' [[\1 | \2]] ')
27
+ body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, ' \1[[\2]] ')
28
+ body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
29
+ # text decoration
30
+ body.gsub!(/'''(.+)'''/, '*\1*')
31
+ body.gsub!(/''(.+)''/, '_\1_')
32
+ body.gsub!(/`(.+)`/, '@\1@')
33
+ # itemize
34
+ body.gsub!(/^\s\s\s\*/, '***')
35
+ body.gsub!(/^\s\s\*/, '**')
36
+ body.gsub!(/^\s\*/, '*')
37
+ body.gsub!(/^\s\s\s\d\./, '###')
38
+ body.gsub!(/^\s\s\d\./, '##')
39
+ body.gsub!(/^\s\d\./, '#')
40
+ body
41
+ end
42
+
43
+ # TODO this is so far only copy of textile conversion
44
+ # not tested!
45
+ def to_markdown str
46
+ body = body.dup
47
+ body.gsub!(/\r/, '')
48
+ body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '@\1@')
49
+ body.gsub!(/\{\{\{\n#!([^\n]+?)(.+?)\}\}\}/m, '<pre><code class="\1">\2</code></pre>')
50
+ body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre>\1</pre>')
51
+ # macro
52
+ body.gsub!(/\[\[BR\]\]/, '')
53
+ body.gsub!(/\[\[PageOutline.*\]\]/, '{{toc}}')
54
+ body.gsub!(/\[\[Image\((.+?)\)\]\]/, '!\1!')
55
+ # header
56
+ body.gsub!(/=====\s(.+?)\s=====/, "== #{'\1'} ==\n\n")
57
+ body.gsub!(/====\s(.+?)\s====/, "=== #{'\1'} ===\n\n")
58
+ body.gsub!(/===\s(.+?)\s===/, "==== #{'\1'} ====\n\n")
59
+ body.gsub!(/==\s(.+?)\s==/, "===== #{'\1'} =====\n\n")
60
+ body.gsub!(/=\s(.+?)\s=[\s\n]*/, "====== #{'\1'} ======\n\n")
61
+ # table
62
+ body.gsub!(/\|\|/, "|")
63
+ # link
64
+ body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, ' "\2":\1' )
65
+ body.gsub!(/\[([^\s]+)\s(.+)\]/, ' [[\1 | \2]] ')
66
+ body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, ' \1[[\2]] ')
67
+ body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
68
+ # text decoration
69
+ body.gsub!(/'''(.+)'''/, '*\1*')
70
+ body.gsub!(/''(.+)''/, '_\1_')
71
+ body.gsub!(/`(.+)`/, '@\1@')
72
+ # itemize
73
+ body.gsub!(/^\s\s\s\*/, '***')
74
+ body.gsub!(/^\s\s\*/, '**')
75
+ body.gsub!(/^\s\*/, '*')
76
+ body.gsub!(/^\s\s\s\d\./, '###')
77
+ body.gsub!(/^\s\s\d\./, '##')
78
+ body.gsub!(/^\s\d\./, '#')
79
+ body
80
+ end
81
+ end
82
+ end
@@ -21,8 +21,8 @@ module Caramelize
21
21
  return []
22
22
  end
23
23
 
24
- def convert_syntax?
25
- @options[:syntax] == :markdown
24
+ def convert_markup? to_markup
25
+ markup != to_markup
26
26
  end
27
27
 
28
28
  def latest_revisions
@@ -33,5 +33,9 @@ module Caramelize
33
33
  end
34
34
  @latest_revisions
35
35
  end
36
+
37
+ def markup
38
+ @options[:markup]
39
+ end
36
40
  end
37
41
  end
@@ -0,0 +1,32 @@
1
+ module Caramelize
2
+ module WikkaConverter
3
+
4
+ # take an input stream and convert all wikka syntax to markdown syntax
5
+ def to_markdown 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
+
17
+ body.gsub!(/(.*?)(\n\t-)(.*?)/) {|s| $1 + '\n' + $3 } #list
18
+
19
+ body.gsub!(/(\t-)(.*?)/) {|s| '*' + $2 } #list
20
+ #str.gsub!(/(----)/) {|s| '~~~~'} #seperator
21
+
22
+
23
+ body.gsub!(/(\[\[)(\w+)\s(.+?)(\]\])/, '[[\3|\2]]')
24
+ #body.gsub!(/\[\[(\w+)\s(.+)\]\]/, ' [[\1 | \2]] ')
25
+
26
+
27
+ # TODO more syntax conversion for links and images
28
+
29
+ body
30
+ end
31
+ end
32
+ end
@@ -1,12 +1,17 @@
1
1
  #Encoding: UTF-8
2
2
  module Caramelize
3
3
  autoload :DatabaseConnector, 'caramelize/database_connector'
4
- autoload :Wikka2MarkdownConverter, 'caramelize/wikka2markdown_converter'
4
+ autoload :WikkaConverter, 'caramelize/wiki/wikka_converter'
5
5
 
6
6
  class WikkaWiki < Wiki
7
7
  include DatabaseConnector
8
- include Wikka2MarkdownConverter
8
+ include WikkaConverter
9
9
 
10
+ def initialize options={}
11
+ super(options)
12
+ options[:markup] = :wikka
13
+ end
14
+
10
15
  # after calling this action, I expect the @titles and @revisions to be filled
11
16
  def read_pages
12
17
  sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
@@ -19,7 +24,7 @@ module Caramelize
19
24
  page = Page.new({:id => row["id"],
20
25
  :title => row["tag"],
21
26
  :body => row["body"],
22
- :syntax => 'wikka',
27
+ :markup => :wikka,
23
28
  :latest => row["latest"] == "Y",
24
29
  :time => row["time"],
25
30
  :message => row["note"],
@@ -46,5 +51,5 @@ module Caramelize
46
51
  end
47
52
  @authors
48
53
  end
49
- end
54
+ end
50
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caramelize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql2
16
- requirement: &2156326680 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156326680
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: cmdparse
27
- requirement: &2156326200 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2156326200
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: gollum
38
- requirement: &2156325620 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: 1.3.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *2156325620
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
47
62
  description: By defining the access from the input to the output wiki you can migrate
48
63
  any wiki.
49
64
  email:
@@ -71,11 +86,12 @@ files:
71
86
  - lib/caramelize/ext.rb
72
87
  - lib/caramelize/gollum_output.rb
73
88
  - lib/caramelize/page.rb
74
- - lib/caramelize/redmine_wiki.rb
75
89
  - lib/caramelize/version.rb
76
- - lib/caramelize/wiki.rb
77
- - lib/caramelize/wikka2markdown_converter.rb
78
- - lib/caramelize/wikkawiki.rb
90
+ - lib/caramelize/wiki/redmine_wiki.rb
91
+ - lib/caramelize/wiki/trac_converter.rb
92
+ - lib/caramelize/wiki/wiki.rb
93
+ - lib/caramelize/wiki/wikka_converter.rb
94
+ - lib/caramelize/wiki/wikkawiki.rb
79
95
  - test/helper.rb
80
96
  - test/test_caramelize.rb
81
97
  homepage: http://github.com/Dahie/caramelize
@@ -99,10 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
115
  version: '0'
100
116
  requirements: []
101
117
  rubyforge_project: caramelize
102
- rubygems_version: 1.8.10
118
+ rubygems_version: 1.8.21
103
119
  signing_key:
104
120
  specification_version: 3
105
121
  summary: Abstract wiki convert to migrate your data from one wiki software to another
106
122
  test_files:
107
123
  - test/helper.rb
108
124
  - test/test_caramelize.rb
125
+ has_rdoc:
@@ -1,27 +0,0 @@
1
- module Caramelize
2
- module Wikka2MarkdownConverter
3
-
4
- # take an input stream and convert all wikka syntax to markdown syntax
5
- def convert2markdown str
6
- str.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
7
- str.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2
8
- str.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3
9
- str.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4
10
-
11
- str.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold
12
- str.gsub!(/(\/\/)(.*?)(\/\/)/) {|s| '_' + $2 + '_' } #italic
13
- #str.gsub!(/(===)(.*?)(===)/) {|s| '`' + $2 + '`'} #code
14
- str.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline
15
-
16
- #str.gsub!(/(.*?)(\n\t-)(.*?)/) {|s| $1 + '\n' + $3 } #list
17
-
18
- str.gsub!(/(\t-)(.*?)/) {|s| '*' + $2 } #list
19
- #str.gsub!(/(----)/) {|s| '~~~~'} #seperator
20
-
21
-
22
- # TODO more syntax conversion for links and images
23
-
24
- str
25
- end
26
- end
27
- end