coderay 0.7.1.147 → 0.7.2.165
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.
- 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
data/lib/coderay/duo.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
module CodeRay
|
2
|
-
|
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
|
-
end
|
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
|
data/lib/coderay/encoder.rb
CHANGED
@@ -1,173 +1,173 @@
|
|
1
|
-
module CodeRay
|
2
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
|
3
|
+
# This module holds the Encoder class and its subclasses.
|
4
|
+
# For example, the HTML encoder is named CodeRay::Encoders::HTML
|
5
|
+
# can be found in coderay/encoders/html.
|
6
|
+
#
|
7
|
+
# Encoders also provides methods and constants for the register
|
8
|
+
# mechanism and the [] method that returns the Encoder class
|
9
|
+
# belonging to the given format.
|
10
|
+
module Encoders
|
11
|
+
extend PluginHost
|
12
|
+
plugin_path File.dirname(__FILE__), 'encoders'
|
13
|
+
|
14
|
+
# = Encoder
|
15
|
+
#
|
16
|
+
# The Encoder base class. Together with Scanner and
|
17
|
+
# Tokens, it forms the highlighting triad.
|
18
|
+
#
|
19
|
+
# Encoder instances take a Tokens object and do something with it.
|
20
|
+
#
|
21
|
+
# The most common Encoder is surely the HTML encoder
|
22
|
+
# (CodeRay::Encoders::HTML). It highlights the code in a colorful
|
23
|
+
# html page.
|
24
|
+
# If you want the highlighted code in a div or a span instead,
|
25
|
+
# use its subclasses Div and Span.
|
26
|
+
class Encoder
|
27
|
+
extend Plugin
|
28
|
+
plugin_host Encoders
|
29
|
+
|
30
|
+
attr_reader :token_stream
|
31
|
+
|
32
|
+
class << self
|
33
|
+
|
34
|
+
# Returns if the Encoder can be used in streaming mode.
|
35
|
+
def streamable?
|
36
|
+
is_a? Streamable
|
37
|
+
end
|
38
|
+
|
39
|
+
# If FILE_EXTENSION isn't defined, this method returns the
|
40
|
+
# downcase class name instead.
|
41
|
+
def const_missing sym
|
42
|
+
if sym == :FILE_EXTENSION
|
43
|
+
sym.to_s.downcase
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
# Subclasses are to store their default options in this constant.
|
52
|
+
DEFAULT_OPTIONS = { :stream => false }
|
53
|
+
|
54
|
+
# The options you gave the Encoder at creating.
|
55
|
+
attr_accessor :options
|
56
|
+
|
57
|
+
# Creates a new Encoder.
|
58
|
+
# +options+ is saved and used for all encode operations, as long
|
59
|
+
# as you don't overwrite it there by passing additional options.
|
60
|
+
#
|
61
|
+
# Encoder objects provide three encode methods:
|
62
|
+
# - encode simply takes a +code+ string and a +lang+
|
63
|
+
# - encode_tokens expects a +tokens+ object instead
|
64
|
+
# - encode_stream is like encode, but uses streaming mode.
|
65
|
+
#
|
66
|
+
# Each method has an optional +options+ parameter. These are
|
67
|
+
# added to the options you passed at creation.
|
68
|
+
def initialize options = {}
|
69
|
+
@options = self.class::DEFAULT_OPTIONS.merge options
|
70
|
+
raise "I am only the basic Encoder class. I can't encode "\
|
71
|
+
"anything. :( Use my subclasses." if self.class == Encoder
|
72
|
+
end
|
73
|
+
|
74
|
+
# Encode a Tokens object.
|
75
|
+
def encode_tokens tokens, options = {}
|
76
|
+
options = @options.merge options
|
77
|
+
setup options
|
78
|
+
compile tokens, options
|
79
|
+
finish options
|
80
|
+
end
|
81
|
+
|
82
|
+
# Encode the given +code+ after tokenizing it using the Scanner
|
83
|
+
# for +lang+.
|
84
|
+
def encode code, lang, options = {}
|
85
|
+
options = @options.merge options
|
86
|
+
scanner_options = CodeRay.get_scanner_options(options)
|
87
|
+
tokens = CodeRay.scan code, lang, scanner_options
|
88
|
+
encode_tokens tokens, options
|
89
|
+
end
|
90
|
+
|
91
|
+
# You can use highlight instead of encode, if that seems
|
92
|
+
# more clear to you.
|
93
|
+
alias highlight encode
|
94
|
+
|
95
|
+
# Encode the given +code+ using the Scanner for +lang+ in
|
96
|
+
# streaming mode.
|
97
|
+
def encode_stream code, lang, options = {}
|
98
|
+
raise NotStreamableError, self unless kind_of? Streamable
|
99
|
+
options = @options.merge options
|
100
|
+
setup options
|
101
|
+
scanner_options = CodeRay.get_scanner_options options
|
102
|
+
@token_stream =
|
103
|
+
CodeRay.scan_stream code, lang, scanner_options, &self
|
104
|
+
finish options
|
105
|
+
end
|
106
|
+
|
107
|
+
# Behave like a proc. The token method is converted to a proc.
|
108
|
+
def to_proc
|
109
|
+
method(:token).to_proc
|
110
|
+
end
|
111
|
+
|
112
|
+
# Return the default file extension for outputs of this encoder.
|
113
|
+
def file_extension
|
114
|
+
self.class::FILE_EXTENSION
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
# Called with merged options before encoding starts.
|
120
|
+
# Sets @out to an empty string.
|
121
|
+
#
|
122
|
+
# See the HTML Encoder for an example of option caching.
|
123
|
+
def setup options
|
124
|
+
@out = ''
|
125
|
+
end
|
126
|
+
|
127
|
+
# Called with +text+ and +kind+ of the currently scanned token.
|
128
|
+
# For simple scanners, it's enougth to implement this method.
|
129
|
+
#
|
130
|
+
# By default, it calls text_token or block_token, depending on
|
131
|
+
# whether +text+ is a String.
|
132
|
+
def token text, kind
|
133
|
+
if text.is_a? ::String
|
134
|
+
text_token text, kind
|
135
|
+
elsif text.is_a? ::Symbol
|
136
|
+
block_token text, kind
|
137
|
+
else
|
138
|
+
raise 'Unknown token text type: %p' % text
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def text_token text, kind
|
143
|
+
end
|
144
|
+
|
145
|
+
def block_token action, kind
|
146
|
+
case action
|
147
|
+
when :open
|
148
|
+
open_token kind
|
149
|
+
when :close
|
150
|
+
close_token kind
|
151
|
+
else
|
152
|
+
raise 'unknown block action: %p' % action
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Called with merged options after encoding starts.
|
157
|
+
# The return value is the result of encoding, typically @out.
|
158
|
+
def finish options
|
159
|
+
@out
|
160
|
+
end
|
161
|
+
|
162
|
+
# Do the encoding.
|
163
|
+
#
|
164
|
+
# The already created +tokens+ object must be used; it can be a
|
165
|
+
# TokenStream or a Tokens object.
|
166
|
+
def compile tokens, options
|
167
|
+
tokens.each(&self)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
map :stats => :statistic,
|
5
|
+
:plain => :text
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
class Count < Encoder
|
5
|
+
|
6
|
+
include Streamable
|
7
|
+
register_for :count
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def setup options
|
12
|
+
@out = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def token text, kind
|
16
|
+
@out += 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|