coderay 0.7.1.147 → 0.7.2.165

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/bin/coderay +54 -56
  2. data/demo/suite.rb +54 -54
  3. data/lib/coderay.rb +187 -187
  4. data/lib/coderay/duo.rb +29 -29
  5. data/lib/coderay/encoder.rb +173 -173
  6. data/lib/coderay/encoders/_map.rb +8 -8
  7. data/lib/coderay/encoders/count.rb +21 -21
  8. data/lib/coderay/encoders/debug.rb +46 -46
  9. data/lib/coderay/encoders/div.rb +20 -20
  10. data/lib/coderay/encoders/html.rb +249 -245
  11. data/lib/coderay/encoders/html/classes.rb +73 -73
  12. data/lib/coderay/encoders/html/css.rb +65 -65
  13. data/lib/coderay/encoders/html/numerization.rb +122 -122
  14. data/lib/coderay/encoders/html/output.rb +195 -195
  15. data/lib/coderay/encoders/null.rb +26 -26
  16. data/lib/coderay/encoders/page.rb +21 -21
  17. data/lib/coderay/encoders/span.rb +20 -20
  18. data/lib/coderay/encoders/statistic.rb +81 -81
  19. data/lib/coderay/encoders/text.rb +33 -33
  20. data/lib/coderay/encoders/tokens.rb +44 -44
  21. data/lib/coderay/encoders/xml.rb +71 -71
  22. data/lib/coderay/encoders/yaml.rb +22 -22
  23. data/lib/coderay/helpers/filetype.rb +152 -153
  24. data/lib/coderay/helpers/gzip_simple.rb +67 -68
  25. data/lib/coderay/helpers/plugin.rb +297 -297
  26. data/lib/coderay/helpers/word_list.rb +46 -47
  27. data/lib/coderay/scanner.rb +238 -238
  28. data/lib/coderay/scanners/_map.rb +15 -14
  29. data/lib/coderay/scanners/c.rb +163 -155
  30. data/lib/coderay/scanners/delphi.rb +131 -129
  31. data/lib/coderay/scanners/html.rb +174 -167
  32. data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
  33. data/lib/coderay/scanners/plaintext.rb +15 -15
  34. data/lib/coderay/scanners/rhtml.rb +73 -65
  35. data/lib/coderay/scanners/ruby.rb +404 -397
  36. data/lib/coderay/scanners/ruby/patterns.rb +216 -216
  37. data/lib/coderay/scanners/xml.rb +18 -18
  38. data/lib/coderay/style.rb +20 -20
  39. data/lib/coderay/styles/_map.rb +3 -3
  40. data/lib/coderay/styles/cycnus.rb +18 -18
  41. data/lib/coderay/styles/murphy.rb +18 -18
  42. data/lib/coderay/tokens.rb +322 -322
  43. metadata +86 -86
  44. data/lib/coderay/scanners/nitro_html.rb +0 -125
  45. data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,20 +1,20 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- load :html
