safely allow loading jekyll customizations from inside a site

This commit is contained in:
Jamie Macey 2009-11-29 13:25:00 -05:00
parent 2f2e45bedf
commit fab5a715c5
5 changed files with 41 additions and 2 deletions

View File

@ -62,6 +62,14 @@ opts = OptionParser.new do |opts|
end end
end end
opts.on("--extensions", "Load Jekyll extensions from _lib directory") do
options['extensions'] = true
end
opts.on("--no-extensions", "Do not load Jekyll extensions") do
options['extensions'] = false
end
opts.on("--version", "Display current version") do opts.on("--version", "Display current version") do
puts "Jekyll " + Jekyll.version puts "Jekyll " + Jekyll.version
exit 0 exit 0

View File

@ -61,3 +61,21 @@ Feature: Site configuration
When I run jekyll When I run jekyll
Then the _site directory should exist Then the _site directory should exist
And I should see "puts 'Hello world!'" in "_site/index.html" And I should see "puts 'Hello world!'" in "_site/index.html"
Scenario: Load an extension from _lib
Given I have an "index.html" page that contains "{{ 'extension' | hello }}"
And I have a _lib directory
And I have a "_lib/hello.rb" file that contains "module Jekyll::Filters ; def hello(input) ; "hello #{input}" ; end ; end"
And I have a configuration file with "extensions" set to "true"
When I run jekyll
Then the _site directory should exist
And I should see "hello extension" in "_site/index.html"
Scenario: Skip loading extensions from _lib
Given I have an "index.html" page that contains "{{ 'extension' | hello }}"
And I have a _lib directory
And I have a "_lib/hello.rb" file that contains "module Jekyll::Filters ; def hello(input) ; "hello #{input}" ; end ; end"
And I have a configuration file with "extensions" set to "false"
When I run jekyll
Then the _site directory should exist
And I should not see "hello extension" in "_site/index.html"

View File

@ -25,7 +25,7 @@ EOF
end end
end end
Given /^I have an "(.*)" file that contains "(.*)"$/ do |file, text| Given /^I have an? "(.*)" file that contains "(.*)"$/ do |file, text|
File.open(file, 'w') do |f| File.open(file, 'w') do |f|
f.write(text) f.write(text)
f.close f.close
@ -123,6 +123,10 @@ Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
assert_match Regexp.new(text), File.open(file).readlines.join assert_match Regexp.new(text), File.open(file).readlines.join
end end
Then /^I should not see "(.*)" in "(.*)"$/ do |text, file|
assert_no_match Regexp.new(text), File.open(file).readlines.join
end
Then /^the "(.*)" file should not exist$/ do |file| Then /^the "(.*)" file should not exist$/ do |file|
assert !File.exists?(file) assert !File.exists?(file)
end end

View File

@ -42,6 +42,7 @@ module Jekyll
'pygments' => false, 'pygments' => false,
'markdown' => 'maruku', 'markdown' => 'maruku',
'permalink' => 'date', 'permalink' => 'date',
'extensions' => false,
'maruku' => { 'maruku' => {
'use_tex' => false, 'use_tex' => false,

View File

@ -2,7 +2,8 @@ module Jekyll
class Site class Site
attr_accessor :config, :layouts, :posts, :categories, :exclude, attr_accessor :config, :layouts, :posts, :categories, :exclude,
:source, :dest, :lsi, :pygments, :permalink_style, :tags :source, :dest, :lsi, :pygments, :permalink_style, :tags,
:extensions
# Initialize the site # Initialize the site
# +config+ is a Hash containing site configurations details # +config+ is a Hash containing site configurations details
@ -17,6 +18,7 @@ module Jekyll
self.pygments = config['pygments'] self.pygments = config['pygments']
self.permalink_style = config['permalink'].to_sym self.permalink_style = config['permalink'].to_sym
self.exclude = config['exclude'] || [] self.exclude = config['exclude'] || []
self.extensions = config['extensions']
self.reset self.reset
self.setup self.setup
@ -80,6 +82,12 @@ module Jekyll
else else
raise "Invalid Markdown processor: '#{self.config['markdown']}' -- did you mean 'maruku' or 'rdiscount'?" raise "Invalid Markdown processor: '#{self.config['markdown']}' -- did you mean 'maruku' or 'rdiscount'?"
end end
# Load extensions from _lib folder
if self.extensions
# load instead of require so that jekyll --auto reloads changes
Dir["#{source}/_lib/*.rb"].each {|f| load f}
end
end end
def textile(content) def textile(content)