class Jekyll::PluginManager

Attributes

site[R]

Public Class Methods

new(site) click to toggle source

Create an instance of this class.

site - the instance of Jekyll::Site we're concerned with

Returns nothing

# File lib/jekyll/plugin_manager.rb, line 10
def initialize(site)
  @site = site
end
require_from_bundler() click to toggle source
# File lib/jekyll/plugin_manager.rb, line 30
def self.require_from_bundler
  if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
    require "bundler"
    Bundler.setup # puts all groups on the load path
    required_gems = Bundler.require(:jekyll_plugins) # requires the gems in this group only
    Jekyll.logger.debug("PluginManager:", "Required #{required_gems.map(&:name).join(', ')}")
    ENV["JEKYLL_NO_BUNDLER_REQUIRE"] = "true"
    true
  else
    false
  end
rescue LoadError, Bundler::GemfileNotFound
  false
end

Public Instance Methods

conscientious_require() click to toggle source

Require all the plugins which are allowed.

Returns nothing

# File lib/jekyll/plugin_manager.rb, line 17
def conscientious_require
  require_plugin_files
  require_gems
  deprecation_checks
end
deprecation_checks() click to toggle source
# File lib/jekyll/plugin_manager.rb, line 86
def deprecation_checks
  pagination_included = (site.config['gems'] || []).include?('jekyll-paginate') || defined?(Jekyll::Paginate)
  if site.config['paginate'] && !pagination_included
    Jekyll::Deprecator.deprecation_message "You appear to have pagination "            "turned on, but you haven't included the `jekyll-paginate` gem. "            "Ensure you have `gems: [jekyll-paginate]` in your configuration file."
  end
end
plugin_allowed?(gem_name) click to toggle source

Check whether a gem plugin is allowed to be used during this build.

gem_name - the name of the gem

Returns true if the gem name is in the whitelist or if the site is not

in safe mode.
# File lib/jekyll/plugin_manager.rb, line 51
def plugin_allowed?(gem_name)
  !site.safe || whitelist.include?(gem_name)
end
plugins_path() click to toggle source

Public: Setup the plugin search path

Returns an Array of plugin search paths

# File lib/jekyll/plugin_manager.rb, line 78
def plugins_path
  if site.config['plugins_dir'] == Jekyll::Configuration::DEFAULTS['plugins_dir']
    [site.in_source_dir(site.config['plugins_dir'])]
  else
    Array(site.config['plugins_dir']).map { |d| File.expand_path(d) }
  end
end
require_gems() click to toggle source

Require each of the gem plugins specified.

Returns nothing.

# File lib/jekyll/plugin_manager.rb, line 26
def require_gems
  Jekyll::External.require_with_graceful_fail(site.gems.select { |gem| plugin_allowed?(gem) })
end
require_plugin_files() click to toggle source

Require all .rb files if safe mode is off

Returns nothing.

# File lib/jekyll/plugin_manager.rb, line 66
def require_plugin_files
  unless site.safe
    plugins_path.each do |plugin_search_path|
      plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb"))
      Jekyll::External.require_with_graceful_fail(plugin_files)
    end
  end
end
whitelist() click to toggle source

Build an array of allowed plugin gem names.

Returns an array of strings, each string being the name of a gem name

that is allowed to be used.
# File lib/jekyll/plugin_manager.rb, line 59
def whitelist
  @whitelist ||= Array[site.config['whitelist']].flatten
end