[DRE-commits] r4041 - in branches: . upstream upstream/coderay upstream/coderay/current upstream/coderay/current/bin

Joshua Timberman jtimberman-guest at alioth.debian.org
Mon Aug 31 04:01:57 UTC 2009


Author: jtimberman-guest
Date: 2009-08-31 04:01:56 +0000 (Mon, 31 Aug 2009)
New Revision: 4041

Added:
   branches/upstream/
   branches/upstream/coderay/
   branches/upstream/coderay/current/
   branches/upstream/coderay/current/bin/
   branches/upstream/coderay/current/bin/coderay
   branches/upstream/coderay/current/bin/coderay_stylesheet
Log:
[svn-inject] Installing original source of coderay

Added: branches/upstream/coderay/current/bin/coderay
===================================================================
--- branches/upstream/coderay/current/bin/coderay	                        (rev 0)
+++ branches/upstream/coderay/current/bin/coderay	2009-08-31 04:01:56 UTC (rev 4041)
@@ -0,0 +1,82 @@
+#!/usr/bin/env ruby
+# CodeRay Executable
+#
+# Version: 0.1
+# Author: murphy
+
+def err msg
+  $stderr.puts msg
+end
+
+begin
+  require 'coderay'
+
+  if ARGV.empty?
+    puts <<-USAGE
+CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
+Usage:
+  coderay -<lang> [-<format>] < file > output
+  coderay file [-<format>]
+Example:
+  coderay -ruby -statistic < foo.rb
+  coderay codegen.c  # generates codegen.c.html
+    USAGE
+  end
+
+  first, second = ARGV
+
+  if first
+    if first[/-(\w+)/] == first
+      lang = $1
+      input = $stdin.read
+      tokens = :scan
+    elsif first == '-'
+      lang = $1
+      input = $stdin.read
+      tokens = :scan
+    else
+      file = first
+      tokens = CodeRay.scan_file file
+      output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
+    end
+  else
+    puts 'No lang/file given.'
+    exit 1
+  end
+
+  if second
+    if second[/-(\w+)/] == second
+      format = $1
+    else
+      raise 'Invalid format (must be -xxx).'
+    end
+  else
+    $stderr.puts 'No format given; setting to default (HTML Page)'
+    format = :page
+  end
+  
+  # TODO: allow streaming
+  if tokens == :scan
+    output = CodeRay::Duo[lang => format].highlight input  #, :stream => true
+  else
+    output = tokens.encode format
+  end
+  out = $stdout
+  if output_filename
+    output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
+    if File.exist? output_filename
+      err 'File %s already exists.' % output_filename
+      exit
+    else
+      out = File.open output_filename, 'w'
+    end
+  end
+  out.print output
+
+rescue => boom
+  err "Error: #{boom.message}\n"
+  err boom.backtrace
+  err '-' * 50
+  err ARGV
+  exit 1
+end

Added: branches/upstream/coderay/current/bin/coderay_stylesheet
===================================================================
--- branches/upstream/coderay/current/bin/coderay_stylesheet	                        (rev 0)
+++ branches/upstream/coderay/current/bin/coderay_stylesheet	2009-08-31 04:01:56 UTC (rev 4041)
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require 'coderay'
+
+puts CodeRay::Encoders[:html]::CSS.new.stylesheet




More information about the Pkg-ruby-extras-commits mailing list