Skip to content

Commit

Permalink
Maruku is now the only processor dependency installed by default. Closes
Browse files Browse the repository at this point in the history
 jekyll#57.

Other processors will be lazy-loaded when necessary (and prompt the
user to install them when necessary).
  • Loading branch information
mojombo committed Jun 22, 2010
1 parent 6932a40 commit de8bd48
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 34 deletions.
3 changes: 3 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion bin/jekyll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions jekyll.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def require_all(path)

# 3rd party
require 'liquid'
require 'redcloth'
require 'maruku'

# internal requires
require 'jekyll/core_ext'
Expand All @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions lib/jekyll/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 29 additions & 21 deletions lib/jekyll/converters/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
12 changes: 11 additions & 1 deletion lib/jekyll/converters/textile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,9 +25,9 @@ def output_ext(ext)
end

def convert(content)
setup
RedCloth.new(content).to_html
end

end

end
6 changes: 6 additions & 0 deletions lib/jekyll/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Jekyll

class FatalException < StandardError
end

end
6 changes: 6 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions test/test_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de8bd48

Please sign in to comment.