coderay 0.5.0.121 → 0.7.1.147

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/FOLDERS +53 -0
  2. data/README +21 -13
  3. data/bin/coderay +79 -0
  4. data/demo/demo_cache.rb +12 -0
  5. data/demo/demo_html_list.rb +12 -0
  6. data/lib/coderay.rb +11 -2
  7. data/lib/coderay/duo.rb +29 -0
  8. data/lib/coderay/encoder.rb +4 -4
  9. data/lib/coderay/encoders/_map.rb +6 -6
  10. data/lib/coderay/encoders/count.rb +3 -3
  11. data/lib/coderay/encoders/debug.rb +38 -30
  12. data/lib/coderay/encoders/div.rb +4 -2
  13. data/lib/coderay/encoders/html.rb +9 -19
  14. data/lib/coderay/encoders/html/classes.rb +5 -2
  15. data/lib/coderay/encoders/html/css.rb +5 -6
  16. data/lib/coderay/encoders/html/numerization.rb +28 -18
  17. data/lib/coderay/encoders/html/output.rb +4 -4
  18. data/lib/coderay/encoders/null.rb +16 -16
  19. data/lib/coderay/encoders/page.rb +21 -0
  20. data/lib/coderay/encoders/span.rb +6 -3
  21. data/lib/coderay/encoders/statistic.rb +4 -2
  22. data/lib/coderay/encoders/tokens.rb +35 -35
  23. data/lib/coderay/encoders/xml.rb +53 -52
  24. data/lib/coderay/encoders/yaml.rb +13 -10
  25. data/lib/coderay/helpers/filetype.rb +41 -5
  26. data/lib/coderay/helpers/gzip_simple.rb +1 -1
  27. data/lib/coderay/helpers/plugin.rb +33 -17
  28. data/lib/coderay/scanner.rb +60 -19
  29. data/lib/coderay/scanners/_map.rb +12 -8
  30. data/lib/coderay/scanners/c.rb +16 -8
  31. data/lib/coderay/scanners/delphi.rb +9 -3
  32. data/lib/coderay/scanners/html.rb +167 -0
  33. data/lib/coderay/scanners/nitro_html.rb +125 -0
  34. data/lib/coderay/scanners/plaintext.rb +4 -2
  35. data/lib/coderay/scanners/rhtml.rb +65 -0
  36. data/lib/coderay/scanners/ruby.rb +51 -39
  37. data/lib/coderay/scanners/ruby/patterns.rb +12 -9
  38. data/lib/coderay/scanners/xml.rb +18 -0
  39. data/lib/coderay/scanners/yaml.rb +85 -0
  40. data/lib/coderay/styles/_map.rb +7 -0
  41. data/lib/coderay/styles/cycnus.rb +105 -99
  42. data/lib/coderay/styles/murphy.rb +18 -18
  43. metadata +19 -6
data/FOLDERS ADDED
@@ -0,0 +1,53 @@
1
+ = CodeRay - Trunk 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
+
20
+ == demo - Demos and functional tests
21
+
22
+ Demonstrational scripts to show of CodeRay's features.
23
+
24
+ Run them as functional tests with <code>rake test:demos</code>.
25
+
26
+
27
+ == etc - Lots of stuff
28
+
29
+ Some addidtional files for CodeRay, mainly graphics and Vim scripts.
30
+
31
+
32
+ == gem_server - Gem output folder
33
+
34
+ For <code>rake gem</code>.
35
+
36
+
37
+ == lib - CodeRay library code
38
+
39
+ This is the base directory for the CodeRay library.
40
+
41
+
42
+ == rake_helpers - Rake helper libraries
43
+
44
+ Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
45
+
46
+
47
+ == test - Tests
48
+
49
+ Test for the scanners.
50
+
51
+ Each language has its own subfolder and sub-suite.
52
+
53
+ Run with <code>rake test</code>.
data/README CHANGED
@@ -11,20 +11,21 @@ Keywords, strings, floats, comments - all in different colors.
11
11
  And with line numbers.
12
12
 
13
13
  *Syntax* *Highlighting*...
14
- * makes code easier to read
15
- * lets you detect errors faster
14
+ * makes code easier to read and maintain
15
+ * lets you detect syntax errors faster
16
16
  * helps you to understand the syntax of a language
