diff --git a/lib/jekyll.rb b/lib/jekyll.rb index bde11581..3f01e4d0 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -29,12 +29,6 @@ require 'liquid' require 'kramdown' require 'colorator' -# Conditional optimizations -begin - require 'liquid-c' -rescue LoadError -end - SafeYAML::OPTIONS[:suppress_warnings] = true Liquid::Template.error_mode = :strict @@ -51,6 +45,7 @@ module Jekyll autoload :EntryFilter, 'jekyll/entry_filter' autoload :Errors, 'jekyll/errors' autoload :Excerpt, 'jekyll/excerpt' + autoload :External, 'jekyll/external' autoload :Filters, 'jekyll/filters' autoload :FrontmatterDefaults, 'jekyll/frontmatter_defaults' autoload :Layout, 'jekyll/layout' @@ -162,6 +157,9 @@ module Jekyll end end + # Conditional optimizations + Jekyll::External.require_if_present('liquid-c') + end end @@ -172,7 +170,7 @@ require_all 'jekyll/generators' require_all 'jekyll/tags' # Eventually remove these for 3.0 as non-core -Jekyll::Deprecator.gracefully_require(%w[ +Jekyll::External.require_with_graceful_fail(%w[ toml jekyll-paginate jekyll-gist diff --git a/lib/jekyll/commands/build.rb b/lib/jekyll/commands/build.rb index 11f1f75e..536324fc 100644 --- a/lib/jekyll/commands/build.rb +++ b/lib/jekyll/commands/build.rb @@ -66,7 +66,7 @@ module Jekyll # # Returns nothing. def watch(site, options) - Deprecator.gracefully_require 'jekyll-watch' + External.require_with_graceful_fail 'jekyll-watch' Jekyll::Watcher.watch(options) end diff --git a/lib/jekyll/converters/markdown/rdiscount_parser.rb b/lib/jekyll/converters/markdown/rdiscount_parser.rb index 0c8634e4..fb5172e7 100644 --- a/lib/jekyll/converters/markdown/rdiscount_parser.rb +++ b/lib/jekyll/converters/markdown/rdiscount_parser.rb @@ -3,7 +3,7 @@ module Jekyll class Markdown class RDiscountParser def initialize(config) - Jekyll::Deprecator.gracefully_require "rdiscount" + Jekyll::External.require_with_graceful_fail "rdiscount" @config = config @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym } end diff --git a/lib/jekyll/converters/markdown/redcarpet_parser.rb b/lib/jekyll/converters/markdown/redcarpet_parser.rb index 468069e9..3be60739 100644 --- a/lib/jekyll/converters/markdown/redcarpet_parser.rb +++ b/lib/jekyll/converters/markdown/redcarpet_parser.rb @@ -14,7 +14,7 @@ module Jekyll module WithPygments include CommonMethods def block_code(code, lang) - Jekyll::Deprecator.gracefully_require("pygments") + Jekyll::External.require_with_graceful_fail("pygments") lang = lang && lang.split.first || "text" add_code_tags( Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }), @@ -55,7 +55,7 @@ module Jekyll def initialize(config) - Deprecator.gracefully_require("redcarpet") + External.require_with_graceful_fail("redcarpet") @config = config @redcarpet_extensions = {} @config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true } @@ -71,7 +71,7 @@ module Jekyll end when "rouge" Class.new(Redcarpet::Render::HTML) do - Jekyll::Deprecator.gracefully_require(%w[ + Jekyll::External.require_with_graceful_fail(%w[ rouge rouge/plugins/redcarpet ]) diff --git a/lib/jekyll/deprecator.rb b/lib/jekyll/deprecator.rb index 8e4daf9c..9ec5857e 100644 --- a/lib/jekyll/deprecator.rb +++ b/lib/jekyll/deprecator.rb @@ -40,22 +40,5 @@ module Jekyll Jekyll.logger.warn "Defaults:", "Please update your front-matter defaults to use 'type: #{current}'." end - def gracefully_require(gem_name) - Array(gem_name).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 Errors::MissingDependencyException.new(name) - end - end - end end end