Skip to content

Commit

Permalink
require external library only if necessary (#6596)
Browse files Browse the repository at this point in the history
Merge pull request 6596
  • Loading branch information
ashmaroli authored and jekyllbot committed Jan 14, 2018
1 parent 9cc6e2a commit 9a88900
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/jekyll/converters/markdown/kramdown_parser.rb
Expand Up @@ -14,7 +14,9 @@ class KramdownParser
}.freeze

def initialize(config)
Jekyll::External.require_with_graceful_fail "kramdown"
unless defined?(Kramdown)
Jekyll::External.require_with_graceful_fail "kramdown"
end
@main_fallback_highlighter = config["highlighter"] || "rouge"
@config = config["kramdown"] || {}
@highlighter = nil
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/converters/markdown/rdiscount_parser.rb
Expand Up @@ -5,7 +5,9 @@ module Converters
class Markdown
class RDiscountParser
def initialize(config)
Jekyll::External.require_with_graceful_fail "rdiscount"
unless defined?(RDiscount)
Jekyll::External.require_with_graceful_fail "rdiscount"
end
@config = config
@rdiscount_extensions = @config["rdiscount"]["extensions"].map(&:to_sym)
end
Expand Down
8 changes: 6 additions & 2 deletions lib/jekyll/converters/markdown/redcarpet_parser.rb
Expand Up @@ -16,7 +16,9 @@ def add_code_tags(code, lang)
module WithPygments
include CommonMethods
def block_code(code, lang)
Jekyll::External.require_with_graceful_fail("pygments")
unless defined?(Pygments)
Jekyll::External.require_with_graceful_fail("pygments")
end
lang = lang && lang.split.first || "text"
add_code_tags(
Pygments.highlight(
Expand Down Expand Up @@ -60,7 +62,9 @@ def rouge_formatter(_lexer)
end

def initialize(config)
Jekyll::External.require_with_graceful_fail("redcarpet")
unless defined?(Redcarpet)
Jekyll::External.require_with_graceful_fail("redcarpet")
end
@config = config
@redcarpet_extensions = {}
@config["redcarpet"]["extensions"].each do |e|
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/converters/smartypants.rb
Expand Up @@ -20,7 +20,9 @@ class SmartyPants < Converter
priority :low

def initialize(config)
Jekyll::External.require_with_graceful_fail "kramdown"
unless defined?(Kramdown)
Jekyll::External.require_with_graceful_fail "kramdown"
end
@config = config["kramdown"].dup || {}
@config[:input] = :SmartyPants
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/theme.rb
Expand Up @@ -38,7 +38,7 @@ def assets_path

def configure_sass
return unless sass_path
Jekyll::External.require_with_graceful_fail "sass"
External.require_with_graceful_fail("sass") unless defined?(Sass)
Sass.load_paths << sass_path
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/utils/rouge.rb
Expand Up @@ -5,7 +5,7 @@ module Utils
module Rouge

def self.html_formatter(*args)
Jekyll::External.require_with_graceful_fail("rouge")
Jekyll::External.require_with_graceful_fail("rouge") unless defined?(::Rouge)
if old_api?
::Rouge::Formatters::HTML.new(*args)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/utils/win_tz.rb
Expand Up @@ -12,7 +12,7 @@ module WinTZ
#
# Returns a string that ultimately re-defines ENV["TZ"] in Windows
def calculate(timezone)
External.require_with_graceful_fail("tzinfo")
External.require_with_graceful_fail("tzinfo") unless defined?(TZInfo)
tz = TZInfo::Timezone.get(timezone)
difference = Time.now.to_i - tz.now.to_i
#
Expand Down

0 comments on commit 9a88900

Please sign in to comment.