lib/caramelize/content_transferer.rb in caramelize-0.4.0 vs lib/caramelize/content_transferer.rb in caramelize-1.0.0

- old
+ new

@@ -1,28 +1,26 @@ -require 'gollum-lib' -require 'grit' require 'ruby-progressbar' module Caramelize require 'caramelize/page' - require 'caramelize/ext' require 'caramelize/content_transferer' require 'caramelize/database_connector' require 'caramelize/output_wiki/gollum' require 'caramelize/input_wiki/redmine_wiki' require 'caramelize/input_wiki/wikkawiki' class ContentTransferer attr_reader :input_wiki, :options, :filter_processor + DEFAULT_GOLLUM_HOME_TITLE = 'Home'.freeze + def initialize(input_wiki, options) @input_wiki = input_wiki @options = options options[:default_author] = options.fetch(:default_author, "Caramelize") - options[:target_directory] = './wiki-export' options[:markup] = target_markup end def execute input_wiki.read_authors @@ -37,10 +35,12 @@ migrate_markup_of_latest_revisions puts 'Create Namespace Overview' if verbose? create_overview_page_of_namespaces if options[:create_namespace_overview] + + rename_home_page end private def target_markup @@ -55,11 +55,11 @@ def revisions @revisions ||= input_wiki.read_pages end def output_wiki - @output_wiki ||= OutputWiki::Gollum.new(options[:target_directory]) + @output_wiki ||= OutputWiki::Gollum.new(options[:target]) end def filter_processor @filter_processor ||= FilterProcessor.new(input_wiki) end @@ -70,53 +70,67 @@ def revisions_count revisions.count end + def latest_revisions_count + input_wiki.latest_revisions.count + end + def create_overview_page_of_namespaces output_wiki.commit_namespace_overview(input_wiki.namespaces) end - def migrate_markup_of_latest_revisions - progress_bar = ProgressBar.create(title: "Markup filters", - total: revisions_count) + def migrate_markup_progress_bar + @migrate_markup_progress_bar ||= + ProgressBar.create(title: "Markup filters", + total: latest_revisions_count) + end + def commit_history_progress_bar + @commit_history_progress_bar ||= + ProgressBar.create(title: "Revisions", + total: revisions_count) + end + + def migrate_markup_of_latest_revisions input_wiki.latest_revisions.each do |revision| - migrate_markup_of_revision(revision, progress_bar) + migrate_markup_of_revision(revision) end end def commit_history - puts revisions_count - progress_bar = ProgressBar.create(title: "Revisions", - total: revisions_count) - output_wiki.commit_history(revisions, options) do |page, index| if verbose? puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}" else - progress_bar.increment + commit_history_progress_bar.increment end end end - def migrate_markup_of_revision(revision, progress_bar) + def migrate_markup_of_revision(revision) if verbose? puts "Filter source: #{revision.title} #{revision.time}" else - progress_bar.increment + migrate_markup_progress_bar.increment end body_new = filter_processor.run(revision.body) unless body_new == revision.body revision.body = body_new - revision.author_name = target_markup + revision.author_name = 'Caramelize' revision.time = Time.now revision.author = nil + revision.message = "Markup of '#{revision.title}' converted to #{target_markup}" # commit as latest page revision output_wiki.commit_revision(revision, options[:markup]) end + end + + def rename_home_page + output_wiki.rename_page(options[:home_page_title], DEFAULT_GOLLUM_HOME_TITLE) end end end