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|
|
||||
options.defaults :serving => false
|
||||
options = Jekyll.configuration(options.__hash__)
|
||||
Jekyll::BuildCommand.process(options)
|
||||
Jekyll::Commands::Build.process(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,8 +49,8 @@ command :serve do |c|
|
|||
:serving => true
|
||||
|
||||
options = Jekyll.configuration(options.__hash__)
|
||||
Jekyll::BuildCommand.process(options)
|
||||
Jekyll::ServeCommand.process(options)
|
||||
Jekyll::Commands::Build.process(options)
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,6 +65,6 @@ command :import do |c|
|
|||
c.option '--host', 'Host address to use when migrating'
|
||||
|
||||
c.action do |args, options|
|
||||
Jekyll::MigrateCommand.process(args.first, options)
|
||||
Jekyll::Commands::Migrate.process(args.first, options)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,76 +1,76 @@
|
|||
module Jekyll
|
||||
module Commands
|
||||
class Build < Command
|
||||
def self.process(options)
|
||||
site = Jekyll::Site.new(options)
|
||||
|
||||
class BuildCommand < Command
|
||||
def self.process(options)
|
||||
site = Jekyll::Site.new(options)
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
|
||||
if options['watch']
|
||||
self.watch(site, options)
|
||||
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
|
||||
if options['watch']
|
||||
self.watch(site, options)
|
||||
else
|
||||
self.build(site, options)
|
||||
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']
|
||||
trap("INT") do
|
||||
puts "Stopping auto-regeneration..."
|
||||
exit 0
|
||||
# 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
|
||||
|
||||
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
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
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
|
||||
MIGRATORS = {
|
||||
:csv => 'CSV',
|
||||
: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)
|
||||
abort 'missing argument. Please specify a migrator' if migrator.nil?
|
||||
migrator = migrator.downcase
|
||||
|
||||
def self.process(migrator, options)
|
||||
abort 'missing argument. Please specify a migrator' if migrator.nil?
|
||||
migrator = migrator.downcase
|
||||
|
||||
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
|
||||
cmd_options = []
|
||||
[ :file, :dbname, :user, :pass, :host, :site ].each do |p|
|
||||
cmd_options << "\"#{options[p]}\"" unless options[p].nil?
|
||||
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
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
module Jekyll
|
||||
module Commands
|
||||
class Serve < Command
|
||||
def self.process(options)
|
||||
require 'webrick'
|
||||
include WEBrick
|
||||
|
||||
class ServeCommand < Command
|
||||
def self.process(options)
|
||||
require 'webrick'
|
||||
include WEBrick
|
||||
destination = options['destination']
|
||||
|
||||
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
|
||||
mime_types.store 'js', 'application/javascript'
|
||||
s = HTTPServer.new(
|
||||
:Port => options['port'],
|
||||
:BindAddress => options['host'],
|
||||
:MimeTypes => mime_types
|
||||
)
|
||||
|
||||
s = HTTPServer.new(
|
||||
:Port => options['port'],
|
||||
:BindAddress => options['host'],
|
||||
:MimeTypes => mime_types
|
||||
)
|
||||
|
||||
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
|
||||
t = Thread.new { s.start }
|
||||
trap("INT") { s.shutdown }
|
||||
t.join()
|
||||
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
|
||||
t = Thread.new { s.start }
|
||||
trap("INT") { s.shutdown }
|
||||
t.join()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue