lib/jekyll/assets/utils.rb in jekyll-assets-3.0.5 vs lib/jekyll/assets/utils.rb in jekyll-assets-3.0.6
- old
+ new
@@ -1,12 +1,22 @@
# Frozen-string-literal: true
-# Copyright: 2012 - 2017 - MIT License
+# Copyright: 2012 - 2018 - MIT License
# Encoding: utf-8
module Jekyll
module Assets
module Utils
+ def self.activate(gem)
+ return unless Gem::Specification.find_all_by_name(gem)&.any? ||
+ Gem::Specification.find_by_path(gem)&.any?
+
+ require gem
+ if block_given?
+ yield
+ end
+ end
+
def self.html_fragment(*a)
Nokogiri::HTML.fragment(*a) do |c|
c.options = Nokogiri::XML::ParseOptions::NONET | \
Nokogiri::XML::ParseOptions::NOENT
end
@@ -293,36 +303,19 @@
out
end
# --
- # rubocop:enable Metrics/AbcSize
- # Either require the file or keep moving along.
- # @yield a block of code if the require works out.
- # @param [String] file the file to require.
- # @return [nil]
- # --
- module_function
- def try_require(file)
- require file
- if block_given?
- yield
- end
- rescue LoadError
- Logger.debug "Unable to load file `#{file}'"
- end
-
- # --
# @yield a blockof code if the require works out.
# Either require exec.js, and the file or move along.
# @param [String] file the file to require.
# @return [nil]
# --
- module_function
- def javascript?
- require "execjs"
- if block_given?
- yield
+ def self.javascript?
+ activate "execjs" do
+ if block_given?
+ yield
+ end
end
rescue ExecJS::RuntimeUnavailable
nil
end
end