Use External instead of Deprecator for requiring gracefully

This commit is contained in:
Parker Moore 2014-12-28 14:37:49 -05:00
parent 8c19a6f430
commit c576d23908
5 changed files with 10 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
])

View File

@ -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