lib/caramelize/content_transferer.rb in caramelize-0.0.3 vs lib/caramelize/content_transferer.rb in caramelize-0.1.0

- old
+ new

@@ -2,55 +2,71 @@ require 'gollum' require 'grit' module Caramelize - autoload :Wiki, 'caramelize/wiki' - autoload :WikkaWiki, 'caramelize/wikkawiki' - autoload :RedmineWiki, 'caramelize/redmine_wiki' + autoload :Wiki, 'caramelize/wiki/wiki' + autoload :WikkaWiki, 'caramelize/wiki/wikkawiki' + autoload :RedmineWiki, 'caramelize/wiki/redmine_wiki' autoload :GollumOutput, 'caramelize/gollum_output' - autoload :Wikka2MarkdownConverter, 'wikka2markdown_converter' autoload :Author, 'caramelize/author' autoload :Page, 'caramelize/page' # Controller for the content migration class ContentTransferer # Execute the content migration - def self.execute original_wiki, options={} + def self.execute(original_wiki, options={}) + options[:markup] = :markdown if !options[:markup] + options[:default_author] = "Caramelize" if !options[:default_author] + # read page revisions from wiki # store page revisions original_wiki.read_authors @revisions = original_wiki.read_pages # initiate new wiki + output_wiki = GollumOutput.new('wiki.git') # TODO make wiki_path an option - output_wiki = GollumOutput.new('wiki.git') - + # TODO ask if we should replace existing paths + # commit page revisions to new wiki + output_wiki.commit_history @revisions, options - output_wiki.commit_history @revisions - - # if wiki needs to convert sytax, do so - if original_wiki.convert_syntax? - puts "latest revisions:" + # if wiki needs to convert syntax, do so + puts "From markup: " + original_wiki.markup.to_s if options[:verbosity] == :verbose + puts "To markup: " + options[:markup].to_s if options[:verbosity] == :verbose + if original_wiki.convert_markup? options[:markup] # is wiki in target markup + + puts "Latest revisions:" if options[:verbosity] == :verbose # take each latest revision for rev in original_wiki.latest_revisions - puts "Updated syntax: #{rev.title} #{rev.time}" + puts "Updated syntax: #{rev.title} #{rev.time}" if options[:verbosity] == :verbose + # parse markup & convert to new syntax - body_new = original_wiki.convert2markdown rev.body - unless body_new == rev.body + if options[:markup] == :markdown + body_new = original_wiki.to_markdown rev.body + else + body_new = original_wiki.to_textile rev.body + end + + if body_new.start_with?('Einige interessante') + puts rev.body + puts body_new + end + + unless body_new.eql? rev.body rev.body = body_new - rev.author_name = "Caramelize" + rev.author_name = options[:markup] rev.time = Time.now rev.author = nil # commit as latest page revision - output_wiki.commit_revision rev + output_wiki.commit_revision rev, options[:markup] end end end - end + end # end execute end end \ No newline at end of file