Load Jekyll plugins from BUNDLE_GEMFILE location (#8585)
Merge pull request 8585
This commit is contained in:
parent
6a6d735db2
commit
93ef9389ba
|
@ -46,7 +46,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.require_from_bundler
|
def self.require_from_bundler
|
||||||
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
|
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && gemfile_exists?
|
||||||
require "bundler"
|
require "bundler"
|
||||||
|
|
||||||
Bundler.setup
|
Bundler.setup
|
||||||
|
@ -61,6 +61,13 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check for the existence of a Gemfile.
|
||||||
|
#
|
||||||
|
# Returns true if a Gemfile exists in the places bundler will look
|
||||||
|
def self.gemfile_exists?
|
||||||
|
File.file?("Gemfile") || (ENV["BUNDLE_GEMFILE"] && File.file?(ENV["BUNDLE_GEMFILE"]))
|
||||||
|
end
|
||||||
|
|
||||||
# Check whether a gem plugin is allowed to be used during this build.
|
# Check whether a gem plugin is allowed to be used during this build.
|
||||||
#
|
#
|
||||||
# plugin_name - the name of the plugin
|
# plugin_name - the name of the plugin
|
||||||
|
|
|
@ -10,6 +10,13 @@ class TestPluginManager < JekyllUnitTest
|
||||||
FileUtils.mv "Gemfile.old", "Gemfile"
|
FileUtils.mv "Gemfile.old", "Gemfile"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_bundle_gemfile
|
||||||
|
FileUtils.mv "Gemfile", "AlternateGemfile"
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
FileUtils.mv "AlternateGemfile", "Gemfile"
|
||||||
|
end
|
||||||
|
|
||||||
context "JEKYLL_NO_BUNDLER_REQUIRE set to `nil`" do
|
context "JEKYLL_NO_BUNDLER_REQUIRE set to `nil`" do
|
||||||
should "require from bundler" do
|
should "require from bundler" do
|
||||||
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
|
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
|
||||||
|
@ -20,6 +27,18 @@ class TestPluginManager < JekyllUnitTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "BUNDLE_GEMFILE set to `AlternateGemfile`" do
|
||||||
|
should "require from bundler" do
|
||||||
|
with_env("BUNDLE_GEMFILE", "AlternateGemfile") do
|
||||||
|
with_bundle_gemfile do
|
||||||
|
assert Jekyll::PluginManager.require_from_bundler,
|
||||||
|
"require_from_bundler should return true"
|
||||||
|
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], "Gemfile plugins were not required."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "JEKYLL_NO_BUNDLER_REQUIRE set to `true`" do
|
context "JEKYLL_NO_BUNDLER_REQUIRE set to `true`" do
|
||||||
should "not require from bundler" do
|
should "not require from bundler" do
|
||||||
with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do
|
with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do
|
||||||
|
|
Loading…
Reference in New Issue