17
17
  * looks nice
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.5.0 (2006.march.16)
22
- Author:: murphy
23
- Idea:: licenser
24
- Website:: rd.cYcnus.de/coderay[http://rd.cYcnus.de/coderay]
21
+ Version: 0.5.0 (2006.april.16)
22
+ Author:: murphy (Kornelius Kalnbach)
23
+ Contact:: murphy rubychan de
24
+ Website:: coderay.rubychan.de[http://coderay.rubychan.de]
25
+ Old Website:: rd.cYcnus.de/coderay[http://rd.cYcnus.de/coderay]
25
26
  Copyright:: (c) 2006 by cYcnus
26
27
  License:: GNU LGPL; see LICENSE file in the main directory.
27
- Subversion:: $Id: README 119 2006-03-16 00:43:02Z murphy $
28
+ Subversion:: $Id: README 139 2006-04-16 04:31:10Z murphy $
28
29
 
29
30
  -----
30
31
 
@@ -34,10 +35,15 @@ You need RubyGems[http://rubyforge.org/frs/?group_id=126].
34
35
 
35
36
  % gem install coderay
36
37
 
38
+ Since CodeRay is still in beta stage, nightly buildy may be useful:
39
+
40
+ % gem install coderay -rs rd.cYcnus.de/coderay
41
+
37
42
 
38
43
  === Dependencies
39
44
 
40
- CodeRay needs Ruby 1.8 and the strscan[http://www.ruby-doc.org/stdlib/libdoc/strscan/rdoc/index.htm] library included.
45
+ CodeRay needs Ruby 1.8 and the strscan[http://www.ruby-doc.org/stdlib/libdoc/strscan/rdoc/index.htm] library
46
+ (part of the standard library.)
41
47
 
42
48
 
43
49
  == Example Usage
@@ -45,8 +51,9 @@ CodeRay needs Ruby 1.8 and the strscan[http://www.ruby-doc.org/stdlib/libdoc/str
45
51
 
46
52
  require 'coderay'
47
53
 
48
- hl = CodeRay.html :line_numbers => :table
49
- puts hl.highlight_page "puts 'Hello, world!'", :ruby
54
+ tokens = CodeRay.scan "puts 'Hello, world!'", :ruby
55
+ page = tokens.html :line_numbers => :inline, :wrap => :page
56
+ puts page
50
57
 
51
58
 
52
59
  == Documentation
@@ -74,9 +81,10 @@ Please report errors in this documentation to <coderay cycnus de>.
74
81
  * Doug Kearns and everyone else who worked on ruby.vim - it not only helped me coding CodeRay,
75
82
  but also gave me a wonderful target to reach for the Ruby scanner.
76
83
  * everyone who used CodeRay on http://www.rubyforen.de and http://www.infhu.de/mx
77
- * iGEL, magichisoka, manveru and everyone I forgot from rubyforen.de
84
+ * iGEL, magichisoka, manveru, WoN�Do and everyone I forgot from rubyforen.de
85
+ * Daniel and Dethix from ruby-mine.de
78
86
  * Dookie (who is no longer with us...) and Leonidas from http://www.python-forum.de
79
- * matz, nobu, why, dave, dhh, etc... you know, those Ruby gods and gurus
87
+ * matz and all Ruby gods and gurus
80
88
  * The inventors of: the computer, the internet, the true color display, HTML & CSS, VIM, RUBY,
81
89
  pizza, microwaves, guitars, scouting, programming, anime, manga, coke and green ice tea.
82
90
 
@@ -94,7 +102,7 @@ Where would we be without all those people?
94
102
  * RubyGems[http://docs.rubygems.org/]
95
103
  * {Subversion/TortoiseSVN}[http://tortoisesvn.tigris.org/] using Apache via XAMPP[http://www.apachefriends.org/en/xampp.html]
96
104
  * RDoc (though I'm quite unsatisfied with it)
97
- * GNUWin32, MinGW and some other tools to make the shell under windows a bit more usefull
105
+ * GNUWin32, MinGW and some other tools to make the shell under windows a bit more useful
98
106
 
99
107
  ---
100
108
 
data/bin/coderay ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # CodeRay Executable
3
+ #
4
+ # Version: 0.1
5
+ # Author: murphy
6
+
7
+ def err msg
8
+ $stderr.puts msg
9
+ end
10
+
11
+ begin
12
+ require 'coderay'
13
+
14
+ if ARGV.empty?
15
+ puts <<-USAGE
16
+ CodeRay #{CodeRay::Version} (http://rd.cYcnus.de/coderay)
17
+ Usage:
18
+ coderay -<lang> [-<format>] < file > output
19
+ coderay file [-<format>]
20
+ Example:
21
+ coderay -ruby -statistic < foo.rb
22
+ coderay codegen.c # generates codegen.c.html
23
+ USAGE
24
+ end
25
+
26
+ first, second = ARGV
27
+
28
+ if first
29
+ if first[/-(\w+)/] == first
30
+ lang = $1.to_sym
31
+ input = $stdin.read
32
+ tokens = CodeRay.scan input, lang
33
+ elsif first == '-'
34
+ lang = $1.to_sym
35
+ input = $stdin.read
36
+ tokens = CodeRay.scan input, lang
37
+ else
38
+ file = first
39
+ tokens = CodeRay.scan_file file
40
+ output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
41
+ end
42
+ else
43
+ puts 'No lang/file given.'
44
+ exit 1
45
+ end
46
+
47
+ if second
48
+ if second[/-(\w+)/] == second
49
+ format = $1.to_sym
50
+ else
51
+ raise 'Invalid format (must be -xxx).'
52
+ end
53
+ else
54
+ $stderr.puts 'No format given; setting to default (HTML Page)'
55
+ format = :page
56
+ end
57
+
58
+ output = tokens.encode format
59
+ out = $stdout
60
+ if output_filename
61
+ output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
62
+ if File.exist? output_filename
63
+ err 'File %s already exists.' % output_filename
64
+ exit
65
+ else
66
+ out = File.open output_filename, 'w'
67
+ end
68
+ else
69
+
70
+ end
71
+ out.print output
72
+
73
+ rescue => boom
74
+ err "Error: #{boom.message}\n"
75
+ err boom.backtrace
76
+ err '-' * 50
77
+ err ARGV.options
78
+ exit 1
79
+ end
@@ -0,0 +1,12 @@
1
+ require 'coderay'
2
+
3
+ html_encoder = CodeRay.encoder :html
4
+
5
+ scanner = Hash.new do |h, lang|
6
+ h[lang] = CodeRay.scanner lang
7
+ end
8
+
9
+ for lang in [:ruby, :html]
10
+ tokens = scanner[lang].tokenize 'test <test>'
11
+ puts html_encoder.encode_tokens(tokens)
12
+ end
@@ -0,0 +1,12 @@
1
+ $: << '..'
2
+ require 'coderay'
3
+
4
+ tokens = CodeRay.scan File.read(__FILE__), :ruby
5
+ html = tokens.html(:tab_width => 2, :line_numbers => :inline, :line_number_start => -1)
6
+
7
+ puts html.page
8
+
9
+ commment = <<_
10
+ This code must be > 10 lines
11
+ because I want to test the correct adjustment of the line numbers.
12
+ _
data/lib/coderay.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # = CodeRay Library
2
2
  #
3
- # $Id: coderay.rb 120 2006-03-16 18:35:43Z murphy $
3
+ # $Id: coderay.rb 141 2006-05-11 23:32:49Z murphy $
4
4
  #
5
5
  # CodeRay is a Ruby library for syntax highlighting.
6
6
  #
@@ -133,11 +133,12 @@ module CodeRay
133
133
  # Minor: odd for beta, even for stable
134
134
  # Teeny: development state
135
135
  # Revision: Subversion Revision number (generated on rake)
136
- Version = '0.6.0'
136
+ Version = '0.7.1'
137
137
 
138
138
  require 'coderay/tokens'
139
139
  require 'coderay/scanner'
140
140
  require 'coderay/encoder'
141
+ require 'coderay/duo'
141
142
  require 'coderay/style'
142
143
 
143
144
 
@@ -271,6 +272,14 @@ module CodeRay
271
272
  Encoders[format].new options
272
273
  end
273
274
 
275
+ # Finds the Scanner class for +lang+ and creates an instance, passing
276
+ # +options+ to it.
277
+ #
278
+ # See Scanner.new.
279
+ def scanner lang, options = {}
280
+ Scanners[lang].new '', options
281
+ end
282
+
274
283
  # Extract the options for the scanner from the +options+ hash.
275
284
  #
276
285
  # Returns an empty Hash if <tt>:scanner_options</tt> is not set.
@@ -0,0 +1,29 @@
1
+ module CodeRay
2
+
3
+ # = Duo
4
+ #
5
+ # $Id: scanner.rb 123 2006-03-21 14:46:34Z murphy $
6
+ #
7
+ # TODO: Doc.
8
+ class Duo
9
+
10
+ attr_accessor :scanner, :encoder
11
+
12
+ def initialize lang, format, options = {}
13
+ @scanner = CodeRay.scanner lang, CodeRay.get_scanner_options(options)
14
+ @encoder = CodeRay.encoder format, options
15
+ end
16
+
17
+ class << self
18
+ alias [] new
19
+ end
20
+
21
+ def encode code
22
+ @scanner.string = code
23
+ @encoder.encode_tokens(scanner.tokenize)
24
+ end
25
+ alias highlight encode
26
+
27
+ end
28
+
29
+ end
@@ -130,10 +130,12 @@ module CodeRay
130
130
  # By default, it calls text_token or block_token, depending on
131
131
  # whether +text+ is a String.
132
132
  def token text, kind
133
- if text.is_a? String
133
+ if text.is_a? ::String
134
134
  text_token text, kind
135
- else
135
+ elsif text.is_a? ::Symbol
136
136
  block_token text, kind
137
+ else
138
+ raise 'Unknown token text type: %p' % text
137
139
  end
138
140
  end
139
141
 
@@ -169,5 +171,3 @@ module CodeRay
169
171
 
170
172
  end
171
173
  end
172
-
173
- # vim:sw=2:ts=2:noet:tw=78
@@ -1,8 +1,8 @@
1
1
  module CodeRay
2
- module Encoders
3
-
4
- map :stats => :statistic,
5
- :plain => :text
6
-
7
- end
2
+ module Encoders
3
+
4
+ map :stats => :statistic,
5
+ :plain => :text
6
+
7
+ end
8
8
  end
@@ -6,12 +6,12 @@ module Encoders
6
6
  include Streamable
7
7
  register_for :count
8
8
 
9
- protected
10
-
9
+ protected
10
+
11
11
  def setup options
12
12
  @out = 0
13
13
  end
14
-
14
+
15
15
  def token text, kind
16
16
  @out += 1
17
17
  end
@@ -1,38 +1,46 @@
1
1
  module CodeRay
2
- module Encoders
3
-
4
- # = Debug Encoder
5
- class Debug < Encoder
6
-
7
- include Streamable
8
- register_for :debug
9
-
10
- FILE_EXTENSION = 'raydebug'
11
-
12
- protected
13
- def text_token text, kind
14
- @out <<
15
- if kind == :space
16
- text
17
- else
18
- text = text.gsub(/[)\\]/, '\\\\\0')
19
- "#{kind}(#{text})"
20
- end
21
- end
22
-
23
- def block_token action, kind
24
- @out << super
25
- end
2
+ module Encoders
3
+
4
+ # = Debug Encoder
5
+ #
6
+ # Fast encoder producing simple debug output.
7
+ #
8
+ # It is readable and diff-able and is used for testing.
9
+ #
10
+ # You cannot fully restore the tokens information from the
11
+ # output, because consecutive :space tokens are merged.
12
+ # Use Tokens#dump for caching purposes.
13
+ class Debug < Encoder
14
+
15
+ include Streamable
16
+ register_for :debug
17
+
18
+ FILE_EXTENSION = 'raydebug'
19
+
20
+ protected
21
+ def text_token text, kind
22
+ @out <<
23
+ if kind == :space
24
+ text
25
+ else
26
+ text = text.gsub(/[)\\]/, '\\\\\0')
27
+ "#{kind}(#{text})"
28
+ end
29
+ end
26
30
 
27
- def open_token kind
28
- "#{kind}<"
29
- end
31
+ def block_token action, kind
32
+ @out << super
33
+ end
30
34
 
31
- def close_token kind
32
- ">"
33
- end
35
+ def open_token kind
36
+ "#{kind}<"
37
+ end
34
38
 
39
+ def close_token kind
40
+ ">"
35
41
  end
36
42
 
37
43
  end
44
+
45
+ end
38
46
  end
@@ -1,4 +1,5 @@
1
- module CodeRay module Encoders
1
+ module CodeRay
2
+ module Encoders
2
3
 
3
4
  load :html
4
5
 
@@ -15,4 +16,5 @@ module CodeRay module Encoders
15
16
 
16
17
  end
17
18
 
18
- end end
19
+ end
20
+ end