add `plugins` config key as replacement for `gems` (#5130)
Merge pull request 5130
This commit is contained in:
parent
3df88b2e31
commit
ccb133fd33
|
@ -88,6 +88,6 @@ To enable Coffeescript in Jekyll 3.0 and up you must
|
||||||
* Ensure that your `_config.yml` is up-to-date and includes the following:
|
* Ensure that your `_config.yml` is up-to-date and includes the following:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
gems:
|
plugins:
|
||||||
- jekyll-coffeescript
|
- jekyll-coffeescript
|
||||||
```
|
```
|
||||||
|
|
|
@ -616,7 +616,7 @@ unpublished: false
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
whitelist: []
|
whitelist: []
|
||||||
gems: []
|
plugins: []
|
||||||
|
|
||||||
# Conversion
|
# Conversion
|
||||||
markdown: kramdown
|
markdown: kramdown
|
||||||
|
|
|
@ -27,12 +27,12 @@ You have 3 options for installing plugins:
|
||||||
1. In your site source root, make a `_plugins` directory. Place your plugins
|
1. In your site source root, make a `_plugins` directory. Place your plugins
|
||||||
here. Any file ending in `*.rb` inside this directory will be loaded before
|
here. Any file ending in `*.rb` inside this directory will be loaded before
|
||||||
Jekyll generates your site.
|
Jekyll generates your site.
|
||||||
2. In your `_config.yml` file, add a new array with the key `gems` and the
|
2. In your `_config.yml` file, add a new array with the key `plugins` and the
|
||||||
values of the gem names of the plugins you'd like to use. An example:
|
values of the gem names of the plugins you'd like to use. An example:
|
||||||
|
|
||||||
|
|
||||||
gems: [jekyll-coffeescript, jekyll-watch, jekyll-assets]
|
plugins: [jekyll-coffeescript, jekyll-watch, jekyll-assets]
|
||||||
# This will require each of these gems automatically.
|
# This will require each of these plugins automatically.
|
||||||
|
|
||||||
Then install your plugins using `gem install jekyll-coffeescript jekyll-watch jekyll-assets`
|
Then install your plugins using `gem install jekyll-coffeescript jekyll-watch jekyll-assets`
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Jekyll
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
"whitelist" => [],
|
"whitelist" => [],
|
||||||
"gems" => [],
|
"plugins" => [],
|
||||||
|
|
||||||
# Conversion
|
# Conversion
|
||||||
"markdown" => "kramdown",
|
"markdown" => "kramdown",
|
||||||
|
@ -229,9 +229,10 @@ module Jekyll
|
||||||
# Provide backwards-compatibility
|
# Provide backwards-compatibility
|
||||||
check_auto(config)
|
check_auto(config)
|
||||||
check_server(config)
|
check_server(config)
|
||||||
|
check_plugins(config)
|
||||||
|
|
||||||
renamed_key "server_port", "port", config
|
renamed_key "server_port", "port", config
|
||||||
renamed_key "plugins", "plugins_dir", config
|
renamed_key "gems", "plugins", config
|
||||||
renamed_key "layouts", "layouts_dir", config
|
renamed_key "layouts", "layouts_dir", config
|
||||||
renamed_key "data_source", "data_dir", config
|
renamed_key "data_source", "data_dir", config
|
||||||
|
|
||||||
|
@ -385,5 +386,24 @@ module Jekyll
|
||||||
"`_config.yml` file."
|
"`_config.yml` file."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Private: Checks if the `plugins` config is a String
|
||||||
|
#
|
||||||
|
# config - the config hash
|
||||||
|
#
|
||||||
|
# Raises a Jekyll::Errors::InvalidConfigurationError if the config `plugins`
|
||||||
|
# is a string
|
||||||
|
private
|
||||||
|
def check_plugins(config)
|
||||||
|
if config.key?("plugins") && config["plugins"].is_a?(String)
|
||||||
|
Jekyll.logger.error "Configuration Error:", "You specified the" \
|
||||||
|
" `plugins` config in your configuration file as a string, please" \
|
||||||
|
" use an array instead. If you wanted to set the directory of your" \
|
||||||
|
" plugins, use the config key `plugins_dir` instead."
|
||||||
|
raise Jekyll::Errors::InvalidConfigurationError,
|
||||||
|
"'plugins' should not be a string, but was: " \
|
||||||
|
"#{config["plugins"].inspect}. Use 'plugins_dir' instead."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,5 +13,6 @@ module Jekyll
|
||||||
InvalidPostNameError = Class.new(FatalException)
|
InvalidPostNameError = Class.new(FatalException)
|
||||||
PostURLError = Class.new(FatalException)
|
PostURLError = Class.new(FatalException)
|
||||||
InvalidURLError = Class.new(FatalException)
|
InvalidURLError = Class.new(FatalException)
|
||||||
|
InvalidConfigurationError = Class.new(FatalException)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def require_gems
|
def require_gems
|
||||||
Jekyll::External.require_with_graceful_fail(
|
Jekyll::External.require_with_graceful_fail(
|
||||||
site.gems.select { |gem| plugin_allowed?(gem) }
|
site.gems.select { |plugin| plugin_allowed?(plugin) }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ module Jekyll
|
||||||
|
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# gem_name - the name of the gem
|
# plugin_name - the name of the plugin
|
||||||
#
|
#
|
||||||
# Returns true if the gem name is in the whitelist or if the site is not
|
# Returns true if the plugin name is in the whitelist or if the site is not
|
||||||
# in safe mode.
|
# in safe mode.
|
||||||
def plugin_allowed?(gem_name)
|
def plugin_allowed?(plugin_name)
|
||||||
!site.safe || whitelist.include?(gem_name)
|
!site.safe || whitelist.include?(plugin_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Build an array of allowed plugin gem names.
|
# Build an array of allowed plugin gem names.
|
||||||
|
@ -99,12 +99,12 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def deprecation_checks
|
def deprecation_checks
|
||||||
pagination_included = (site.config["gems"] || []).include?("jekyll-paginate") ||
|
pagination_included = (site.config["plugins"] || []).include?("jekyll-paginate") ||
|
||||||
defined?(Jekyll::Paginate)
|
defined?(Jekyll::Paginate)
|
||||||
if site.config["paginate"] && !pagination_included
|
if site.config["paginate"] && !pagination_included
|
||||||
Jekyll::Deprecator.deprecation_message "You appear to have pagination " \
|
Jekyll::Deprecator.deprecation_message "You appear to have pagination " \
|
||||||
"turned on, but you haven't included the `jekyll-paginate` gem. " \
|
"turned on, but you haven't included the `jekyll-paginate` gem. " \
|
||||||
"Ensure you have `gems: [jekyll-paginate]` in your configuration file."
|
"Ensure you have `plugins: [jekyll-paginate]` in your configuration file."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,10 +46,13 @@ module Jekyll
|
||||||
@config = config.clone
|
@config = config.clone
|
||||||
|
|
||||||
%w(safe lsi highlighter baseurl exclude include future unpublished
|
%w(safe lsi highlighter baseurl exclude include future unpublished
|
||||||
show_drafts limit_posts keep_files gems).each do |opt|
|
show_drafts limit_posts keep_files).each do |opt|
|
||||||
self.send("#{opt}=", config[opt])
|
self.send("#{opt}=", config[opt])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# keep using `gems` to avoid breaking change
|
||||||
|
self.gems = config["plugins"]
|
||||||
|
|
||||||
configure_plugins
|
configure_plugins
|
||||||
configure_theme
|
configure_theme
|
||||||
configure_include_paths
|
configure_include_paths
|
||||||
|
|
|
@ -205,9 +205,9 @@ class TestConfiguration < JekyllUnitTest
|
||||||
"exclude" => "READ-ME.md, Gemfile,CONTRIBUTING.hello.markdown",
|
"exclude" => "READ-ME.md, Gemfile,CONTRIBUTING.hello.markdown",
|
||||||
"include" => "STOP_THE_PRESSES.txt,.heloses, .git",
|
"include" => "STOP_THE_PRESSES.txt,.heloses, .git",
|
||||||
"pygments" => true,
|
"pygments" => true,
|
||||||
"plugins" => true,
|
|
||||||
"layouts" => true,
|
"layouts" => true,
|
||||||
"data_source" => true,
|
"data_source" => true,
|
||||||
|
"gems" => [],
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
should "unset 'auto' and 'watch'" do
|
should "unset 'auto' and 'watch'" do
|
||||||
|
@ -242,9 +242,6 @@ class TestConfiguration < JekyllUnitTest
|
||||||
assert_equal @config.backwards_compatibilize["highlighter"], "pygments"
|
assert_equal @config.backwards_compatibilize["highlighter"], "pygments"
|
||||||
end
|
end
|
||||||
should "adjust directory names" do
|
should "adjust directory names" do
|
||||||
assert @config.key?("plugins")
|
|
||||||
assert !@config.backwards_compatibilize.key?("plugins")
|
|
||||||
assert @config.backwards_compatibilize["plugins_dir"]
|
|
||||||
assert @config.key?("layouts")
|
assert @config.key?("layouts")
|
||||||
assert !@config.backwards_compatibilize.key?("layouts")
|
assert !@config.backwards_compatibilize.key?("layouts")
|
||||||
assert @config.backwards_compatibilize["layouts_dir"]
|
assert @config.backwards_compatibilize["layouts_dir"]
|
||||||
|
@ -252,6 +249,17 @@ class TestConfiguration < JekyllUnitTest
|
||||||
assert !@config.backwards_compatibilize.key?("data_source")
|
assert !@config.backwards_compatibilize.key?("data_source")
|
||||||
assert @config.backwards_compatibilize["data_dir"]
|
assert @config.backwards_compatibilize["data_dir"]
|
||||||
end
|
end
|
||||||
|
should "raise an error if `plugins` key is a string" do
|
||||||
|
config = Configuration[{ "plugins" => "_plugin" }]
|
||||||
|
assert_raises Jekyll::Errors::InvalidConfigurationError do
|
||||||
|
config.backwards_compatibilize
|
||||||
|
end
|
||||||
|
end
|
||||||
|
should "set the `gems` config to `plugins`" do
|
||||||
|
assert @config.key?("gems")
|
||||||
|
assert !@config.backwards_compatibilize["gems"]
|
||||||
|
assert @config.backwards_compatibilize["plugins"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
context "#fix_common_issues" do
|
context "#fix_common_issues" do
|
||||||
setup do
|
setup do
|
||||||
|
|
|
@ -132,7 +132,7 @@ class TestPluginManager < JekyllUnitTest
|
||||||
|
|
||||||
should "print no deprecation warning if jekyll-paginate is present" do
|
should "print no deprecation warning if jekyll-paginate is present" do
|
||||||
site = double({
|
site = double({
|
||||||
:config => { "paginate" => true, "gems" => ["jekyll-paginate"] },
|
:config => { "paginate" => true, "plugins" => ["jekyll-paginate"] },
|
||||||
})
|
})
|
||||||
plugin_manager = PluginManager.new(site)
|
plugin_manager = PluginManager.new(site)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue