class Caramelize::ContentTransferer

Constants

DEFAULT_AUTHOR_EMAIL
DEFAULT_AUTHOR_NAME
DEFAULT_GOLLUM_HOME_TITLE

Attributes

input_wiki[R]
options[R]

Public Class Methods

new(input_wiki, options) click to toggle source
# File lib/caramelize/content_transferer.rb, line 20
def initialize(input_wiki, options)
  @input_wiki = input_wiki
  @options = options

  options[:default_author] = options.fetch(:default_author, 'Caramelize')
  options[:markup] = target_markup
end

Public Instance Methods

execute() click to toggle source
# File lib/caramelize/content_transferer.rb, line 28
def execute
  input_wiki.read_authors
  commit_history
  print_meta_data if verbose?

  migrate_markup_of_latest_revisions

  create_overview_page_of_namespaces if options[:create_namespace_overview]

  rename_home_page if options[:home_page_title]
end

Private Instance Methods

build_revision_metadata(revision, body_new) click to toggle source
# File lib/caramelize/content_transferer.rb, line 152
def build_revision_metadata(revision, body_new)
  revision.body = body_new
  revision.author = { name: DEFAULT_AUTHOR_NAME, email: DEFAULT_AUTHOR_EMAIL }
  revision.time = Time.zone.now

  revision
end
commit_as_latest_page(revision) click to toggle source
# File lib/caramelize/content_transferer.rb, line 148
def commit_as_latest_page(revision)
  output_wiki.commit_revision(build_revision_metadata(revision, body_new), options[:markup])
end
commit_history() click to toggle source
# File lib/caramelize/content_transferer.rb, line 104
def commit_history
  output_wiki.commit_history(revisions, options) do |page, index|
    commit_page(page, index)
  end
end
commit_history_progress_bar() click to toggle source
# File lib/caramelize/content_transferer.rb, line 91
def commit_history_progress_bar
  @commit_history_progress_bar ||=
    ProgressBar.create(title: 'Revisions',
                       total: revisions_count)
end
commit_page(page, index) click to toggle source
# File lib/caramelize/content_transferer.rb, line 110
def commit_page(page, index)
  if input_wiki.excluded_pages.include?(page.title)
    puts "Exclude Page: #{page.title}" if verbose?
    return
  end

  if verbose?
    puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
  else
    commit_history_progress_bar.increment
  end
end
convert_markup_of_revision(revision) click to toggle source
# File lib/caramelize/content_transferer.rb, line 133
def convert_markup_of_revision(revision)
  if input_wiki.excluded_pages.include?(revision.title)
    puts "Exclude Page: #{revision.title}" if verbose?
    return
  end

  if verbose?
    puts "Filter source: #{revision.title} #{revision.time}"
  else
    migrate_markup_progress_bar.increment
  end

  run_filter_processor_on_revision(revision)
end
create_overview_page_of_namespaces() click to toggle source
# File lib/caramelize/content_transferer.rb, line 80
def create_overview_page_of_namespaces
  puts 'Create Namespace Overview' if verbose?
  output_wiki.commit_namespace_overview(input_wiki.namespaces)
end
filter_processor() click to toggle source
# File lib/caramelize/content_transferer.rb, line 64
def filter_processor
  @filter_processor ||= FilterProcessor.new(input_wiki)
end
latest_revisions_count() click to toggle source
# File lib/caramelize/content_transferer.rb, line 76
def latest_revisions_count
  input_wiki.latest_revisions.count
end
migrate_markup_of_latest_revisions() click to toggle source
# File lib/caramelize/content_transferer.rb, line 97
def migrate_markup_of_latest_revisions
  puts 'Convert latest revisions:' if verbose?
  input_wiki.latest_revisions.each do |revision|
    convert_markup_of_revision(revision)
  end
end
migrate_markup_progress_bar() click to toggle source
# File lib/caramelize/content_transferer.rb, line 85
def migrate_markup_progress_bar
  @migrate_markup_progress_bar ||=
    ProgressBar.create(title: 'Markup filters',
                       total: latest_revisions_count)
end
needs_conversion_to_target_markup?() click to toggle source
# File lib/caramelize/content_transferer.rb, line 52
def needs_conversion_to_target_markup?
  output_wiki.supported_markup.index(input_wiki.markup)
end
output_wiki() click to toggle source
# File lib/caramelize/content_transferer.rb, line 60
def output_wiki
  @output_wiki ||= OutputWiki::Gollum.new(options[:target])
end
print_meta_data() click to toggle source
rename_home_page() click to toggle source
# File lib/caramelize/content_transferer.rb, line 160
def rename_home_page
  puts "Rename page #{options[:home_page_title]} to #{DEFAULT_GOLLUM_HOME_TITLE}" if verbose?
  output_wiki.rename_page(options[:home_page_title], DEFAULT_GOLLUM_HOME_TITLE)
end
revisions() click to toggle source
# File lib/caramelize/content_transferer.rb, line 56
def revisions
  @revisions ||= input_wiki.read_pages
end
revisions_count() click to toggle source
# File lib/caramelize/content_transferer.rb, line 72
def revisions_count
  revisions.count
end
run_filter_processor_on_revision(revision) click to toggle source
# File lib/caramelize/content_transferer.rb, line 123
def run_filter_processor_on_revision(revision)
  body_new = filter_processor.run(revision.body)

  return if body_new == revision.body

  revision.message = "Markup of '#{revision.title}' converted to #{target_markup}"

  commit_as_latest_page(revision)
end
target_markup() click to toggle source
# File lib/caramelize/content_transferer.rb, line 47
def target_markup
  @target_markup ||=
    needs_conversion_to_target_markup? ? input_wiki.markup : :markdown
end
verbose?() click to toggle source
# File lib/caramelize/content_transferer.rb, line 68
def verbose?
  options[:verbose]
end