just use the pygments.appspot.com if there's no pygmentize on the path, rather than as a command line flag

This commit is contained in:
Burke Libbey 2010-03-30 13:46:24 -05:00
parent bc8bdccb7d
commit fb4b5404ae
2 changed files with 6 additions and 9 deletions

View File

@ -7,10 +7,6 @@
#/ -c, --comment-chars=<chars> #/ -c, --comment-chars=<chars>
#/ The string to recognize as a comment marker #/ The string to recognize as a comment marker
#/ -o, --output=<dir> Directory where generated HTML files are written #/ -o, --output=<dir> Directory where generated HTML files are written
#/ -w Highlight code using http://pygments.appspot.com
#/ instead of pygmentize(1)
#/
#/
#/ --help Show this help message #/ --help Show this help message
require 'optparse' require 'optparse'
@ -40,7 +36,6 @@ ARGV.options { |o|
o.on("-o", "--output=DIR") { |dir| output_dir = dir } o.on("-o", "--output=DIR") { |dir| output_dir = dir }
o.on("-l", "--language=LANG") { |lang| options[:language] = lang } o.on("-l", "--language=LANG") { |lang| options[:language] = lang }
o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) } o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
o.on("-w") { |v| options[:webservice] = v }
o.on_tail("-h", "--help") { usage($stdout, 0) } o.on_tail("-h", "--help") { usage($stdout, 0) }
o.parse! o.parse!
} or abort_with_note } or abort_with_note

View File

@ -75,7 +75,6 @@ class Rocco
defaults = { defaults = {
:language => 'ruby', :language => 'ruby',
:comment_chars => '#', :comment_chars => '#',
:webservice => false
} }
@options = defaults.merge(options) @options = defaults.merge(options)
@sources = sources @sources = sources
@ -162,9 +161,10 @@ class Rocco
code_stream = code_blocks.join("\n\n# DIVIDER\n\n") code_stream = code_blocks.join("\n\n# DIVIDER\n\n")
code_html = code_html =
if @options[:webservice] if `which pygmentize` == ""
puts "Warning: pygmentize not installed. Using pygmentize.appspot.com"
highlight_webservice(code_stream) highlight_webservice(code_stream)
else elsif
highlight_pygmentize(code_stream) highlight_pygmentize(code_stream)
end end
@ -199,7 +199,9 @@ class Rocco
code_html code_html
end end
# Pygments is not one of those things that's trivial for a ruby user to install,
# so we'll fall back on a webservice to highlight the code if it isn't available.
def highlight_webservice(code) def highlight_webservice(code)
Net::HTTP.post_form( Net::HTTP.post_form(
URI.parse('http://pygments.appspot.com/'), URI.parse('http://pygments.appspot.com/'),