Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #select_renderer. #4

Merged
merged 1 commit into from Apr 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/octopress-code-highlighter/renderer.rb
Expand Up @@ -19,17 +19,23 @@ def initialize(code, options = {})
end

def select_renderer
begin
require 'rouge'
return 'rouge' if defined?(Rouge)
rescue LoadError; end
begin
require 'pygments.rb'
return 'pygments' if defined?(Pygments)
rescue LoadError
puts "To highlight code, install the gem pygments.rb or rouge.".red
return 'plain'
case true
when renderer_available?('rouge')
require 'rouge'
return 'rouge'
when renderer_available?('pygments.rb')
require 'pygments'
return 'pygments'
else
$stderr.puts 'No syntax highlighting:'.yellow
$stderr.puts "\tInstall pygments.rb, rouge".yellow
end

'plain'
end

def renderer_available?(which)
Gem::Specification::find_all_by_name(which).any?
end

def highlight
Expand Down