From eed5d48981fd5c53fdcdcb18f68a5ac7a594ad37 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Fri, 2 Apr 2010 15:59:52 -0700 Subject: [PATCH] avoid which(1) --- lib/rocco.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/rocco.rb b/lib/rocco.rb index f3d96d0..2e7fb34 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -52,7 +52,8 @@ require 'net/http' # Code is run through [Pygments](http://pygments.org/) for syntax # highlighting. If it's not installed, locally, use a webservice. -if `which pygmentize`.blank? +include FileTest +if !ENV['PATH'].split(':').any? { |dir| executable?("#{dir}/pygmentize") } warn "WARNING: Pygments not found. Using webservice." end @@ -166,10 +167,10 @@ class Rocco # `pygmentize(1)` or code_stream = code_blocks.join("\n\n#{@options[:comment_chars]} DIVIDER\n\n") - if `which pygmentize`.blank? - code_html = highlight_webservice(code_stream) - else + if ENV['PATH'].split(':').any? { |dir| executable?("#{dir}/pygmentize") } code_html = highlight_pygmentize(code_stream) + else + code_html = highlight_webservice(code_stream) end # Do some post-processing on the pygments output to split things back