class Jekyll::Commands::Import

Constants

IMPORTERS

Public Class Methods

abort_on_invalid_migrator(migrator) click to toggle source
# File lib/jekyll/commands/import.rb, line 65
def abort_on_invalid_migrator(migrator)
  warn "Sorry, '#{migrator}' isn't a valid migrator. Valid choices:"
  IMPORTERS.each_key { |k| warn "* #{k}" }
  raise "'#{migrator}' is not a valid migrator."
end
init_with_program(prog) click to toggle source
# File lib/jekyll/commands/import.rb, line 32
def init_with_program(prog)
  prog.command(:import) do |c|
    c.syntax "import <platform> [options]"
    c.description "Import your old blog to Jekyll"
    importers = JekyllImport.add_importer_commands(c)

    c.action do |args, _options|
      if args.empty?
        Jekyll.logger.warn "You must specify an importer."
        Jekyll.logger.info "Valid options are:"
        importers.sort.each { |i| Jekyll.logger.info "*", i.to_s }
      end
    end
  end
end
process(migrator, options) click to toggle source
# File lib/jekyll/commands/import.rb, line 48
def process(migrator, options)
  migrator = migrator.to_s.downcase

  if IMPORTERS.key?(migrator.to_sym)
    if JekyllImport::Importers.const_defined?(IMPORTERS[migrator.to_sym])
      klass = JekyllImport::Importers.const_get(IMPORTERS[migrator.to_sym])
      if options.respond_to?(:__hash__)
        klass.run(options.__hash__)
      else
        klass.run(options)
      end
    end
  else
    abort_on_invalid_migrator(migrator)
  end
end