Class: Jekyll::PluginManager
- Inherits:
-
Object
- Object
- Jekyll::PluginManager
- Defined in:
- lib/jekyll/plugin_manager.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
-
#conscientious_require ⇒ Object
Require all the plugins which are allowed.
- #deprecation_checks ⇒ Object
-
#initialize(site) ⇒ PluginManager
constructor
Create an instance of this class.
-
#plugin_allowed?(gem_name) ⇒ Boolean
Check whether a gem plugin is allowed to be used during this build.
-
#plugins_path ⇒ Object
Public: Setup the plugin search path.
-
#require_gems ⇒ Object
Require each of the gem plugins specified.
-
#require_plugin_files ⇒ Object
Require all .rb files if safe mode is off.
-
#whitelist ⇒ Object
Build an array of allowed plugin gem names.
Constructor Details
#initialize(site) ⇒ PluginManager
Create an instance of this class.
site - the instance of Jekyll::Site we’re concerned with
Returns nothing
10 11 12 |
# File 'lib/jekyll/plugin_manager.rb', line 10 def initialize(site) @site = site end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
3 4 5 |
# File 'lib/jekyll/plugin_manager.rb', line 3 def site @site end |
Class Method Details
.require_from_bundler ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll/plugin_manager.rb', line 35 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 |
Instance Method Details
#conscientious_require ⇒ Object
Require all the plugins which are allowed.
Returns nothing
17 18 19 20 21 |
# File 'lib/jekyll/plugin_manager.rb', line 17 def conscientious_require require_plugin_files require_gems deprecation_checks end |
#deprecation_checks ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/jekyll/plugin_manager.rb', line 92 def deprecation_checks pagination_included = (site.config['gems'] || []).include?('jekyll-paginate') || defined?(Jekyll::Paginate) if site.config['paginate'] && !pagination_included Jekyll::Deprecator. "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) ⇒ Boolean
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.
56 57 58 |
# File 'lib/jekyll/plugin_manager.rb', line 56 def plugin_allowed?(gem_name) !site.safe || whitelist.include?(gem_name) end |
#plugins_path ⇒ Object
Public: Setup the plugin search path
Returns an Array of plugin search paths
84 85 86 87 88 89 90 |
# File 'lib/jekyll/plugin_manager.rb', line 84 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.(d) } end end |
#require_gems ⇒ Object
Require each of the gem plugins specified.
Returns nothing.
26 27 28 29 30 31 32 33 |
# File 'lib/jekyll/plugin_manager.rb', line 26 def require_gems site.gems.each do |gem| if plugin_allowed?(gem) Jekyll.logger.debug("PluginManager:", "Requiring #{gem}") require gem end end end |
#require_plugin_files ⇒ Object
Require all .rb files if safe mode is off
Returns nothing.
71 72 73 74 75 76 77 78 79 |
# File 'lib/jekyll/plugin_manager.rb', line 71 def require_plugin_files unless site.safe plugins_path.each do |plugins| Dir[File.join(plugins, "**", "*.rb")].sort.each do |f| require f end end end end |
#whitelist ⇒ Object
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.
64 65 66 |
# File 'lib/jekyll/plugin_manager.rb', line 64 def whitelist @whitelist ||= Array[site.config['whitelist']].flatten end |