coderay 1.0.0.864rc3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/coderay +1 -1
- data/lib/coderay/encoder.rb +1 -1
- data/lib/coderay/encoders/html/output.rb +9 -1
- data/lib/coderay/scanners/java/builtin_types.rb +2 -0
- data/lib/coderay/scanners/yaml.rb +1 -1
- data/lib/coderay/styles/alpha.rb +0 -1
- data/lib/coderay/tokens.rb +0 -91
- data/lib/coderay/tokens_proxy.rb +23 -6
- data/lib/coderay/version.rb +1 -1
- data/test/functional/basic.rb +3 -1
- data/test/functional/examples.rb +2 -2
- data/test/functional/suite.rb +1 -0
- metadata +13 -13
data/bin/coderay
CHANGED
@@ -197,7 +197,7 @@ when 'li', 'list'
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
when 'stylesheet', 'style', 'css'
|
200
|
-
puts CodeRay::Encoders[:html]::CSS.new(args.first).stylesheet
|
200
|
+
puts CodeRay::Encoders[:html]::CSS.new(args.first || :default).stylesheet
|
201
201
|
when 'commands'
|
202
202
|
commands
|
203
203
|
when 'help'
|
data/lib/coderay/encoder.rb
CHANGED
@@ -140,10 +140,18 @@ module Encoders
|
|
140
140
|
text-decoration: inherit;
|
141
141
|
color: inherit;
|
142
142
|
}
|
143
|
+
body {
|
144
|
+
background-color: white;
|
145
|
+
padding: 0;
|
146
|
+
margin: 0;
|
147
|
+
}
|
143
148
|
<%CSS%>
|
149
|
+
.CodeRay {
|
150
|
+
border: none;
|
151
|
+
}
|
144
152
|
</style>
|
145
153
|
</head>
|
146
|
-
<body
|
154
|
+
<body>
|
147
155
|
|
148
156
|
<%CONTENT%>
|
149
157
|
</body>
|
@@ -3,6 +3,7 @@ module Scanners
|
|
3
3
|
|
4
4
|
module Java::BuiltinTypes # :nodoc:
|
5
5
|
|
6
|
+
#:nocov:
|
6
7
|
List = %w[
|
7
8
|
AbstractAction AbstractBorder AbstractButton AbstractCellEditor AbstractCollection
|
8
9
|
AbstractColorChooserPanel AbstractDocument AbstractExecutorService AbstractInterruptibleChannel
|
@@ -412,6 +413,7 @@ module Scanners
|
|
412
413
|
XPathFactoryConfigurationException XPathFunction XPathFunctionException XPathFunctionResolver
|
413
414
|
XPathVariableResolver ZipEntry ZipException ZipFile ZipInputStream ZipOutputStream ZoneView
|
414
415
|
]
|
416
|
+
#:nocov:
|
415
417
|
|
416
418
|
end
|
417
419
|
|
@@ -76,7 +76,7 @@ module Scanners
|
|
76
76
|
when match = scan(/[,{}\[\]]/)
|
77
77
|
encoder.text_token match, :operator
|
78
78
|
next
|
79
|
-
when state == :initial && match = scan(/[
|
79
|
+
when state == :initial && match = scan(/[-\w.()\/ ]*\S(?= *:(?: |$))/)
|
80
80
|
encoder.text_token match, :key
|
81
81
|
key_indent = column(pos - match.size) - 1
|
82
82
|
state = :colon
|
data/lib/coderay/styles/alpha.rb
CHANGED
@@ -45,7 +45,6 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
|
|
45
45
|
.CodeRay span.line-numbers { padding: 0px 4px; }
|
46
46
|
.CodeRay .line { display: block; float: left; width: 100%; }
|
47
47
|
.CodeRay .code { width: 100%; }
|
48
|
-
.CodeRay .code pre { overflow: auto; }
|
49
48
|
MAIN
|
50
49
|
|
51
50
|
TOKEN_COLORS = <<-'TOKENS'
|
data/lib/coderay/tokens.rb
CHANGED
@@ -83,97 +83,6 @@ module CodeRay
|
|
83
83
|
super
|
84
84
|
end
|
85
85
|
|
86
|
-
# Returns the tokens compressed by joining consecutive
|
87
|
-
# tokens of the same kind.
|
88
|
-
#
|
89
|
-
# This can not be undone, but should yield the same output
|
90
|
-
# in most Encoders. It basically makes the output smaller.
|
91
|
-
#
|
92
|
-
# Combined with dump, it saves space for the cost of time.
|
93
|
-
#
|
94
|
-
# If the scanner is written carefully, this is not required -
|
95
|
-
# for example, consecutive //-comment lines could already be
|
96
|
-
# joined in one comment token by the Scanner.
|
97
|
-
def optimize
|
98
|
-
raise NotImplementedError, 'Tokens#optimize needs to be rewritten.'
|
99
|
-
# last_kind = last_text = nil
|
100
|
-
# new = self.class.new
|
101
|
-
# for text, kind in self
|
102
|
-
# if text.is_a? String
|
103
|
-
# if kind == last_kind
|
104
|
-
# last_text << text
|
105
|
-
# else
|
106
|
-
# new << [last_text, last_kind] if last_kind
|
107
|
-
# last_text = text
|
108
|
-
# last_kind = kind
|
109
|
-
# end
|
110
|
-
# else
|
111
|
-
# new << [last_text, last_kind] if last_kind
|
112
|
-
# last_kind = last_text = nil
|
113
|
-
# new << [text, kind]
|
114
|
-
# end
|
115
|
-
# end
|
116
|
-
# new << [last_text, last_kind] if last_kind
|
117
|
-
# new
|
118
|
-
end
|
119
|
-
|
120
|
-
# Compact the object itself; see optimize.
|
121
|
-
def optimize!
|
122
|
-
replace optimize
|
123
|
-
end
|
124
|
-
|
125
|
-
# Ensure that all begin_group tokens have a correspondent end_group.
|
126
|
-
#
|
127
|
-
# TODO: Test this!
|
128
|
-
def fix
|
129
|
-
raise NotImplementedError, 'Tokens#fix needs to be rewritten.'
|
130
|
-
# tokens = self.class.new
|
131
|
-
# # Check token nesting using a stack of kinds.
|
132
|
-
# opened = []
|
133
|
-
# for type, kind in self
|
134
|
-
# case type
|
135
|
-
# when :begin_group
|
136
|
-
# opened.push [:begin_group, kind]
|
137
|
-
# when :begin_line
|
138
|
-
# opened.push [:end_line, kind]
|
139
|
-
# when :end_group, :end_line
|
140
|
-
# expected = opened.pop
|
141
|
-
# if [type, kind] != expected
|
142
|
-
# # Unexpected end; decide what to do based on the kind:
|
143
|
-
# # - token was never opened: delete the end (just skip it)
|
144
|
-
# next unless opened.rindex expected
|
145
|
-
# # - token was opened earlier: also close tokens in between
|
146
|
-
# tokens << token until (token = opened.pop) == expected
|
147
|
-
# end
|
148
|
-
# end
|
149
|
-
# tokens << [type, kind]
|
150
|
-
# end
|
151
|
-
# # Close remaining opened tokens
|
152
|
-
# tokens << token while token = opened.pop
|
153
|
-
# tokens
|
154
|
-
end
|
155
|
-
|
156
|
-
def fix!
|
157
|
-
replace fix
|
158
|
-
end
|
159
|
-
|
160
|
-
# TODO: Scanner#split_into_lines
|
161
|
-
#
|
162
|
-
# Makes sure that:
|
163
|
-
# - newlines are single tokens
|
164
|
-
# (which means all other token are single-line)
|
165
|
-
# - there are no open tokens at the end the line
|
166
|
-
#
|
167
|
-
# This makes it simple for encoders that work line-oriented,
|
168
|
-
# like HTML with list-style numeration.
|
169
|
-
def split_into_lines
|
170
|
-
raise NotImplementedError
|
171
|
-
end
|
172
|
-
|
173
|
-
def split_into_lines!
|
174
|
-
replace split_into_lines
|
175
|
-
end
|
176
|
-
|
177
86
|
# Split the tokens into parts of the given +sizes+.
|
178
87
|
#
|
179
88
|
# The result will be an Array of Tokens objects. The parts have
|
data/lib/coderay/tokens_proxy.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
module CodeRay
|
2
2
|
|
3
|
-
|
3
|
+
# The result of a scan operation is a TokensProxy, but should act like Tokens.
|
4
|
+
#
|
5
|
+
# This proxy makes it possible to use the classic CodeRay.scan.encode API
|
6
|
+
# while still providing the benefits of direct streaming.
|
7
|
+
class TokensProxy
|
4
8
|
|
9
|
+
attr_accessor :input, :lang, :options, :block
|
10
|
+
|
11
|
+
# Create a new TokensProxy with the arguments of CodeRay.scan.
|
12
|
+
def initialize input, lang, options = {}, block = nil
|
13
|
+
@input = input
|
14
|
+
@lang = lang
|
15
|
+
@options = options
|
16
|
+
@block = block
|
17
|
+
end
|
18
|
+
|
19
|
+
# Call CodeRay.encode if +encoder+ is a Symbol;
|
20
|
+
# otherwise, convert the receiver to tokens and call encoder.encode_tokens.
|
5
21
|
def encode encoder, options = {}
|
6
22
|
if encoder.respond_to? :to_sym
|
7
23
|
CodeRay.encode(input, lang, encoder, options)
|
@@ -10,29 +26,30 @@ module CodeRay
|
|
10
26
|
end
|
11
27
|
end
|
12
28
|
|
29
|
+
# Tries to call encode;
|
30
|
+
# delegates to tokens otherwise.
|
13
31
|
def method_missing method, *args, &blk
|
14
|
-
encode method, *args
|
32
|
+
encode method.to_sym, *args
|
15
33
|
rescue PluginHost::PluginNotFound
|
16
34
|
tokens.send(method, *args, &blk)
|
17
35
|
end
|
18
36
|
|
37
|
+
# The (cached) result of the tokenized input; a Tokens instance.
|
19
38
|
def tokens
|
20
39
|
@tokens ||= scanner.tokenize(input)
|
21
40
|
end
|
22
41
|
|
42
|
+
# A (cached) scanner instance to use for the scan task.
|
23
43
|
def scanner
|
24
44
|
@scanner ||= CodeRay.scanner(lang, options, &block)
|
25
45
|
end
|
26
46
|
|
47
|
+
# Overwrite Struct#each.
|
27
48
|
def each *args, &blk
|
28
49
|
tokens.each(*args, &blk)
|
29
50
|
self
|
30
51
|
end
|
31
52
|
|
32
|
-
def count
|
33
|
-
tokens.count
|
34
|
-
end
|
35
|
-
|
36
53
|
end
|
37
54
|
|
38
55
|
end
|
data/lib/coderay/version.rb
CHANGED
data/test/functional/basic.rb
CHANGED
@@ -148,7 +148,9 @@ more code # and another comment, in-line.
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
assert_equal 'reserved', CodeRay::TokenKinds[:reserved]
|
151
|
-
|
151
|
+
assert_warning 'Undefined Token kind: :shibboleet' do
|
152
|
+
assert_equal false, CodeRay::TokenKinds[:shibboleet]
|
153
|
+
end
|
152
154
|
end
|
153
155
|
|
154
156
|
class Milk < CodeRay::Encoders::Encoder
|
data/test/functional/examples.rb
CHANGED
@@ -34,8 +34,8 @@ end
|
|
34
34
|
|
35
35
|
# output as standalone HTML page (using CSS classes)
|
36
36
|
page = CodeRay.scan('puts "Hello, world!"', :ruby).page
|
37
|
-
|
38
|
-
<body
|
37
|
+
assert_match <<-PAGE, page
|
38
|
+
<body>
|
39
39
|
|
40
40
|
<table class="CodeRay"><tr>
|
41
41
|
<td class="line-numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>
|
data/test/functional/suite.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kornelius Kalnbach
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-19 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Fast and easy syntax highlighting for selected languages, written in
|
15
15
|
Ruby. Comes with RedCloth integration and LOC counter.
|
@@ -21,6 +21,10 @@ extensions: []
|
|
21
21
|
extra_rdoc_files:
|
22
22
|
- README_INDEX.rdoc
|
23
23
|
files:
|
24
|
+
- LICENSE
|
25
|
+
- README_INDEX.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/coderay.rb
|
24
28
|
- lib/coderay/duo.rb
|
25
29
|
- lib/coderay/encoder.rb
|
26
30
|
- lib/coderay/encoders/_map.rb
|
@@ -29,10 +33,10 @@ files:
|
|
29
33
|
- lib/coderay/encoders/debug.rb
|
30
34
|
- lib/coderay/encoders/div.rb
|
31
35
|
- lib/coderay/encoders/filter.rb
|
36
|
+
- lib/coderay/encoders/html.rb
|
32
37
|
- lib/coderay/encoders/html/css.rb
|
33
38
|
- lib/coderay/encoders/html/numbering.rb
|
34
39
|
- lib/coderay/encoders/html/output.rb
|
35
|
-
- lib/coderay/encoders/html.rb
|
36
40
|
- lib/coderay/encoders/json.rb
|
37
41
|
- lib/coderay/encoders/lines_of_code.rb
|
38
42
|
- lib/coderay/encoders/null.rb
|
@@ -62,16 +66,16 @@ files:
|
|
62
66
|
- lib/coderay/scanners/groovy.rb
|
63
67
|
- lib/coderay/scanners/haml.rb
|
64
68
|
- lib/coderay/scanners/html.rb
|
65
|
-
- lib/coderay/scanners/java/builtin_types.rb
|
66
69
|
- lib/coderay/scanners/java.rb
|
70
|
+
- lib/coderay/scanners/java/builtin_types.rb
|
67
71
|
- lib/coderay/scanners/java_script.rb
|
68
72
|
- lib/coderay/scanners/json.rb
|
69
73
|
- lib/coderay/scanners/php.rb
|
70
74
|
- lib/coderay/scanners/python.rb
|
71
75
|
- lib/coderay/scanners/raydebug.rb
|
76
|
+
- lib/coderay/scanners/ruby.rb
|
72
77
|
- lib/coderay/scanners/ruby/patterns.rb
|
73
78
|
- lib/coderay/scanners/ruby/string_state.rb
|
74
|
-
- lib/coderay/scanners/ruby.rb
|
75
79
|
- lib/coderay/scanners/sql.rb
|
76
80
|
- lib/coderay/scanners/text.rb
|
77
81
|
- lib/coderay/scanners/xml.rb
|
@@ -83,10 +87,6 @@ files:
|
|
83
87
|
- lib/coderay/tokens.rb
|
84
88
|
- lib/coderay/tokens_proxy.rb
|
85
89
|
- lib/coderay/version.rb
|
86
|
-
- lib/coderay.rb
|
87
|
-
- Rakefile
|
88
|
-
- README_INDEX.rdoc
|
89
|
-
- LICENSE
|
90
90
|
- test/functional/basic.rb
|
91
91
|
- test/functional/examples.rb
|
92
92
|
- test/functional/for_redcloth.rb
|
@@ -106,13 +106,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.8.
|
109
|
+
version: 1.8.6
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|
113
|
-
- - ! '
|
113
|
+
- - ! '>='
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
115
|
+
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project: coderay
|
118
118
|
rubygems_version: 1.8.10
|