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 CHANGED
@@ -4,97 +4,83 @@
4
4
  # Version: 0.2
5
5
  # Author: murphy
6
6
 
7
- def err msg
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
- begin
20
- require 'coderay'
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 -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
37
- end
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
- first, second = ARGV
32
+ first, second = ARGV
40
33
 
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
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 = first
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
- puts 'No lang/file given.'
57
- exit 1
43
+ $stdin.read
58
44
  end
45
+ end
59
46
 
60
- if second
61
- if second[/-(\w+)/] == second
62
- format = $1
63
- else
64
- raise 'invalid format (must be -xxx)'
65
- end
47
+ if first
48
+ if first[/-(\w+)/] == first
49
+ lang = $1
50
+ input = read
51
+ tokens = :scan
66
52
  else
67
- if $stdout.tty?
68
- format = :term
69
- else
70
- $stderr.puts 'No format given; setting to default (HTML Page).'
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
- # TODO: allow streaming
76
- if tokens == :scan
77
- output = CodeRay::Duo[lang => format].highlight input #, :stream => true
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
- output = tokens.encode format
69
+ raise 'invalid format (must be -xxx)'
80
70
  end
81
- out = $stdout
82
- if output_filename
83
- output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
84
- if File.exist? output_filename
85
- err 'File %s already exists.' % output_filename
86
- exit
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
- out.puts output
78
+ end
93
79
 
94
- rescue => boom
95
- err "Error: #{boom.message}\n"
96
- err boom.backtrace
97
- err '-' * 50
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
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.3
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(/(@@)((?>[^@\n]*))(@@)/)
51
- tokens << [:begin_line, line_kind = :change]
52
- tokens << [self[1], :change]
53
- tokens << [self[2], :plain]
54
- tokens << [self[3], :change]
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(/\+/)
@@ -91,7 +91,7 @@ module Scanners
91
91
  end
92
92
 
93
93
  when :attribute
94
- if scan(/#{TAG_END}/)
94
+ if scan(/#{TAG_END}/o)
95
95
  kind = :tag
96
96
  state = :initial
97
97
  elsif scan(/#{ATTR_NAME}/o)
@@ -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
- @ruby_scanner.tokenize code
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.3'
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
- - 3
9
- version: 0.9.3
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-04-19 00:00:00 +02:00
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.6
143
+ rubygems_version: 1.3.7
137
144
  signing_key:
138
145
  specification_version: 3
139
146
  summary: Fast syntax highlighting for selected languages.