Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

load plugins under safe mode

  • Loading branch information...
commit cb77a5287b82349bc662a3cd9d2093eee783b991 1 parent 31c65c5
@mojombo mojombo authored
View
1  History.txt
@@ -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)
View
4 bin/jekyll
@@ -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
View
2  lib/jekyll.rb
@@ -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,
View
2  lib/jekyll/converters/identity.rb
@@ -1,6 +1,8 @@
module Jekyll
class IdentityConverter < Converter
+ safe true
+
priority :lowest
def matches(ext)
View
2  lib/jekyll/converters/markdown.rb
@@ -1,6 +1,8 @@
module Jekyll
class MarkdownConverter < Converter
+ safe true
+
pygments_prefix '\n'
pygments_suffix '\n'
View
2  lib/jekyll/converters/textile.rb
@@ -1,6 +1,8 @@
module Jekyll
class TextileConverter < Converter
+ safe true
+
pygments_prefix '<notextile>'
pygments_suffix '</notextile>'
View
1  lib/jekyll/generators/pagination.rb
@@ -1,6 +1,7 @@
module Jekyll
class Pagination < Generator
+ safe true
def generate(site)
site.pages.dup.each do |page|
View
16 lib/jekyll/plugin.rb
@@ -25,7 +25,7 @@ def self.subclasses
@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 @@ def self.priority(priority = nil)
@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.
View
24 lib/jekyll/site.rb
@@ -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 @@ class Site
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 @@ def reset
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
Please sign in to comment.
Something went wrong with that request. Please try again.