diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-01-22 13:18:01 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-01-22 13:18:01 +0000 |
commit | 144ca23442a5e123935dea4073670d4dba4caa89 (patch) | |
tree | 61c02c4fee71195b09fd7e6270d866a3b2fabd28 /vendor/gems/coderay-0.9.7/bin/coderay | |
parent | e4faf3553a1b9d22ee171e08f62f112637b05e19 (diff) | |
download | redmine-144ca23442a5e123935dea4073670d4dba4caa89.tar.gz redmine-144ca23442a5e123935dea4073670d4dba4caa89.zip |
Coderay upgraded to 0.9.7 (#5344).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4739 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor/gems/coderay-0.9.7/bin/coderay')
-rw-r--r-- | vendor/gems/coderay-0.9.7/bin/coderay | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/vendor/gems/coderay-0.9.7/bin/coderay b/vendor/gems/coderay-0.9.7/bin/coderay new file mode 100644 index 000000000..62101a83a --- /dev/null +++ b/vendor/gems/coderay-0.9.7/bin/coderay @@ -0,0 +1,86 @@ +#!/usr/bin/env ruby +# CodeRay Executable +# +# Version: 0.2 +# Author: murphy + +require 'coderay' + +if ARGV.empty? + $stderr.puts <<-USAGE +CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de) + +Usage: + coderay file [-<format>] + coderay -<lang> [-<format>] [< file] [> output] + +Defaults: + lang: based on file extension + format: ANSI colorized output for terminal, HTML page for files + +Examples: + coderay foo.rb # colorized output to terminal, based on file extension + coderay foo.rb -loc # print LOC count, based on file extension and format + coderay foo.rb > foo.html # HTML page output to file, based on extension + coderay -ruby < foo.rb # colorized output to terminal, based on lang + coderay -ruby -loc < foo.rb # print LOC count, based on lang + coderay -ruby -page foo.rb # HTML page output to terminal, based on lang and format + coderay -ruby -page foo.rb > foo.html # HTML page output to file, based on lang and format + USAGE +end + +first, second = ARGV + +def read + file = ARGV.grep(/^(?!-)/).last + if file + if File.exist?(file) + File.read file + else + $stderr.puts "No such file: #{file}" + end + else + $stdin.read + end +end + +if first + if first[/-(\w+)/] == first + lang = $1 + input = read + tokens = :scan + else + file = first + unless File.exist? file + $stderr.puts "No such file: #{file}" + exit 2 + end + tokens = CodeRay.scan_file file + end +else + $stderr.puts 'No lang/file given.' + exit 1 +end + +if second + if second[/-(\w+)/] == second + format = $1.to_sym + else + raise 'invalid format (must be -xxx)' + end +else + if $stdout.tty? + format = :term + else + $stderr.puts 'No format given; setting to default (HTML Page).' + format = :page + end +end + +if tokens == :scan + output = CodeRay::Duo[lang => format].highlight input +else + output = tokens.encode format +end +out = $stdout +out.puts output |