5
-
6
- class Span < HTML
7
-
8
- FILE_EXTENSION = 'span.html'
9
-
10
- register_for :span
11
-
12
- DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
13
- :css => :style,
14
- :wrap => :span,
15
- })
16
-
17
- end
18
-
19
- end
20
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ load :html
5
+
6
+ class Span < HTML
7
+
8
+ FILE_EXTENSION = 'span.html'
9
+
10
+ register_for :span
11
+
12
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
13
+ :css => :style,
14
+ :wrap => :span,
15
+ })
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -1,81 +1,81 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- # Makes a statistic for the given tokens.
5
- class Statistic < Encoder
6
-
7
- include Streamable
8
- register_for :stats, :statistic
9
-
10
- attr_reader :type_stats, :real_token_count
11
-
12
- protected
13
-
14
- TypeStats = Struct.new :count, :size
15
-
16
- def setup options
17
- @type_stats = Hash.new { |h, k| h[k] = TypeStats.new 0, 0 }
18
- @real_token_count = 0
19
- end
20
-
21
- def generate tokens, options
22
- @tokens = tokens
23
- super
24
- end
25
-
26
- def text_token text, kind
27
- @real_token_count += 1 unless kind == :space
28
- @type_stats[kind].count += 1
29
- @type_stats[kind].size += text.size
30
- @type_stats['TOTAL'].size += text.size
31
- end
32
-
33
- # TODO Hierarchy handling
34
- def block_token action, kind
35
- #@content_type = kind
36
- @type_stats['open/close'].count += 1
37
- end
38
-
39
- def token text, kind
40
- super
41
- @type_stats['TOTAL'].count += 1
42
- end
43
-
44
- STATS = <<-STATS
45
-
46
- Code Statistics
47
-
48
- Tokens %8d
49
- Non-Whitespace %8d
50
- Bytes Total %8d
51
-
52
- Token Types (%d):
53
- type count ratio size (average)
54
- -------------------------------------------------------------
55
- %s
56
- STATS
57
- # space 12007 33.81 % 1.7
58
- TOKEN_TYPES_ROW = <<-TKR
59
- %-20s %8d %6.2f %% %5.1f
60
- TKR
61
-
62
- def finish options
63
- all = @type_stats['TOTAL']
64
- all_count, all_size = all.count, all.size
65
- @type_stats.each do |type, stat|
66
- stat.size /= stat.count.to_f
67
- end
68
- types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
69
- TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
70
- end.join
71
- STATS % [
72
- all_count, @real_token_count, all_size,
73
- @type_stats.delete_if { |k, v| k.is_a? String }.size,
74
- types_stats
75
- ]
76
- end
77
-
78
- end
79
-
80
- end
81
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # Makes a statistic for the given tokens.
5
+ class Statistic < Encoder
6
+
7
+ include Streamable
8
+ register_for :stats, :statistic
9
+
10
+ attr_reader :type_stats, :real_token_count
11
+
12
+ protected
13
+
14
+ TypeStats = Struct.new :count, :size
15
+
16
+ def setup options
17
+ @type_stats = Hash.new { |h, k| h[k] = TypeStats.new 0, 0 }
18
+ @real_token_count = 0
19
+ end
20
+
21
+ def generate tokens, options
22
+ @tokens = tokens
23
+ super
24
+ end
25
+
26
+ def text_token text, kind
27
+ @real_token_count += 1 unless kind == :space
28
+ @type_stats[kind].count += 1
29
+ @type_stats[kind].size += text.size
30
+ @type_stats['TOTAL'].size += text.size
31
+ end
32
+
33
+ # TODO Hierarchy handling
34
+ def block_token action, kind
35
+ #@content_type = kind
36
+ @type_stats['open/close'].count += 1
37
+ end
38
+
39
+ def token text, kind
40
+ super
41
+ @type_stats['TOTAL'].count += 1
42
+ end
43
+
44
+ STATS = <<-STATS
45
+
46
+ Code Statistics
47
+
48
+ Tokens %8d
49
+ Non-Whitespace %8d
50
+ Bytes Total %8d
51
+
52
+ Token Types (%d):
53
+ type count ratio size (average)
54
+ -------------------------------------------------------------
55
+ %s
56
+ STATS
57
+ # space 12007 33.81 % 1.7
58
+ TOKEN_TYPES_ROW = <<-TKR
59
+ %-20s %8d %6.2f %% %5.1f
60
+ TKR
61
+
62
+ def finish options
63
+ all = @type_stats['TOTAL']
64
+ all_count, all_size = all.count, all.size
65
+ @type_stats.each do |type, stat|
66
+ stat.size /= stat.count.to_f
67
+ end
68
+ types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
69
+ TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
70
+ end.join
71
+ STATS % [
72
+ all_count, @real_token_count, all_size,
73
+ @type_stats.delete_if { |k, v| k.is_a? String }.size,
74
+ types_stats
75
+ ]
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
@@ -1,33 +1,33 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- class Text < Encoder
5
-
6
- include Streamable
7
- register_for :text
8
-
9
- FILE_EXTENSION = 'txt'
10
-
11
- DEFAULT_OPTIONS = {
12
- :separator => ''
13
- }
14
-
15
- protected
16
- def setup options
17
- super
18
- @sep = options[:separator]
19
- end
20
-
21
- def token text, kind
22
- return unless text.respond_to? :to_str
23
- @out << text + @sep
24
- end
25
-
26
- def finish options
27
- @out.chomp @sep
28
- end
29
-
30
- end
31
-
32
- end
33
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ class Text < Encoder
5
+
6
+ include Streamable
7
+ register_for :text
8
+
9
+ FILE_EXTENSION = 'txt'
10
+
11
+ DEFAULT_OPTIONS = {
12
+ :separator => ''
13
+ }
14
+
15
+ protected
16
+ def setup options
17
+ super
18
+ @sep = options[:separator]
19
+ end
20
+
21
+ def token text, kind
22
+ return unless text.respond_to? :to_str
23
+ @out << text + @sep
24
+ end
25
+
26
+ def finish options
27
+ @out.chomp @sep
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -1,44 +1,44 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- # The Tokens encoder converts the tokens to a simple
5
- # readable format. It doesn't use colors and is mainly
6
- # intended for console output.
7
- #
8
- # The tokens are converted with Tokens.write_token.
9
- #
10
- # The format is:
11
- #
12
- # <token-kind> \t <escaped token-text> \n
13
- #
14
- # Example:
15
- #
16
- # require 'coderay'
17
- # puts CodeRay.scan("puts 3 + 4", :ruby).tokens
18
- #
19
- # prints:
20
- #
21
- # ident puts
22
- # space
23
- # integer 3
24
- # space
25
- # operator +
26
- # space
27
- # integer 4
28
- #
29
- class Tokens < Encoder
30
-
31
- include Streamable
32
- register_for :tokens
33
-
34
- FILE_EXTENSION = 'tok'
35
-
36
- protected
37
- def token *args
38
- @out << CodeRay::Tokens.write_token(*args)
39
- end
40
-
41
- end
42
-
43
- end
44
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # The Tokens encoder converts the tokens to a simple
5
+ # readable format. It doesn't use colors and is mainly
6
+ # intended for console output.
7
+ #
8
+ # The tokens are converted with Tokens.write_token.
9
+ #
10
+ # The format is:
11
+ #
12
+ # <token-kind> \t <escaped token-text> \n
13
+ #
14
+ # Example:
15
+ #
16
+ # require 'coderay'
17
+ # puts CodeRay.scan("puts 3 + 4", :ruby).tokens
18
+ #
19
+ # prints:
20
+ #
21
+ # ident puts
22
+ # space
23
+ # integer 3
24
+ # space
25
+ # operator +
26
+ # space
27
+ # integer 4
28
+ #
29
+ class Tokens < Encoder
30
+
31
+ include Streamable
32
+ register_for :tokens
33
+
34
+ FILE_EXTENSION = 'tok'
35
+
36
+ protected
37
+ def token *args
38
+ @out << CodeRay::Tokens.write_token(*args)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -1,71 +1,71 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- # = XML Encoder
5
- #
6
- # Uses REXML. Very slow.
7
- class XML < Encoder
8
-
9
- include Streamable
10
- register_for :xml
11
-
12
- FILE_EXTENSION = 'xml'
13
-
14
- require 'rexml/document'
15
-
16
- DEFAULT_OPTIONS = {
17
- :tab_width => 8,
18
- :pretty => -1,
19
- :transitive => false,
20
- }
21
-
22
- protected
23
-
24
- def setup options
25
- @out = ''
26
- @doc = REXML::Document.new
27
- @doc << REXML::XMLDecl.new
28
- @tab_width = options[:tab_width]
29
- @root = @node = @doc.add_element('coderay-tokens')
30
- end
31
-
32
- def finish options
33
- @doc.write @out, options[:pretty], options[:transitive], true
34
- @out
35
- end
36
-
37
- def text_token text, kind
38
- if kind == :space
39
- token = @node
40
- else
41
- token = @node.add_element kind.to_s
42
- end
43
- text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
44
- case
45
- when space
46
- token << REXML::Text.new(space, true)
47
- when tab
48
- token << REXML::Text.new(tab, true)
49
- when nl
50
- token << REXML::Text.new(nl, true)
51
- else
52
- token << REXML::Text.new($&)
53
- end
54
- end
55
- end
56
-
57
- def open_token kind
58
- @node = @node.add_element kind.to_s
59
- end
60
-
61
- def close_token kind
62
- if @node == @root
63
- raise 'no token to close!'
64
- end
65
- @node = @node.parent
66
- end
67
-
68
- end
69
-
70
- end
71
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # = XML Encoder
5
+ #
6
+ # Uses REXML. Very slow.
7
+ class XML < Encoder
8
+
9
+ include Streamable
10
+ register_for :xml
11
+
12
+ FILE_EXTENSION = 'xml'
13
+
14
+ require 'rexml/document'
15
+
16
+ DEFAULT_OPTIONS = {
17
+ :tab_width => 8,
18
+ :pretty => -1,
19
+ :transitive => false,
20
+ }
21
+
22
+ protected
23
+
24
+ def setup options
25
+ @out = ''
26
+ @doc = REXML::Document.new
27
+ @doc << REXML::XMLDecl.new
28
+ @tab_width = options[:tab_width]
29
+ @root = @node = @doc.add_element('coderay-tokens')
30
+ end
31
+
32
+ def finish options
33
+ @doc.write @out, options[:pretty], options[:transitive], true
34
+ @out
35
+ end
36
+
37
+ def text_token text, kind
38
+ if kind == :space
39
+ token = @node
40
+ else
41
+ token = @node.add_element kind.to_s
42
+ end
43
+ text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
44
+ case
45
+ when space
46
+ token << REXML::Text.new(space, true)
47
+ when tab
48
+ token << REXML::Text.new(tab, true)
49
+ when nl
50
+ token << REXML::Text.new(nl, true)
51
+ else
52
+ token << REXML::Text.new($&)
53
+ end
54
+ end
55
+ end
56
+
57
+ def open_token kind
58
+ @node = @node.add_element kind.to_s
59
+ end
60
+
61
+ def close_token kind
62
+ if @node == @root
63
+ raise 'no token to close!'
64
+ end
65
+ @node = @node.parent
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end