Update command classes moving into a module
This commit is contained in:
parent
065b251383
commit
e03f48085a
|
@ -27,7 +27,7 @@ command :build do |c|
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
options.defaults :serving => false
|
options.defaults :serving => false
|
||||||
options = Jekyll.configuration(options.__hash__)
|
options = Jekyll.configuration(options.__hash__)
|
||||||
Jekyll::BuildCommand.process(options)
|
Jekyll::Commands::Build.process(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ command :serve do |c|
|
||||||
:serving => true
|
:serving => true
|
||||||
|
|
||||||
options = Jekyll.configuration(options.__hash__)
|
options = Jekyll.configuration(options.__hash__)
|
||||||
Jekyll::BuildCommand.process(options)
|
Jekyll::Commands::Build.process(options)
|
||||||
Jekyll::ServeCommand.process(options)
|
Jekyll::Commands::Serve.process(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +65,6 @@ command :import do |c|
|
||||||
c.option '--host', 'Host address to use when migrating'
|
c.option '--host', 'Host address to use when migrating'
|
||||||
|
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
Jekyll::MigrateCommand.process(args.first, options)
|
Jekyll::Commands::Migrate.process(args.first, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,76 +1,76 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
module Commands
|
||||||
|
class Build < Command
|
||||||
|
def self.process(options)
|
||||||
|
site = Jekyll::Site.new(options)
|
||||||
|
|
||||||
class BuildCommand < Command
|
source = options['source']
|
||||||
def self.process(options)
|
destination = options['destination']
|
||||||
site = Jekyll::Site.new(options)
|
|
||||||
|
|
||||||
source = options['source']
|
if options['watch']
|
||||||
destination = options['destination']
|
self.watch(site, options)
|
||||||
|
else
|
||||||
if options['watch']
|
self.build(site, options)
|
||||||
self.watch(site, options)
|
end
|
||||||
else
|
|
||||||
self.build(site, options)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Private: Build the site from source into destination.
|
|
||||||
#
|
|
||||||
# site - A Jekyll::Site instance
|
|
||||||
# options - A Hash of options passed to the command
|
|
||||||
#
|
|
||||||
# Returns nothing.
|
|
||||||
def self.build(site, options)
|
|
||||||
source = options['source']
|
|
||||||
destination = options['destination']
|
|
||||||
puts "Building site: #{source} -> #{destination}"
|
|
||||||
begin
|
|
||||||
site.process
|
|
||||||
rescue Jekyll::FatalException => e
|
|
||||||
puts
|
|
||||||
puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
|
|
||||||
puts "------------------------------------"
|
|
||||||
puts e.message
|
|
||||||
exit(1)
|
|
||||||
end
|
|
||||||
puts "Successfully generated site: #{source} -> #{destination}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Private: Watch for file changes and rebuild the site.
|
|
||||||
#
|
|
||||||
# site - A Jekyll::Site instance
|
|
||||||
# options - A Hash of options passed to the command
|
|
||||||
#
|
|
||||||
# Returns nothing.
|
|
||||||
def self.watch(site, options)
|
|
||||||
require 'directory_watcher'
|
|
||||||
|
|
||||||
source = options['source']
|
|
||||||
destination = options['destination']
|
|
||||||
|
|
||||||
puts "Auto-Regenerating enabled: #{source} -> #{destination}"
|
|
||||||
|
|
||||||
dw = DirectoryWatcher.new(source)
|
|
||||||
dw.interval = 1
|
|
||||||
dw.glob = self.globs(source)
|
|
||||||
|
|
||||||
dw.add_observer do |*args|
|
|
||||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
puts "[#{t}] regeneration: #{args.size} files changed"
|
|
||||||
site.process
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dw.start
|
# Private: Build the site from source into destination.
|
||||||
|
#
|
||||||
|
# site - A Jekyll::Site instance
|
||||||
|
# options - A Hash of options passed to the command
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
def self.build(site, options)
|
||||||
|
source = options['source']
|
||||||
|
destination = options['destination']
|
||||||
|
puts "Building site: #{source} -> #{destination}"
|
||||||
|
begin
|
||||||
|
site.process
|
||||||
|
rescue Jekyll::FatalException => e
|
||||||
|
puts
|
||||||
|
puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
|
||||||
|
puts "------------------------------------"
|
||||||
|
puts e.message
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
puts "Successfully generated site: #{source} -> #{destination}"
|
||||||
|
end
|
||||||
|
|
||||||
unless options['serving']
|
# Private: Watch for file changes and rebuild the site.
|
||||||
trap("INT") do
|
#
|
||||||
puts "Stopping auto-regeneration..."
|
# site - A Jekyll::Site instance
|
||||||
exit 0
|
# options - A Hash of options passed to the command
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
def self.watch(site, options)
|
||||||
|
require 'directory_watcher'
|
||||||
|
|
||||||
|
source = options['source']
|
||||||
|
destination = options['destination']
|
||||||
|
|
||||||
|
puts "Auto-Regenerating enabled: #{source} -> #{destination}"
|
||||||
|
|
||||||
|
dw = DirectoryWatcher.new(source)
|
||||||
|
dw.interval = 1
|
||||||
|
dw.glob = self.globs(source)
|
||||||
|
|
||||||
|
dw.add_observer do |*args|
|
||||||
|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
puts "[#{t}] regeneration: #{args.size} files changed"
|
||||||
|
site.process
|
||||||
end
|
end
|
||||||
|
|
||||||
loop { sleep 1000 }
|
dw.start
|
||||||
|
|
||||||
|
unless options['serving']
|
||||||
|
trap("INT") do
|
||||||
|
puts "Stopping auto-regeneration..."
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
loop { sleep 1000 }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
module Commands
|
||||||
|
class Migrate < Command
|
||||||
|
MIGRATORS = {
|
||||||
|
:csv => 'CSV',
|
||||||
|
:drupal => 'Drupal',
|
||||||
|
:enki => 'Enki',
|
||||||
|
:mephisto => 'Mephisto',
|
||||||
|
:mt => 'MT',
|
||||||
|
:posterous => 'Posterous',
|
||||||
|
:textpattern => 'TextPattern',
|
||||||
|
:tumblr => 'Tumblr',
|
||||||
|
:typo => 'Typo',
|
||||||
|
:wordpressdotcom => 'WordpressDotCom',
|
||||||
|
:wordpress => 'WordPress'
|
||||||
|
}
|
||||||
|
|
||||||
class MigrateCommand < Command
|
def self.process(migrator, options)
|
||||||
MIGRATORS = {
|
abort 'missing argument. Please specify a migrator' if migrator.nil?
|
||||||
:csv => 'CSV',
|
migrator = migrator.downcase
|
||||||
:drupal => 'Drupal',
|
|
||||||
:enki => 'Enki',
|
|
||||||
:mephisto => 'Mephisto',
|
|
||||||
:mt => 'MT',
|
|
||||||
:posterous => 'Posterous',
|
|
||||||
:textpattern => 'TextPattern',
|
|
||||||
:tumblr => 'Tumblr',
|
|
||||||
:typo => 'Typo',
|
|
||||||
:wordpressdotcom => 'WordpressDotCom',
|
|
||||||
:wordpress => 'WordPress'
|
|
||||||
}
|
|
||||||
|
|
||||||
def self.process(migrator, options)
|
cmd_options = []
|
||||||
abort 'missing argument. Please specify a migrator' if migrator.nil?
|
[ :file, :dbname, :user, :pass, :host, :site ].each do |p|
|
||||||
migrator = migrator.downcase
|
cmd_options << "\"#{options[p]}\"" unless options[p].nil?
|
||||||
|
|
||||||
cmd_options = []
|
|
||||||
[ :file, :dbname, :user, :pass, :host, :site ].each do |p|
|
|
||||||
cmd_options << "\"#{options[p]}\"" unless options[p].nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
if MIGRATORS.keys.include?(migrator)
|
|
||||||
app_root = File.expand_path(
|
|
||||||
File.join(File.dirname(__FILE__), '..', '..', '..')
|
|
||||||
)
|
|
||||||
|
|
||||||
require "#{app_root}/lib/jekyll/migrators/#{migrator}"
|
|
||||||
|
|
||||||
if Jekyll.const_defiend?(MIGRATORS[migrator.to_sym])
|
|
||||||
puts 'Importing...'
|
|
||||||
migrator_class = Jekyll.const_get(MIGRATORS[migrator.to_sym])
|
|
||||||
migrator_class.process(*cmd_options)
|
|
||||||
exit 0
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
abort 'invalid migrator. Please specify a valid migrator'
|
|
||||||
|
if MIGRATORS.keys.include?(migrator)
|
||||||
|
app_root = File.expand_path(
|
||||||
|
File.join(File.dirname(__FILE__), '..', '..', '..')
|
||||||
|
)
|
||||||
|
|
||||||
|
require "#{app_root}/lib/jekyll/migrators/#{migrator}"
|
||||||
|
|
||||||
|
if Jekyll.const_defiend?(MIGRATORS[migrator.to_sym])
|
||||||
|
puts 'Importing...'
|
||||||
|
migrator_class = Jekyll.const_get(MIGRATORS[migrator.to_sym])
|
||||||
|
migrator_class.process(*cmd_options)
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
abort 'invalid migrator. Please specify a valid migrator'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
module Commands
|
||||||
|
class Serve < Command
|
||||||
|
def self.process(options)
|
||||||
|
require 'webrick'
|
||||||
|
include WEBrick
|
||||||
|
|
||||||
class ServeCommand < Command
|
destination = options['destination']
|
||||||
def self.process(options)
|
|
||||||
require 'webrick'
|
|
||||||
include WEBrick
|
|
||||||
|
|
||||||
destination = options['destination']
|
FileUtils.mkdir_p(destination)
|
||||||
|
|
||||||
FileUtils.mkdir_p(destination)
|
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
|
||||||
|
mime_types.store 'js', 'application/javascript'
|
||||||
|
|
||||||
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
|
s = HTTPServer.new(
|
||||||
mime_types.store 'js', 'application/javascript'
|
:Port => options['port'],
|
||||||
|
:BindAddress => options['host'],
|
||||||
|
:MimeTypes => mime_types
|
||||||
|
)
|
||||||
|
|
||||||
s = HTTPServer.new(
|
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
|
||||||
:Port => options['port'],
|
t = Thread.new { s.start }
|
||||||
:BindAddress => options['host'],
|
trap("INT") { s.shutdown }
|
||||||
:MimeTypes => mime_types
|
t.join()
|
||||||
)
|
end
|
||||||
|
|
||||||
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
|
|
||||||
t = Thread.new { s.start }
|
|
||||||
trap("INT") { s.shutdown }
|
|
||||||
t.join()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue