Class: Jekyll::Commands::Import

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll/commands/import.rb

Constant Summary collapse

IMPORTERS =
{
  :blogger => 'Blogger',
  :behance => 'Behance',
  :csv => 'CSV',
  :drupal6 => 'Drupal6',
  :drupal7 => 'Drupal7',
  :enki => 'Enki',
  :joomla => 'Joomla',
  :joomla3 => 'Joomla3',
  :jrnl => 'Jrnl',
  :ghost => 'Ghost',
  :google_reader => 'GoogleReader',
  :marley => 'Marley',
  :mephisto => 'Mephisto',
  :mt => 'MT',
  :posterous => 'Posterous',
  :rss => 'RSS',
  :s9y => 'S9Y',
  :textpattern => 'TextPattern',
  :tumblr => 'Tumblr',
  :typo => 'Typo',
  :wordpress => 'WordPress',
  :wordpressdotcom => 'WordpressDotCom'
}

Class Method Summary collapse

Class Method Details

.abort_on_invalid_migrator(migrator) ⇒ Object

Raises:

  • (RuntimeError)


69
70
71
72
73
# File 'lib/jekyll/commands/import.rb', line 69

def abort_on_invalid_migrator(migrator)
  $stderr.puts "Sorry, '#{migrator}' isn't a valid migrator. Valid choices:"
  IMPORTERS.keys.each { |k| $stderr.puts "* #{k}" }
  raise RuntimeError.new("'#{migrator}' is not a valid migrator.")
end

.init_with_program(prog) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/commands/import.rb', line 36

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.each { |i| Jekyll.logger.info "*", "#{i}" }
      end
    end
  end
end

.process(migrator, options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jekyll/commands/import.rb', line 52

def process(migrator, options)
  migrator = migrator.to_s.downcase

  if IMPORTERS.keys.include?(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