lib/guard/jekyll-plus.rb in guard-jekyll-plus-1.3.0 vs lib/guard/jekyll-plus.rb in guard-jekyll-plus-1.4.0

- old
+ new

@@ -2,28 +2,35 @@ require 'guard' require 'guard/guard' require 'jekyll' +#begin require 'thin' rescue false end +begin + require 'rack' + USE_RACK = true +rescue LoadError +end module Guard class Jekyllplus < Guard def initialize (watchers=[], options={}) super default_extensions = ['md','mkd','mkdn','markdown','textile','html','haml','slim','xml','yml'] @options = { - :extensions => [], - :config => ['_config.yml'], - :serve => false, - :drafts => false, - :future => false, - :config_hash => nil, - :silent => false, - :msg_prefix => 'Jekyll' + :extensions => [], + :config => ['_config.yml'], + :serve => false, + :rack_config => nil, + :drafts => false, + :future => false, + :config_hash => nil, + :silent => false, + :msg_prefix => 'Jekyll' }.merge(options) # The config_hash option should be a hash ready to be consumed by Jekyll's Site class. # @config = jekyll_config(@options) @@ -49,10 +56,12 @@ @pid = nil # Create a Jekyll site # @site = ::Jekyll::Site.new @config + @rack = ::Rack::Server.new(rack_config) if USE_RACK + puts @rack end def start if @options[:serve] @@ -197,17 +206,24 @@ def jekyll_config(options) if options[:config_hash] config = options[:config_hash] elsif options[:config] - config_files = options[:config] - config_files = [config_files] unless config_files.is_a? Array - config = { "config" => config_files} + options[:config] = [options[:config]] unless options[:config].is_a? Array + config = options end ::Jekyll.configuration(config) end + def rack_config + default_config = File.expand_path("../rack/config.ru", File.dirname(__FILE__)) + local_config = File.exist? 'config.ru' ? 'config.ru' : nil + config = (@config['rack_config'] || local_config || default_config) + puts config + { :config => config, :Port => @config['port'], :Host => @config['host'] } + end + def local_path(path) Dir.chdir('.') current = Dir.pwd path = path.sub current, '' if path == '' @@ -229,11 +245,15 @@ def ignore_underscores(paths) paths.select { |file| file =~ /^[^_]/ } end def server(config) - proc{ Process.fork { ::Jekyll::Commands::Serve.process(config) } } + if @rack + proc{ Process.fork { @rack.start } } + else + proc{ Process.fork { ::Jekyll::Commands::Serve.process(config) } } + end end def kill proc{|pid| Process.kill("QUIT", pid)} end @@ -242,9 +262,10 @@ return @pid if alive? @pid = instance_eval &server(@config) end def stop_server + #@rack.stop if @rack if alive? instance_eval do kill.call(@pid) @pid = nil end