From 9d0b59983f43b3a98765ac114b73016cd99e7ebc Mon Sep 17 00:00:00 2001 From: Eric Strathmeyer Date: Mon, 19 Sep 2011 01:52:55 -0400 Subject: [PATCH] use local pygmentize on Windows --- bin/rocco | 12 +++++++++++- lib/rocco.rb | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bin/rocco b/bin/rocco index 71a67c6..96e98ef 100755 --- a/bin/rocco +++ b/bin/rocco @@ -47,8 +47,18 @@ ARGV.options { |o| o.parse! } or abort_with_note +if RUBY_PLATFORM =~ /(win|w)32$/ + # windows machine + path_dirs = ENV['PATH'].split(';') + found_pygmentize = path_dirs.any? { |dir| File.executable?("#{dir}/pygmentize.exe") } +else + # *nix system + path_dirs = ENV['PATH'].split(':') + found_pygmentize = path_dirs.any? { |dir| File.executable?("#{dir}/pygmentize") } +end + # Use http://pygments.appspot.com in case `pygmentize(1)` isn't available. -if ! ENV['PATH'].split(':').any? { |dir| File.exist?("#{dir}/pygmentize") } +if !found_pygmentize unless options[:webservice] $stderr.puts "pygmentize not in PATH; using pygments.appspot.com instead" options[:webservice] = true diff --git a/lib/rocco.rb b/lib/rocco.rb index 551a79d..ed36bdd 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -51,7 +51,17 @@ # Code is run through [Pygments](http://pygments.org/) for syntax # highlighting. If it's not installed, locally, use a webservice. -if !ENV['PATH'].split(':').any? { |dir| File.executable?("#{dir}/pygmentize") } +if RUBY_PLATFORM =~ /(win|w)32$/ + # windows machine + path_dirs = ENV['PATH'].split(';') + found_pygmentize = path_dirs.any? { |dir| File.executable?("#{dir}/pygmentize.exe") } +else + # *nix system + path_dirs = ENV['PATH'].split(':') + found_pygmentize = path_dirs.any? { |dir| File.executable?("#{dir}/pygmentize") } +end + +if !found_pygmentize warn "WARNING: Pygments not found. Using webservice." end