Permalink
Browse files

Maruku is now the only processor dependency installed by default. Closes

 #57.

Other processors will be lazy-loaded when necessary (and prompt the
user to install them when necessary).
  • Loading branch information...
1 parent 6932a40 commit de8bd48154c952e68790a6966bde5adddf67e3dd @mojombo mojombo committed Jun 22, 2010
Showing with 84 additions and 34 deletions.
  1. +3 −0 History.txt
  2. +5 −1 bin/jekyll
  3. +6 −3 jekyll.gemspec
  4. +2 −1 lib/jekyll.rb
  5. +7 −0 lib/jekyll/converter.rb
  6. +29 −21 lib/jekyll/converters/markdown.rb
  7. +11 −1 lib/jekyll/converters/textile.rb
  8. +6 −0 lib/jekyll/errors.rb
  9. +6 −0 test/helper.rb
  10. +9 −7 test/test_site.rb
View
@@ -2,6 +2,9 @@
* Major Enhancements
* Proper plugin system (#19, #100)
* Add safe mode so unsafe converters/generators can be added
+ * Maruku is now the only processor dependency installed by default.
+ Other processors will be lazy-loaded when necessary (and prompt the
+ user to install them when necessary) (#57)
* Minor Enhancements
* Inclusion/exclusion of future dated posts (#59)
* Generation for a specific time (#59)
View
@@ -142,7 +142,11 @@ if options['auto']
end
else
puts "Building site: #{source} -> #{destination}"
- site.process
+ begin
+ site.process
+ rescue Jekyll::FatalException
+ exit(1)
+ end
puts "Successfully generated site: #{source} -> #{destination}"
end
View
@@ -23,13 +23,16 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.textile LICENSE]
- s.add_runtime_dependency('RedCloth', [">= 4.2.1"])
s.add_runtime_dependency('liquid', [">= 1.9.0"])
s.add_runtime_dependency('classifier', [">= 1.3.1"])
- s.add_runtime_dependency('maruku', [">= 0.5.9"])
s.add_runtime_dependency('directory_watcher', [">= 1.1.1"])
+ s.add_runtime_dependency('maruku', [">= 0.5.9"])
- s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
+ s.add_development_dependency('redgreen', [">= 4.2.1"])
+ s.add_development_dependency('shoulda', [">= 4.2.1"])
+ s.add_development_dependency('rr', [">= 4.2.1"])
+ s.add_development_dependency('cucumber', [">= 4.2.1"])
+ s.add_development_dependency('RedCloth', [">= 4.2.1"])
# = MANIFEST =
s.files = %w[
View
@@ -22,7 +22,7 @@ def require_all(path)
# 3rd party
require 'liquid'
-require 'redcloth'
+require 'maruku'
# internal requires
require 'jekyll/core_ext'
@@ -34,6 +34,7 @@ def require_all(path)
require 'jekyll/filters'
require 'jekyll/albino'
require 'jekyll/static_file'
+require 'jekyll/errors'
# extensions
require 'jekyll/plugin'
View
@@ -25,6 +25,13 @@ def self.pygments_suffix(pygments_suffix = nil)
@pygments_suffix
end
+ # Initialize the converter.
+ #
+ # Returns an initialized Converter.
+ def initialize(config = {})
+ @config = config
+ end
+
# Get the pygments prefix.
#
# Returns the String prefix.
@@ -6,36 +6,30 @@ class MarkdownConverter < Converter
pygments_prefix '\n'
pygments_suffix '\n'
- def initialize(config = {})
+ def setup
+ return if @setup
# Set the Markdown interpreter (and Maruku self.config, if necessary)
- case config['markdown']
+ case @config['markdown']
when 'rdiscount'
begin
require 'rdiscount'
-
- def convert(content)
- RDiscount.new(content).to_html
- end
-
rescue LoadError
- puts 'You must have the rdiscount gem installed first'
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
+ STDERR.puts ' $ [sudo] gem install rdiscount'
+ raise FatalException.new("Missing dependency: rdiscount")
end
when 'maruku'
begin
require 'maruku'
- def convert(content)
- Maruku.new(content).to_html
- end
-
- if config['maruku']['use_divs']
+ if @config['maruku']['use_divs']
require 'maruku/ext/div'
- puts 'Maruku: Using extended syntax for div elements.'
+ STDERR.puts 'Maruku: Using extended syntax for div elements.'
end
- if config['maruku']['use_tex']
+ if @config['maruku']['use_tex']
require 'maruku/ext/math'
- puts "Maruku: Using LaTeX extension. Images in `#{config['maruku']['png_dir']}`."
+ STDERR.puts "Maruku: Using LaTeX extension. Images in `#{@config['maruku']['png_dir']}`."
# Switch off MathML output
MaRuKu::Globals[:html_math_output_mathml] = false
@@ -44,16 +38,21 @@ def convert(content)
# Turn on math to PNG support with blahtex
# Resulting PNGs stored in `images/latex`
MaRuKu::Globals[:html_math_output_png] = true
- MaRuKu::Globals[:html_png_engine] = config['maruku']['png_engine']
- MaRuKu::Globals[:html_png_dir] = config['maruku']['png_dir']
- MaRuKu::Globals[:html_png_url] = config['maruku']['png_url']
+ MaRuKu::Globals[:html_png_engine] = @config['maruku']['png_engine']
+ MaRuKu::Globals[:html_png_dir] = @config['maruku']['png_dir']
+ MaRuKu::Globals[:html_png_url] = @config['maruku']['png_url']
end
rescue LoadError
- puts "The maruku gem is required for markdown support!"
+ STDERR.puts 'You are missing a library required for Markdown. Please run:'
+ STDERR.puts ' $ [sudo] gem install maruku'
+ raise FatalException.new("Missing dependency: maruku")
end
else
- raise "Invalid Markdown processor: '#{config['markdown']}' -- did you mean 'maruku' or 'rdiscount'?"
+ STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
+ STDERR.puts " Valid options are [ maruku | rdiscount ]"
+ raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
end
+ @setup = true
end
def matches(ext)
@@ -64,6 +63,15 @@ def output_ext(ext)
".html"
end
+ def convert(content)
+ setup
+ case @config['markdown']
+ when 'rdiscount'
+ RDiscount.new(content).to_html
+ when 'maruku'
+ Maruku.new(content).to_html
+ end
+ end
end
end
@@ -6,6 +6,16 @@ class TextileConverter < Converter
pygments_prefix '<notextile>'
pygments_suffix '</notextile>'
+ def setup
+ return if @setup
+ require 'redcloth'
+ @setup = true
+ rescue LoadError
+ STDERR.puts 'You are missing a library required for Textile. Please run:'
+ STDERR.puts ' $ [sudo] gem install RedCloth'
+ raise FatalException.new("Missing dependency: RedCloth")
+ end
+
def matches(ext)
ext =~ /textile/i
end
@@ -15,9 +25,9 @@ def output_ext(ext)
end
def convert(content)
+ setup
RedCloth.new(content).to_html
end
-
end
end
View
@@ -0,0 +1,6 @@
+module Jekyll
+
+ class FatalException < StandardError
+ end
+
+end
View
@@ -3,13 +3,19 @@
require File.join(File.dirname(__FILE__), *%w[.. lib jekyll])
+require 'RedCloth'
+require 'rdiscount'
+
require 'test/unit'
require 'redgreen'
require 'shoulda'
require 'rr'
include Jekyll
+# Send STDERR into the void to suppress program output messages
+STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
+
class Test::Unit::TestCase
include RR::Adapters::TestUnit
View
@@ -133,18 +133,20 @@ class TestSite < Test::Unit::TestCase
end
context 'with an invalid markdown processor in the configuration' do
-
- should 'give a meaningful error message' do
+ should 'not throw an error at initialization time' do
bad_processor = 'not a processor name'
- begin
+ assert_nothing_raised do
Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
- flunk 'Invalid markdown processors should cause a failure on site creation'
- rescue RuntimeError => e
- assert e.to_s =~ /invalid|bad/i
- assert e.to_s =~ %r{#{bad_processor}}
end
end
+ should 'throw FatalException at process time' do
+ bad_processor = 'not a processor name'
+ s = Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
+ assert_raise Jekyll::FatalException do
+ s.process
+ end
+ end
end
end

0 comments on commit de8bd48

Please sign in to comment.