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.
- data/bin/coderay +54 -56
- data/demo/suite.rb +54 -54
- data/lib/coderay.rb +187 -187
- data/lib/coderay/duo.rb +29 -29
- data/lib/coderay/encoder.rb +173 -173
- data/lib/coderay/encoders/_map.rb +8 -8
- data/lib/coderay/encoders/count.rb +21 -21
- data/lib/coderay/encoders/debug.rb +46 -46
- data/lib/coderay/encoders/div.rb +20 -20
- data/lib/coderay/encoders/html.rb +249 -245
- data/lib/coderay/encoders/html/classes.rb +73 -73
- data/lib/coderay/encoders/html/css.rb +65 -65
- data/lib/coderay/encoders/html/numerization.rb +122 -122
- data/lib/coderay/encoders/html/output.rb +195 -195
- data/lib/coderay/encoders/null.rb +26 -26
- data/lib/coderay/encoders/page.rb +21 -21
- data/lib/coderay/encoders/span.rb +20 -20
- data/lib/coderay/encoders/statistic.rb +81 -81
- data/lib/coderay/encoders/text.rb +33 -33
- data/lib/coderay/encoders/tokens.rb +44 -44
- data/lib/coderay/encoders/xml.rb +71 -71
- data/lib/coderay/encoders/yaml.rb +22 -22
- data/lib/coderay/helpers/filetype.rb +152 -153
- data/lib/coderay/helpers/gzip_simple.rb +67 -68
- data/lib/coderay/helpers/plugin.rb +297 -297
- data/lib/coderay/helpers/word_list.rb +46 -47
- data/lib/coderay/scanner.rb +238 -238
- data/lib/coderay/scanners/_map.rb +15 -14
- data/lib/coderay/scanners/c.rb +163 -155
- data/lib/coderay/scanners/delphi.rb +131 -129
- data/lib/coderay/scanners/html.rb +174 -167
- data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
- data/lib/coderay/scanners/plaintext.rb +15 -15
- data/lib/coderay/scanners/rhtml.rb +73 -65
- data/lib/coderay/scanners/ruby.rb +404 -397
- data/lib/coderay/scanners/ruby/patterns.rb +216 -216
- data/lib/coderay/scanners/xml.rb +18 -18
- data/lib/coderay/style.rb +20 -20
- data/lib/coderay/styles/_map.rb +3 -3
- data/lib/coderay/styles/cycnus.rb +18 -18
- data/lib/coderay/styles/murphy.rb +18 -18
- data/lib/coderay/tokens.rb +322 -322
- metadata +86 -86
- data/lib/coderay/scanners/nitro_html.rb +0 -125
- data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,20 +1,20 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
57
|
-
# space 12007 33.81 % 1.7
|
58
|
-
|
59
|
-
%-20s %8d %6.2f %% %5.1f
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/lib/coderay/encoders/xml.rb
CHANGED
@@ -1,71 +1,71 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|