coderay 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/coderay +58 -72
- data/bin/coderay_stylesheet +0 -0
- data/lib/README +1 -1
- data/lib/coderay/scanners/diff.rb +10 -5
- data/lib/coderay/scanners/html.rb +1 -1
- data/lib/coderay/scanners/rhtml.rb +6 -2
- data/lib/coderay.rb +1 -1
- metadata +11 -4
data/bin/coderay
CHANGED
@@ -4,97 +4,83 @@
|
|
4
4
|
# Version: 0.2
|
5
5
|
# Author: murphy
|
6
6
|
|
7
|
-
|
8
|
-
$stderr.puts msg
|
9
|
-
end
|
10
|
-
|
11
|
-
def read
|
12
|
-
if file = ARGV[2]
|
13
|
-
File.read file
|
14
|
-
else
|
15
|
-
$stdin.read
|
16
|
-
end
|
17
|
-
end
|
7
|
+
require 'coderay'
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if ARGV.empty?
|
23
|
-
puts <<-USAGE
|
9
|
+
if ARGV.empty?
|
10
|
+
$stderr.puts <<-USAGE
|
24
11
|
CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
|
25
12
|
|
26
13
|
Usage:
|
27
|
-
coderay -<lang> [-<format>] < file > output
|
28
14
|
coderay file [-<format>]
|
15
|
+
coderay -<lang> [-<format>] [< file] [> output]
|
16
|
+
|
17
|
+
Defaults:
|
18
|
+
lang: based on file extension
|
19
|
+
format: ANSI colorized output for terminal, HTML page for files
|
29
20
|
|
30
21
|
Examples:
|
31
|
-
coderay
|
32
|
-
coderay
|
33
|
-
coderay
|
34
|
-
coderay -ruby
|
35
|
-
coderay
|
36
|
-
|
37
|
-
|
22
|
+
coderay foo.rb # colorized output to terminal, based on file extension
|
23
|
+
coderay foo.rb -loc # print LOC count, based on file extension and format
|
24
|
+
coderay foo.rb > foo.html # HTML page output to file, based on extension
|
25
|
+
coderay -ruby < foo.rb # colorized output to terminal, based on lang
|
26
|
+
coderay -ruby -loc < foo.rb # print LOC count, based on lang
|
27
|
+
coderay -ruby -page foo.rb # HTML page output to terminal, based on lang and format
|
28
|
+
coderay -ruby -page foo.rb > foo.html # HTML page output to file, based on lang and format
|
29
|
+
USAGE
|
30
|
+
end
|
38
31
|
|
39
|
-
|
32
|
+
first, second = ARGV
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
elsif first == '-'
|
47
|
-
lang = $1
|
48
|
-
input = read
|
49
|
-
tokens = :scan
|
34
|
+
def read
|
35
|
+
file = ARGV.grep(/^(?!-)/).last
|
36
|
+
if file
|
37
|
+
if File.exist?(file)
|
38
|
+
File.read file
|
50
39
|
else
|
51
|
-
file
|
52
|
-
tokens = CodeRay.scan_file file
|
53
|
-
output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
|
40
|
+
$stderr.puts "No such file: #{file}"
|
54
41
|
end
|
55
42
|
else
|
56
|
-
|
57
|
-
exit 1
|
43
|
+
$stdin.read
|
58
44
|
end
|
45
|
+
end
|
59
46
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
47
|
+
if first
|
48
|
+
if first[/-(\w+)/] == first
|
49
|
+
lang = $1
|
50
|
+
input = read
|
51
|
+
tokens = :scan
|
66
52
|
else
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
format = :page
|
53
|
+
file = first
|
54
|
+
unless File.exist? file
|
55
|
+
$stderr.puts "No such file: #{file}"
|
56
|
+
exit 2
|
72
57
|
end
|
58
|
+
tokens = CodeRay.scan_file file
|
73
59
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
60
|
+
else
|
61
|
+
$stderr.puts 'No lang/file given.'
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
|
65
|
+
if second
|
66
|
+
if second[/-(\w+)/] == second
|
67
|
+
format = $1.to_sym
|
78
68
|
else
|
79
|
-
|
69
|
+
raise 'invalid format (must be -xxx)'
|
80
70
|
end
|
81
|
-
|
82
|
-
if
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
else
|
88
|
-
out = File.open output_filename, 'w'
|
89
|
-
puts "Writing to #{output_filename}..."
|
90
|
-
end
|
71
|
+
else
|
72
|
+
if $stdout.tty?
|
73
|
+
format = :term
|
74
|
+
else
|
75
|
+
$stderr.puts 'No format given; setting to default (HTML Page).'
|
76
|
+
format = :page
|
91
77
|
end
|
92
|
-
|
78
|
+
end
|
93
79
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
err ARGV
|
99
|
-
exit 1
|
80
|
+
if tokens == :scan
|
81
|
+
output = CodeRay::Duo[lang => format].highlight input
|
82
|
+
else
|
83
|
+
output = tokens.encode format
|
100
84
|
end
|
85
|
+
out = $stdout
|
86
|
+
out.puts output
|
data/bin/coderay_stylesheet
CHANGED
File without changes
|
data/lib/README
CHANGED
@@ -18,7 +18,7 @@ And with line numbers.
|
|
18
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.
|
21
|
+
Version: 0.9.4
|
22
22
|
Author:: murphy (Kornelius Kalnbach)
|
23
23
|
Contact:: murphy rubychan de
|
24
24
|
Website:: coderay.rubychan.de[http://coderay.rubychan.de]
|
@@ -47,11 +47,16 @@ module Scanners
|
|
47
47
|
tokens << [match, :change]
|
48
48
|
next unless match = scan(/.+/)
|
49
49
|
kind = :plain
|
50
|
-
elsif scan(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
elsif match = scan(/@@(?>[^@\n]*)@@/)
|
51
|
+
if check(/\n|$/)
|
52
|
+
tokens << [:begin_line, line_kind = :change]
|
53
|
+
else
|
54
|
+
tokens << [:open, :change]
|
55
|
+
end
|
56
|
+
tokens << [match[0,2], :change]
|
57
|
+
tokens << [match[2...-2], :plain]
|
58
|
+
tokens << [match[-2,2], :change]
|
59
|
+
tokens << [:close, :change] unless line_kind
|
55
60
|
next unless match = scan(/.+/)
|
56
61
|
kind = :plain
|
57
62
|
elsif match = scan(/\+/)
|
@@ -49,12 +49,16 @@ module Scanners
|
|
49
49
|
@html_scanner.tokenize match
|
50
50
|
|
51
51
|
elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
|
52
|
-
start_tag = match[/\A<%[
|
52
|
+
start_tag = match[/\A<%[-=#]?/]
|
53
53
|
end_tag = match[/-?%?>?\z/]
|
54
54
|
tokens << [:open, :inline]
|
55
55
|
tokens << [start_tag, :inline_delimiter]
|
56
56
|
code = match[start_tag.size .. -1 - end_tag.size]
|
57
|
-
|
57
|
+
if start_tag == '<%#'
|
58
|
+
tokens << [code, :comment]
|
59
|
+
else
|
60
|
+
@ruby_scanner.tokenize code
|
61
|
+
end
|
58
62
|
tokens << [end_tag, :inline_delimiter] unless end_tag.empty?
|
59
63
|
tokens << [:close, :inline]
|
60
64
|
|
data/lib/coderay.rb
CHANGED
@@ -134,7 +134,7 @@ module CodeRay
|
|
134
134
|
# Minor: feature milestone
|
135
135
|
# Teeny: development state, 0 for pre-release
|
136
136
|
# Revision: Subversion Revision number (generated on rake gem:make)
|
137
|
-
VERSION = '0.9.
|
137
|
+
VERSION = '0.9.4'
|
138
138
|
|
139
139
|
require 'coderay/tokens'
|
140
140
|
require 'coderay/token_classes'
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 51
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
9
|
+
- 4
|
10
|
+
version: 0.9.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- murphy
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-01 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -103,6 +104,8 @@ files:
|
|
103
104
|
- ./LICENSE
|
104
105
|
- lib/README
|
105
106
|
- FOLDERS
|
107
|
+
- bin/coderay
|
108
|
+
- bin/coderay_stylesheet
|
106
109
|
has_rdoc: true
|
107
110
|
homepage: http://coderay.rubychan.de
|
108
111
|
licenses: []
|
@@ -115,25 +118,29 @@ rdoc_options:
|
|
115
118
|
require_paths:
|
116
119
|
- lib
|
117
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
118
122
|
requirements:
|
119
123
|
- - ">="
|
120
124
|
- !ruby/object:Gem::Version
|
125
|
+
hash: 51
|
121
126
|
segments:
|
122
127
|
- 1
|
123
128
|
- 8
|
124
129
|
- 2
|
125
130
|
version: 1.8.2
|
126
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
127
133
|
requirements:
|
128
134
|
- - ">="
|
129
135
|
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
130
137
|
segments:
|
131
138
|
- 0
|
132
139
|
version: "0"
|
133
140
|
requirements: []
|
134
141
|
|
135
142
|
rubyforge_project: coderay
|
136
|
-
rubygems_version: 1.3.
|
143
|
+
rubygems_version: 1.3.7
|
137
144
|
signing_key:
|
138
145
|
specification_version: 3
|
139
146
|
summary: Fast syntax highlighting for selected languages.
|