summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/coderay21
-rw-r--r--lib/coderay.rb2
-rw-r--r--lib/coderay/duo.rb1
-rw-r--r--lib/coderay/encoders/page.rb21
-rw-r--r--lib/coderay/helpers/plugin.rb2
-rw-r--r--rake_tasks/gem.rake13
6 files changed, 47 insertions, 13 deletions
diff --git a/bin/coderay b/bin/coderay
index a382a84..e0a4788 100644
--- a/bin/coderay
+++ b/bin/coderay
@@ -1,12 +1,9 @@
-#!C:/ruby/bin/ruby
-
+#!/usr/bin/env ruby
# CodeRay Executable
#
# Version: 0.1
# Author: murphy
-require 'optparse'
-
def err msg
$stderr.puts msg
end
@@ -18,8 +15,11 @@ begin
puts <<-USAGE
CodeRay #{CodeRay::Version} (http://rd.cYcnus.de/coderay)
Usage:
- coderay -lang [-format] < file > output
- coderay file [-format]
+ coderay -<lang> [-<format>] < file > output
+ coderay file [-<format>]
+Example:
+ coderay -ruby -statistic < foo.rb
+ coderay codegen.c # generates codegen.c.html
USAGE
end
@@ -40,7 +40,8 @@ Usage:
output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
end
else
- raise 'No lang/file given.'
+ puts 'No lang/file given.'
+ exit 1
end
if second
@@ -50,14 +51,14 @@ Usage:
raise 'Invalid format (must be -xxx).'
end
else
- $stderr.puts 'No format given; setting to default (HTML)'
- format = :html
+ $stderr.puts 'No format given; setting to default (HTML Page)'
+ format = :page
end
output = tokens.encode format
out = $stdout
if output_filename
- output_filename.sub output_ext, CodeRay::Encoders[format]::FILE_EXTENSION
+ output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
if File.exist? output_filename
err 'File %s already exists.' % output_filename
exit
diff --git a/lib/coderay.rb b/lib/coderay.rb
index a39d1cc..d503f03 100644
--- a/lib/coderay.rb
+++ b/lib/coderay.rb
@@ -133,7 +133,7 @@ module CodeRay
# Minor: odd for beta, even for stable
# Teeny: development state
# Revision: Subversion Revision number (generated on rake)
- Version = '0.7'
+ Version = '0.7.1'
require 'coderay/tokens'
require 'coderay/scanner'
diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb
index 1957c95..e4e80df 100644
--- a/lib/coderay/duo.rb
+++ b/lib/coderay/duo.rb
@@ -22,6 +22,7 @@ module CodeRay
@scanner.string = code
@encoder.encode_tokens(scanner.tokenize)
end
+ alias highlight encode
end
diff --git a/lib/coderay/encoders/page.rb b/lib/coderay/encoders/page.rb
new file mode 100644
index 0000000..74bdc55
--- /dev/null
+++ b/lib/coderay/encoders/page.rb
@@ -0,0 +1,21 @@
+module CodeRay
+module Encoders
+
+ load :html
+
+ class Page < HTML
+
+ FILE_EXTENSION = 'html'
+
+ register_for :page
+
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
+ :css => :class,
+ :wrap => :page,
+ :line_numbers => :table
+ })
+
+ end
+
+end
+end
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb
index 2b47d8e..938d1a8 100644
--- a/lib/coderay/helpers/plugin.rb
+++ b/lib/coderay/helpers/plugin.rb
@@ -235,7 +235,7 @@ protected
# Raises +ArgumentError+ for all other objects, or if the
# given String includes non-alphanumeric characters (\W).
def validate_id id
- if id.is_a? Symbol
+ if id.is_a? Symbol or id.nil?
id
elsif id.is_a? String
if id[/\w+/] == id
diff --git a/rake_tasks/gem.rake b/rake_tasks/gem.rake
index d41b5fe..fd34723 100644
--- a/rake_tasks/gem.rake
+++ b/rake_tasks/gem.rake
@@ -31,6 +31,7 @@ def gemspec
# Files
s.require_path = 'lib'
s.autorequire = 'coderay'
+ s.executables = [ 'coderay' ]
s.files = nil # defined later
@@ -49,8 +50,13 @@ namespace :gem do
end
desc 'Create the gem again'
- task :make => [:make_gemspec, :gem, :prepare_server]
+ task :make => [:make_gemspec, :clean, :gem, :prepare_server]
+ desc 'Delete previously created Gems'
+ task :clean do
+ Dir['pkg/*.gem'].each { |g| rm g }
+ end
+
desc 'Find out the current CodeRay version'
task :get_version do
unless $version
@@ -100,4 +106,9 @@ namespace :gem do
gn 'Gem successfully uploaded.'
end
+ desc 'Build the Gem and install it locally'
+ task :install => :make do
+ system "ruby -S gem install --no-rdoc pkg/#{$gemfile}"
+ end
+
end