load plugins under safe mode
This commit is contained in:
parent
31c65c56f4
commit
cb77a5287b
|
@ -1,6 +1,7 @@
|
|||
== Edge
|
||||
* Major Enhancements
|
||||
* Proper plugin system (#19, #100)
|
||||
* Add safe mode so unsafe converters/generators can be added
|
||||
* Minor Enhancements
|
||||
* Inclusion/exclusion of future dated posts (#59)
|
||||
* Generation for a specific time (#59)
|
||||
|
|
|
@ -23,6 +23,10 @@ options = {}
|
|||
opts = OptionParser.new do |opts|
|
||||
opts.banner = help
|
||||
|
||||
opts.on("--safe", "Safe mode (default unsafe)") do
|
||||
options['safe'] = true
|
||||
end
|
||||
|
||||
opts.on("--auto", "Auto-regenerate") do
|
||||
options['auto'] = true
|
||||
end
|
||||
|
|
|
@ -49,12 +49,14 @@ module Jekyll
|
|||
# Default options. Overriden by values in _config.yml or command-line opts.
|
||||
# (Strings rather symbols used for compatability with YAML).
|
||||
DEFAULTS = {
|
||||
'safe' => false,
|
||||
'auto' => false,
|
||||
'server' => false,
|
||||
'server_port' => 4000,
|
||||
|
||||
'source' => '.',
|
||||
'destination' => File.join('.', '_site'),
|
||||
'plugins' => File.join('.', '_plugins'),
|
||||
|
||||
'future' => true,
|
||||
'lsi' => false,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module Jekyll
|
||||
|
||||
class IdentityConverter < Converter
|
||||
safe true
|
||||
|
||||
priority :lowest
|
||||
|
||||
def matches(ext)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module Jekyll
|
||||
|
||||
class MarkdownConverter < Converter
|
||||
safe true
|
||||
|
||||
pygments_prefix '\n'
|
||||
pygments_suffix '\n'
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module Jekyll
|
||||
|
||||
class TextileConverter < Converter
|
||||
safe true
|
||||
|
||||
pygments_prefix '<notextile>'
|
||||
pygments_suffix '</notextile>'
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Jekyll
|
||||
|
||||
class Pagination < Generator
|
||||
safe true
|
||||
|
||||
def generate(site)
|
||||
site.pages.dup.each do |page|
|
||||
|
|
|
@ -25,7 +25,7 @@ module Jekyll
|
|||
@subclasses ||= []
|
||||
end
|
||||
|
||||
# Get or set the priority of this converter. When called without an
|
||||
# Get or set the priority of this plugin. When called without an
|
||||
# argument it returns the priority. When an argument is given, it will
|
||||
# set the priority.
|
||||
#
|
||||
|
@ -40,6 +40,20 @@ module Jekyll
|
|||
@priority || :normal
|
||||
end
|
||||
|
||||
# Get or set the safety of this plugin. When called without an argument
|
||||
# it returns the safety. When an argument is given, it will set the
|
||||
# safety.
|
||||
#
|
||||
# safe - The Boolean safety (default: nil).
|
||||
#
|
||||
# Returns the safety Boolean.
|
||||
def self.safe(safe = nil)
|
||||
if safe
|
||||
@safe = safe
|
||||
end
|
||||
@safe || false
|
||||
end
|
||||
|
||||
# Spaceship is priority [higher -> lower]
|
||||
#
|
||||
# other - The class to be compared.
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
module Jekyll
|
||||
|
||||
class Site
|
||||
attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude,
|
||||
:source, :dest, :lsi, :pygments, :permalink_style, :tags, :time,
|
||||
:future
|
||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||
:categories, :exclude, :source, :dest, :lsi, :pygments,
|
||||
:permalink_style, :tags, :time, :future, :safe, :plugins
|
||||
attr_accessor :converters, :generators
|
||||
|
||||
# Initialize the site
|
||||
|
@ -13,8 +13,10 @@ module Jekyll
|
|||
def initialize(config)
|
||||
self.config = config.clone
|
||||
|
||||
self.safe = config['safe']
|
||||
self.source = File.expand_path(config['source'])
|
||||
self.dest = config['destination']
|
||||
self.plugins = File.expand_path(config['plugins'])
|
||||
self.lsi = config['lsi']
|
||||
self.pygments = config['pygments']
|
||||
self.permalink_style = config['permalink'].to_sym
|
||||
|
@ -38,11 +40,23 @@ module Jekyll
|
|||
def setup
|
||||
require 'classifier' if self.lsi
|
||||
|
||||
self.converters = Jekyll::Converter.subclasses.map do |c|
|
||||
# If safe mode is off, load in any ruby files under the plugins
|
||||
# directory.
|
||||
unless self.safe
|
||||
Dir[File.join(self.plugins, "**/*.rb")].each do |f|
|
||||
require f
|
||||
end
|
||||
end
|
||||
|
||||
self.converters = Jekyll::Converter.subclasses.select do |c|
|
||||
!self.safe || c.safe
|
||||
end.map do |c|
|
||||
c.new(self.config)
|
||||
end
|
||||
|
||||
self.generators = Jekyll::Generator.subclasses.map do |c|
|
||||
self.generators = Jekyll::Generator.subclasses.select do |c|
|
||||
!self.safe || c.safe
|
||||
end.map do |c|
|
||||
c.new(self.config)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue