diff --git a/bin/jekyll b/bin/jekyll index 060c9125..3f2988bc 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -6,12 +6,9 @@ $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib }) require 'jekyll' require 'mercenary' -%w[jekyll-import].each do |blessed_gem| - begin - require blessed_gem - rescue LoadError - end -end +Jekyll::External.require_if_present( + Jekyll::External.blessed_gems +) Jekyll::PluginManager.require_from_bundler diff --git a/lib/jekyll/commands/docs.rb b/lib/jekyll/commands/docs.rb deleted file mode 100644 index 71c10160..00000000 --- a/lib/jekyll/commands/docs.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Jekyll - module Commands - class Docs < Command - - class << self - - def init_with_program(prog) - prog.command(:docs) do |c| - c.syntax 'docs' - c.description "Launch local server with docs for Jekyll v#{Jekyll::VERSION}" - - c.option 'port', '-P', '--port [PORT]', 'Port to listen on' - c.option 'host', '-H', '--host [HOST]', 'Host to bind to' - - c.action do |args, options| - options.merge!({ - 'source' => File.expand_path("../../../site", File.dirname(__FILE__)), - 'destination' => File.expand_path("../../../site/_site", File.dirname(__FILE__)) - }) - Jekyll::Commands::Build.process(options) - Jekyll::Commands::Serve.process(options) - end - end - end - - end - - end - end -end diff --git a/lib/jekyll/external.rb b/lib/jekyll/external.rb new file mode 100644 index 00000000..e41bce27 --- /dev/null +++ b/lib/jekyll/external.rb @@ -0,0 +1,59 @@ +module Jekyll + module External + class << self + + # + # Gems that, if installed, should be loaded. + # Usually contain subcommands. + # + def blessed_gems + %w{ + jekyll-docs + jekyll-import + } + end + + # + # Require a gem or file if it's present, otherwise silently fail. + # + # names - a string gem name or array of gem names + # + def require_if_present(names) + Array(names).each do |name| + begin + require name + rescue LoadError + Jekyll.logger.debug "Couldn't load #{name}. Skipping." + false + end + end + end + + # + # Require a gem or gems. If it's not present, show a very nice error + # message that explains everything and is much more helpful than the + # normal LoadError. + # + # names - a string gem name or array of gem names + # + def require_with_graceful_fail(names) + Array(names).each do |name| + begin + require name + rescue LoadError => e + Jekyll.logger.error "Dependency Error:", <<-MSG +Yikes! It looks like you don't have #{name} or one of its dependencies installed. +In order to use Jekyll as currently configured, you'll need to install this gem. + +The full error message from Ruby is: '#{e.message}' + +If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/! + MSG + raise Jekyll::Errors::MissingDependencyException.new(name) + end + end + end + + end + end +end diff --git a/site/_docs/usage.md b/site/_docs/usage.md index 4959ad45..7d2d68e9 100644 --- a/site/_docs/usage.md +++ b/site/_docs/usage.md @@ -81,4 +81,7 @@ $ jekyll build --source _source --destination _deploy {% endhighlight %} For more about the possible configuration options, see the -[configuration](../configuration/) page. \ No newline at end of file +[configuration](../configuration/) page. + +If you're interested in browsing these docs on-the-go, install the +`jekyll-docs` gem and run `jekyll docs` in your terminal.