coderay 1.0.0 → 1.0.0.598.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/FOLDERS +49 -0
- data/Rakefile +6 -5
- data/bin/coderay +74 -190
- data/bin/coderay_stylesheet +4 -0
- data/{README_INDEX.rdoc → lib/README} +20 -10
- data/lib/coderay.rb +60 -62
- data/lib/coderay/duo.rb +55 -2
- data/lib/coderay/encoder.rb +39 -52
- data/lib/coderay/encoders/_map.rb +7 -11
- data/lib/coderay/encoders/comment_filter.rb +61 -0
- data/lib/coderay/encoders/count.rb +26 -11
- data/lib/coderay/encoders/debug.rb +60 -11
- data/lib/coderay/encoders/div.rb +8 -9
- data/lib/coderay/encoders/filter.rb +52 -12
- data/lib/coderay/encoders/html.rb +113 -106
- data/lib/coderay/encoders/html/css.rb +7 -2
- data/lib/coderay/encoders/html/numbering.rb +27 -24
- data/lib/coderay/encoders/html/output.rb +58 -15
- data/lib/coderay/encoders/json.rb +44 -37
- data/lib/coderay/encoders/lines_of_code.rb +56 -9
- data/lib/coderay/encoders/null.rb +13 -6
- data/lib/coderay/encoders/page.rb +8 -8
- data/lib/coderay/encoders/span.rb +9 -10
- data/lib/coderay/encoders/statistic.rb +114 -51
- data/lib/coderay/encoders/terminal.rb +10 -7
- data/lib/coderay/encoders/text.rb +36 -17
- data/lib/coderay/encoders/token_kind_filter.rb +58 -1
- data/lib/coderay/encoders/xml.rb +11 -13
- data/lib/coderay/encoders/yaml.rb +14 -16
- data/lib/coderay/for_redcloth.rb +1 -1
- data/lib/coderay/helpers/file_type.rb +240 -125
- data/lib/coderay/helpers/gzip_simple.rb +123 -0
- data/lib/coderay/helpers/plugin.rb +307 -241
- data/lib/coderay/helpers/word_list.rb +126 -65
- data/lib/coderay/scanner.rb +103 -153
- data/lib/coderay/scanners/_map.rb +16 -18
- data/lib/coderay/scanners/c.rb +13 -13
- data/lib/coderay/scanners/cpp.rb +6 -6
- data/lib/coderay/scanners/css.rb +48 -47
- data/lib/coderay/scanners/debug.rb +55 -9
- data/lib/coderay/scanners/delphi.rb +4 -4
- data/lib/coderay/scanners/diff.rb +25 -43
- data/lib/coderay/scanners/groovy.rb +2 -2
- data/lib/coderay/scanners/html.rb +30 -107
- data/lib/coderay/scanners/java.rb +5 -6
- data/lib/coderay/scanners/java/builtin_types.rb +0 -2
- data/lib/coderay/scanners/java_script.rb +6 -6
- data/lib/coderay/scanners/json.rb +6 -7
- data/lib/coderay/scanners/nitro_xhtml.rb +136 -0
- data/lib/coderay/scanners/php.rb +12 -13
- data/lib/coderay/scanners/plaintext.rb +26 -0
- data/lib/coderay/scanners/python.rb +4 -4
- data/lib/coderay/scanners/{erb.rb → rhtml.rb} +11 -19
- data/lib/coderay/scanners/ruby.rb +208 -219
- data/lib/coderay/scanners/ruby/patterns.rb +85 -18
- data/lib/coderay/scanners/scheme.rb +136 -0
- data/lib/coderay/scanners/sql.rb +22 -29
- data/lib/coderay/scanners/yaml.rb +10 -11
- data/lib/coderay/styles/_map.rb +2 -2
- data/lib/coderay/styles/alpha.rb +104 -102
- data/lib/coderay/styles/cycnus.rb +143 -0
- data/lib/coderay/styles/murphy.rb +123 -0
- data/lib/coderay/token_kinds.rb +86 -87
- data/lib/coderay/tokens.rb +169 -26
- data/test/functional/basic.rb +14 -200
- data/test/functional/examples.rb +14 -20
- data/test/functional/for_redcloth.rb +8 -15
- data/test/functional/load_plugin_scanner.rb +11 -0
- data/test/functional/suite.rb +6 -9
- data/test/functional/vhdl.rb +126 -0
- data/test/functional/word_list.rb +79 -0
- metadata +129 -107
- data/lib/coderay/helpers/gzip.rb +0 -41
- data/lib/coderay/scanners/clojure.rb +0 -217
- data/lib/coderay/scanners/haml.rb +0 -168
- data/lib/coderay/scanners/ruby/string_state.rb +0 -71
- data/lib/coderay/scanners/text.rb +0 -26
- data/lib/coderay/tokens_proxy.rb +0 -55
- data/lib/coderay/version.rb +0 -3
data/FOLDERS
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= CodeRay - folder structure
|
2
|
+
|
3
|
+
== bench - Benchmarking system
|
4
|
+
|
5
|
+
All benchmarking stuff goes here.
|
6
|
+
|
7
|
+
Test inputs are stored in files named <code>example.<lang></code>.
|
8
|
+
Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
|
9
|
+
|
10
|
+
Run <code>bench/bench.rb</code> to get a usage description.
|
11
|
+
|
12
|
+
Run <code>rake bench</code> to perform an example benchmark.
|
13
|
+
|
14
|
+
|
15
|
+
== bin - Scripts
|
16
|
+
|
17
|
+
Executional files for CodeRay.
|
18
|
+
|
19
|
+
coderay:: The CodeRay executable.
|
20
|
+
coderay_stylesheet:: Prints the default stylesheet.
|
21
|
+
|
22
|
+
== demo - Demos and functional tests
|
23
|
+
|
24
|
+
Demonstrational scripts to show of CodeRay's features.
|
25
|
+
|
26
|
+
Run them as functional tests with <code>rake test:demos</code>.
|
27
|
+
|
28
|
+
|
29
|
+
== etc - Lots of stuff
|
30
|
+
|
31
|
+
Some addidtional files for CodeRay, mainly graphics and Vim scripts.
|
32
|
+
|
33
|
+
|
34
|
+
== lib - CodeRay library code
|
35
|
+
|
36
|
+
This is the base directory for the CodeRay library.
|
37
|
+
|
38
|
+
|
39
|
+
== rake_helpers - Rake helper libraries
|
40
|
+
|
41
|
+
Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
|
42
|
+
|
43
|
+
|
44
|
+
== test - Tests
|
45
|
+
|
46
|
+
In the subfolder scanners/ are the scanners tests.
|
47
|
+
Each language has its own subfolder and sub-suite.
|
48
|
+
|
49
|
+
Run with <code>rake test</code>.
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__) unless $:.include? '.'
|
2
|
+
require 'rake/rdoctask'
|
2
3
|
|
3
4
|
ROOT = '.'
|
4
5
|
LIB_ROOT = File.join ROOT, 'lib'
|
6
|
+
EXTRA_RDOC_FILES = %w(lib/README FOLDERS)
|
5
7
|
|
6
8
|
task :default => :test
|
7
9
|
|
@@ -14,21 +16,20 @@ if File.directory? 'rake_tasks'
|
|
14
16
|
|
15
17
|
else
|
16
18
|
|
17
|
-
# fallback tasks when rake_tasks folder is not present
|
19
|
+
# fallback tasks when rake_tasks folder is not present
|
18
20
|
desc 'Run CodeRay tests (basic)'
|
19
21
|
task :test do
|
20
22
|
ruby './test/functional/suite.rb'
|
21
23
|
ruby './test/functional/for_redcloth.rb'
|
22
24
|
end
|
23
25
|
|
24
|
-
gem 'rdoc' if defined? gem
|
25
|
-
require 'rdoc/task'
|
26
26
|
desc 'Generate documentation for CodeRay'
|
27
27
|
Rake::RDocTask.new :doc do |rd|
|
28
28
|
rd.title = 'CodeRay Documentation'
|
29
|
-
rd.main = '
|
29
|
+
rd.main = 'lib/README'
|
30
30
|
rd.rdoc_files.add Dir['lib']
|
31
|
-
rd.rdoc_files.add
|
31
|
+
rd.rdoc_files.add 'lib/README'
|
32
|
+
rd.rdoc_files.add 'FOLDERS'
|
32
33
|
rd.rdoc_dir = 'doc'
|
33
34
|
end
|
34
35
|
|
data/bin/coderay
CHANGED
@@ -1,215 +1,99 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# CodeRay Executable
|
3
|
+
#
|
4
|
+
# Version: 0.2
|
5
|
+
# Author: murphy
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
subcommand = nil if subcommand && File.exist?(subcommand)
|
7
|
-
args.delete subcommand
|
8
|
-
|
9
|
-
def option? *options
|
10
|
-
!($options & options).empty?
|
11
|
-
end
|
12
|
-
|
13
|
-
def tty?
|
14
|
-
$stdout.tty? || option?('--tty')
|
7
|
+
def err msg
|
8
|
+
$stderr.puts msg
|
15
9
|
end
|
16
10
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def read
|
12
|
+
if file = ARGV[2]
|
13
|
+
File.read file
|
14
|
+
else
|
15
|
+
$stdin.read
|
16
|
+
end
|
21
17
|
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
This is CodeRay #{CodeRay::VERSION}, a syntax highlighting tool for selected languages.
|
26
|
-
|
27
|
-
usage:
|
28
|
-
coderay [-language] [input] [-format] [output]
|
29
|
-
|
30
|
-
defaults:
|
31
|
-
language detect from input file name or shebang; fall back to plain text
|
32
|
-
input STDIN
|
33
|
-
format detect from output file name or use terminal; fall back to HTML
|
34
|
-
output STDOUT
|
35
|
-
|
36
|
-
common:
|
37
|
-
coderay file.rb # highlight file to terminal
|
38
|
-
coderay file.rb > file.html # highlight file to HTML page
|
39
|
-
coderay file.rb -div > file.html # highlight file to HTML snippet
|
40
|
-
|
41
|
-
configure output:
|
42
|
-
coderay file.py output.json # output tokens as JSON
|
43
|
-
coderay file.py -loc # count lines of code in Python file
|
44
|
-
|
45
|
-
configure input:
|
46
|
-
coderay -python file # specify the input language
|
47
|
-
coderay -ruby # take input from STDIN
|
19
|
+
begin
|
20
|
+
require 'coderay'
|
48
21
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
22
|
+
if ARGV.empty?
|
23
|
+
puts <<-USAGE
|
24
|
+
CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
|
53
25
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
highlight code highlighting (default command, optional)
|
58
|
-
stylesheet print the CSS stylesheet with the given name (aliases: style, css)
|
59
|
-
|
60
|
-
about:
|
61
|
-
list [of] list all available plugins (or just the scanners|encoders|styles|filetypes)
|
62
|
-
commands print this list
|
63
|
-
help show some help
|
64
|
-
version print CodeRay version
|
65
|
-
COMMANDS
|
66
|
-
end
|
26
|
+
Usage:
|
27
|
+
coderay -<lang> [-<format>] < file > output
|
28
|
+
coderay file [-<format>]
|
67
29
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
additional_info << aliases.join(', ') unless aliases.empty?
|
76
|
-
info << " (#{additional_info.join('; ')})"
|
77
|
-
end
|
78
|
-
|
79
|
-
info << ' <-- default' if plugin.aliases.include? :default
|
80
|
-
|
81
|
-
info
|
30
|
+
Examples:
|
31
|
+
coderay -ruby -statistic < foo.rb
|
32
|
+
coderay -ruby < foo.rb # colorized output to terminal
|
33
|
+
coderay -ruby -page foo.rb # HTML page output to terminal
|
34
|
+
coderay -ruby -page foo.rb > foo.html # HTML page output to file
|
35
|
+
coderay codegen.c # generates codegen.c.html
|
36
|
+
USAGE
|
82
37
|
end
|
83
|
-
puts plugins.sort
|
84
|
-
end
|
85
38
|
|
86
|
-
|
87
|
-
version
|
88
|
-
end
|
39
|
+
first, second = ARGV
|
89
40
|
|
90
|
-
if
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
else
|
100
|
-
signature = args.map { |arg| arg[/^-/] ? '-' : 'f' }.join
|
101
|
-
names = args.map { |arg| arg.sub(/^-/, '') }
|
102
|
-
case signature
|
103
|
-
when /^$/
|
104
|
-
exit
|
105
|
-
when /^ff?$/
|
106
|
-
input_file, output_file, = *names
|
107
|
-
when /^f-f?$/
|
108
|
-
input_file, output_format, output_file, = *names
|
109
|
-
when /^-ff?$/
|
110
|
-
input_lang, input_file, output_file, = *names
|
111
|
-
when /^-f-f?$/
|
112
|
-
input_lang, input_file, output_format, output_file, = *names
|
113
|
-
when /^--?f?$/
|
114
|
-
input_lang, output_format, output_file, = *names
|
41
|
+
if first
|
42
|
+
if first[/-(\w+)/] == first
|
43
|
+
lang = $1
|
44
|
+
input = read
|
45
|
+
tokens = :scan
|
46
|
+
elsif first == '-'
|
47
|
+
lang = $1
|
48
|
+
input = read
|
49
|
+
tokens = :scan
|
115
50
|
else
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
puts "Unknown parameter order: #{args.join ' '}, expected: [-language] [input] [-format] [output]"
|
120
|
-
exit 1
|
121
|
-
end
|
122
|
-
|
123
|
-
if input_file
|
124
|
-
input_lang ||= CodeRay::FileType.fetch input_file, :text, true
|
51
|
+
file = first
|
52
|
+
tokens = CodeRay.scan_file file
|
53
|
+
output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
|
125
54
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
55
|
+
else
|
56
|
+
puts 'No lang/file given.'
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
if second
|
61
|
+
if second[/-(\w+)/] == second
|
62
|
+
format = $1
|
129
63
|
else
|
130
|
-
|
64
|
+
raise 'invalid format (must be -xxx)'
|
131
65
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
if input_file
|
136
|
-
input = File.read input_file
|
66
|
+
else
|
67
|
+
if $stdout.tty?
|
68
|
+
format = :term
|
137
69
|
else
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
begin
|
142
|
-
file =
|
143
|
-
if output_file
|
144
|
-
File.open output_file, 'w'
|
145
|
-
else
|
146
|
-
$stdout.sync = true
|
147
|
-
$stdout
|
148
|
-
end
|
149
|
-
CodeRay.encode(input, input_lang, output_format, :out => file)
|
150
|
-
file.puts
|
151
|
-
rescue CodeRay::PluginHost::PluginNotFound => boom
|
152
|
-
$stdout = $stderr
|
153
|
-
if boom.message[/CodeRay::(\w+)s could not load plugin :?(.*?): /]
|
154
|
-
puts "I don't know the #$1 \"#$2\"."
|
155
|
-
else
|
156
|
-
puts boom.message
|
157
|
-
end
|
158
|
-
# puts "I don't know this plugin: #{boom.message[/Could not load plugin (.*?): /, 1]}."
|
159
|
-
rescue CodeRay::Scanners::Scanner::ScanError # FIXME: rescue Errno::EPIPE
|
160
|
-
# this is sometimes raised by pagers; ignore [TODO: wtf?]
|
161
|
-
ensure
|
162
|
-
file.close if output_file
|
70
|
+
$stderr.puts 'No format given; setting to default (HTML Page).'
|
71
|
+
format = :page
|
163
72
|
end
|
164
73
|
end
|
165
|
-
when 'li', 'list'
|
166
|
-
arg = args.first && args.first.downcase
|
167
|
-
if [nil, 's', 'sc', 'scanner', 'scanners'].include? arg
|
168
|
-
puts 'input languages (Scanners):'
|
169
|
-
print_list_of CodeRay::Scanners
|
170
|
-
end
|
171
|
-
|
172
|
-
if [nil, 'e', 'en', 'enc', 'encoder', 'encoders'].include? arg
|
173
|
-
puts 'output formats (Encoders):'
|
174
|
-
print_list_of CodeRay::Encoders
|
175
|
-
end
|
176
74
|
|
177
|
-
if
|
178
|
-
|
179
|
-
|
75
|
+
if tokens == :scan
|
76
|
+
output = CodeRay::Duo[lang => format].highlight input
|
77
|
+
else
|
78
|
+
output = tokens.encode format
|
180
79
|
end
|
181
|
-
|
182
|
-
if
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
CodeRay::FileType::TypeFromName.inject filetypes do |types, (name, type)|
|
191
|
-
types[type.to_s] << name
|
192
|
-
types
|
193
|
-
end
|
194
|
-
|
195
|
-
filetypes.sort.each do |type, exts|
|
196
|
-
puts " #{type}: #{exts.sort_by { |ext| ext.size }.join(', ')}"
|
80
|
+
out = $stdout
|
81
|
+
if output_filename
|
82
|
+
output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION.to_s
|
83
|
+
if File.exist? output_filename
|
84
|
+
err 'File %s already exists.' % output_filename
|
85
|
+
exit
|
86
|
+
else
|
87
|
+
out = File.open output_filename, 'w'
|
88
|
+
puts "Writing to #{output_filename}..."
|
197
89
|
end
|
198
90
|
end
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
$stdout = $stderr
|
207
|
-
help
|
208
|
-
puts
|
209
|
-
if subcommand[/\A\w+\z/]
|
210
|
-
puts "Unknown command: #{subcommand}"
|
211
|
-
else
|
212
|
-
puts "File not found: #{subcommand}"
|
213
|
-
end
|
91
|
+
out.puts output
|
92
|
+
|
93
|
+
rescue => boom
|
94
|
+
err "Error: #{boom.message}\n"
|
95
|
+
err boom.backtrace
|
96
|
+
err '-' * 50
|
97
|
+
err ARGV
|
214
98
|
exit 1
|
215
99
|
end
|
@@ -1,45 +1,57 @@
|
|
1
1
|
= CodeRay
|
2
2
|
|
3
|
-
Tired of blue'n'gray? Try the original version of this documentation on
|
4
|
-
coderay.rubychan.de[http://coderay.rubychan.de/doc/]
|
3
|
+
[- Tired of blue'n'gray? Try the original version of this documentation on
|
4
|
+
coderay.rubychan.de[http://coderay.rubychan.de/doc/] (use Ctrl+Click to open it in its own frame.) -]
|
5
5
|
|
6
6
|
== About
|
7
|
-
|
8
7
|
CodeRay is a Ruby library for syntax highlighting.
|
9
8
|
|
10
|
-
You put your code in, and you get it back colored;
|
11
|
-
floats, comments - all in different colors.
|
9
|
+
Syntax highlighting means: You put your code in, and you get it back colored;
|
10
|
+
Keywords, strings, floats, comments - all in different colors.
|
11
|
+
And with line numbers.
|
12
12
|
|
13
13
|
*Syntax* *Highlighting*...
|
14
14
|
* makes code easier to read and maintain
|
15
15
|
* lets you detect syntax errors faster
|
16
16
|
* helps you to understand the syntax of a language
|
17
17
|
* looks nice
|
18
|
-
* is what everybody
|
18
|
+
* is what everybody should have on their website
|
19
19
|
* solves all your problems and makes the girls run after you
|
20
20
|
|
21
|
+
Version: 0.9.2
|
22
|
+
Author:: murphy (Kornelius Kalnbach)
|
23
|
+
Contact:: murphy rubychan de
|
24
|
+
Website:: coderay.rubychan.de[http://coderay.rubychan.de]
|
25
|
+
License:: GNU LGPL; see LICENSE file in the main directory.
|
21
26
|
|
22
27
|
== Installation
|
23
28
|
|
29
|
+
You need RubyGems[http://rubyforge.org/frs/?group_id=126].
|
30
|
+
|
24
31
|
% gem install coderay
|
25
32
|
|
26
33
|
|
27
34
|
=== Dependencies
|
28
35
|
|
29
|
-
CodeRay needs Ruby 1.8.
|
36
|
+
CodeRay needs Ruby 1.8.6 or later. It also runs with Ruby 1.9.1+ and JRuby 1.1+.
|
30
37
|
|
31
38
|
|
32
39
|
== Example Usage
|
40
|
+
(Forgive me, but this is not highlighted.)
|
33
41
|
|
34
42
|
require 'coderay'
|
35
43
|
|
36
|
-
|
44
|
+
tokens = CodeRay.scan "puts 'Hello, world!'", :ruby
|
45
|
+
page = tokens.html :line_numbers => :inline, :wrap => :page
|
46
|
+
puts page
|
37
47
|
|
38
48
|
|
39
49
|
== Documentation
|
40
50
|
|
41
51
|
See CodeRay.
|
42
52
|
|
53
|
+
Please report errors in this documentation to <murphy rubychan de>.
|
54
|
+
|
43
55
|
|
44
56
|
== Credits
|
45
57
|
|
@@ -111,8 +123,6 @@ Where would we be without all those people?
|
|
111
123
|
less useless
|
112
124
|
* Term::ANSIColor[http://term-ansicolor.rubyforge.org/]
|
113
125
|
* PLEAC[http://pleac.sourceforge.net/] code examples
|
114
|
-
* Github
|
115
|
-
* Travis CI (http://travis-ci.org/rubychan/github)
|
116
126
|
|
117
127
|
=== Free
|
118
128
|
|