coderay 1.1.0 → 1.1.3.rc1

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.
@@ -82,7 +82,8 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
82
82
  .exception { color:#C00; font-weight:bold }
83
83
  .float { color:#60E }
84
84
  .function { color:#06B; font-weight:bold }
85
- .function .delimiter { color:#024; font-weight:bold }
85
+ .function .delimiter { color:#059 }
86
+ .function .content { color:#037 }
86
87
  .global-variable { color:#d70 }
87
88
  .hex { color:#02b }
88
89
  .id { color:#33D; font-weight:bold }
@@ -1,11 +1,6 @@
1
1
  module CodeRay
2
-
3
- # This module holds the Style class and its subclasses.
4
- #
5
- # See Plugin.
2
+
6
3
  module Styles
7
- extend PluginHost
8
- plugin_path File.dirname(__FILE__), 'styles'
9
4
 
10
5
  # Base class for styles.
11
6
  #
File without changes
@@ -39,6 +39,9 @@ module CodeRay
39
39
  # You can serialize it to a JSON string and store it in a database, pass it
40
40
  # around to encode it more than once, send it to other algorithms...
41
41
  class Tokens < Array
42
+ # Remove Array#filter that is a new alias for Array#select on Ruby 2.6,
43
+ # for method_missing called with filter method.
44
+ undef_method :filter if instance_methods.include?(:filter)
42
45
 
43
46
  # The Scanner instance that created the tokens.
44
47
  attr_accessor :scanner
@@ -1,3 +1,3 @@
1
1
  module CodeRay
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kornelius Kalnbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-31 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fast and easy syntax highlighting for selected languages, written in
14
14
  Ruby. Comes with RedCloth integration and LOC counter.
@@ -20,17 +20,19 @@ extensions: []
20
20
  extra_rdoc_files:
21
21
  - README_INDEX.rdoc
22
22
  files:
23
+ - MIT-LICENSE
23
24
  - README_INDEX.rdoc
24
- - Rakefile
25
+ - bin/coderay
25
26
  - lib/coderay.rb
26
27
  - lib/coderay/duo.rb
27
- - lib/coderay/encoder.rb
28
+ - lib/coderay/encoders.rb
28
29
  - lib/coderay/encoders/_map.rb
29
30
  - lib/coderay/encoders/comment_filter.rb
30
31
  - lib/coderay/encoders/count.rb
31
32
  - lib/coderay/encoders/debug.rb
32
33
  - lib/coderay/encoders/debug_lint.rb
33
34
  - lib/coderay/encoders/div.rb
35
+ - lib/coderay/encoders/encoder.rb
34
36
  - lib/coderay/encoders/filter.rb
35
37
  - lib/coderay/encoders/html.rb
36
38
  - lib/coderay/encoders/html/css.rb
@@ -51,8 +53,9 @@ files:
51
53
  - lib/coderay/for_redcloth.rb
52
54
  - lib/coderay/helpers/file_type.rb
53
55
  - lib/coderay/helpers/plugin.rb
56
+ - lib/coderay/helpers/plugin_host.rb
54
57
  - lib/coderay/helpers/word_list.rb
55
- - lib/coderay/scanner.rb
58
+ - lib/coderay/scanners.rb
56
59
  - lib/coderay/scanners/_map.rb
57
60
  - lib/coderay/scanners/c.rb
58
61
  - lib/coderay/scanners/clojure.rb
@@ -78,52 +81,44 @@ files:
78
81
  - lib/coderay/scanners/ruby/patterns.rb
79
82
  - lib/coderay/scanners/ruby/string_state.rb
80
83
  - lib/coderay/scanners/sass.rb
84
+ - lib/coderay/scanners/scanner.rb
81
85
  - lib/coderay/scanners/sql.rb
82
86
  - lib/coderay/scanners/taskpaper.rb
83
87
  - lib/coderay/scanners/text.rb
84
88
  - lib/coderay/scanners/xml.rb
85
89
  - lib/coderay/scanners/yaml.rb
86
- - lib/coderay/style.rb
90
+ - lib/coderay/styles.rb
87
91
  - lib/coderay/styles/_map.rb
88
92
  - lib/coderay/styles/alpha.rb
93
+ - lib/coderay/styles/style.rb
89
94
  - lib/coderay/token_kinds.rb
90
95
  - lib/coderay/tokens.rb
91
96
  - lib/coderay/tokens_proxy.rb
92
97
  - lib/coderay/version.rb
93
- - test/functional/basic.rb
94
- - test/functional/examples.rb
95
- - test/functional/for_redcloth.rb
96
- - test/functional/suite.rb
97
- - bin/coderay
98
98
  homepage: http://coderay.rubychan.de
99
99
  licenses:
100
100
  - MIT
101
101
  metadata: {}
102
102
  post_install_message:
103
103
  rdoc_options:
104
- - -SNw2
105
- - -mREADME_INDEX.rdoc
106
- - -t CodeRay Documentation
104
+ - "-SNw2"
105
+ - "-mREADME_INDEX.rdoc"
106
+ - "-t CodeRay Documentation"
107
107
  require_paths:
108
108
  - lib
109
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '>='
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: 1.8.6
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 1.3.1
119
119
  requirements: []
120
- rubyforge_project: coderay
121
- rubygems_version: 2.0.3
120
+ rubygems_version: 3.0.6
122
121
  signing_key:
123
122
  specification_version: 4
124
123
  summary: Fast syntax highlighting for selected languages.
125
- test_files:
126
- - test/functional/basic.rb
127
- - test/functional/examples.rb
128
- - test/functional/for_redcloth.rb
129
- - test/functional/suite.rb
124
+ test_files: []
data/Rakefile DELETED
@@ -1,37 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- $:.unshift File.dirname(__FILE__) unless $:.include? '.'
4
-
5
- ROOT = '.'
6
- LIB_ROOT = File.join ROOT, 'lib'
7
-
8
- task :default => :test
9
-
10
- if File.directory? 'rake_tasks'
11
-
12
- # load rake tasks from subfolder
13
- for task_file in Dir['rake_tasks/*.rake'].sort
14
- load task_file
15
- end
16
-
17
- else
18
-
19
- # fallback tasks when rake_tasks folder is not present (eg. in the distribution package)
20
- desc 'Run CodeRay tests (basic)'
21
- task :test do
22
- ruby './test/functional/suite.rb'
23
- ruby './test/functional/for_redcloth.rb'
24
- end
25
-
26
- gem 'rdoc' if defined? gem
27
- require 'rdoc/task'
28
- desc 'Generate documentation for CodeRay'
29
- Rake::RDocTask.new :doc do |rd|
30
- rd.title = 'CodeRay Documentation'
31
- rd.main = 'README_INDEX.rdoc'
32
- rd.rdoc_files.add Dir['lib']
33
- rd.rdoc_files.add rd.main
34
- rd.rdoc_dir = 'doc'
35
- end
36
-
37
- end
@@ -1,318 +0,0 @@
1
- # encoding: utf-8
2
- require 'test/unit'
3
- require File.expand_path('../../lib/assert_warning', __FILE__)
4
-
5
- $:.unshift File.expand_path('../../../lib', __FILE__)
6
- require 'coderay'
7
-
8
- class BasicTest < Test::Unit::TestCase
9
-
10
- def test_version
11
- assert_nothing_raised do
12
- assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION)
13
- end
14
- end
15
-
16
- def with_empty_load_path
17
- old_load_path = $:.dup
18
- $:.clear
19
- yield
20
- ensure
21
- $:.replace old_load_path
22
- end
23
-
24
- def test_autoload
25
- with_empty_load_path do
26
- assert_nothing_raised do
27
- CodeRay::Scanners::Java::BuiltinTypes
28
- end
29
- end
30
- end
31
-
32
- RUBY_TEST_CODE = 'puts "Hello, World!"'
33
-
34
- RUBY_TEST_TOKENS = [
35
- ['puts', :ident],
36
- [' ', :space],
37
- [:begin_group, :string],
38
- ['"', :delimiter],
39
- ['Hello, World!', :content],
40
- ['"', :delimiter],
41
- [:end_group, :string]
42
- ].flatten
43
- def test_simple_scan
44
- assert_nothing_raised do
45
- assert_equal RUBY_TEST_TOKENS, CodeRay.scan(RUBY_TEST_CODE, :ruby).tokens
46
- end
47
- end
48
-
49
- RUBY_TEST_HTML = 'puts <span class="string"><span class="delimiter">&quot;</span>' +
50
- '<span class="content">Hello, World!</span><span class="delimiter">&quot;</span></span>'
51
- def test_simple_highlight
52
- assert_nothing_raised do
53
- assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
54
- end
55
- end
56
-
57
- def test_scan_file
58
- CodeRay.scan_file __FILE__
59
- end
60
-
61
- def test_encode
62
- assert_equal 1, CodeRay.encode('test', :python, :count)
63
- end
64
-
65
- def test_encode_tokens
66
- assert_equal 1, CodeRay.encode_tokens(CodeRay::Tokens['test', :string], :count)
67
- end
68
-
69
- def test_encode_file
70
- assert_equal File.read(__FILE__), CodeRay.encode_file(__FILE__, :text)
71
- end
72
-
73
- def test_highlight
74
- assert_match '<pre>test</pre>', CodeRay.highlight('test', :python)
75
- end
76
-
77
- def test_highlight_file
78
- assert_match "require <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">test/unit</span><span class=\"delimiter\">'</span></span>\n", CodeRay.highlight_file(__FILE__)
79
- end
80
-
81
- def test_duo
82
- assert_equal(RUBY_TEST_CODE,
83
- CodeRay::Duo[:plain, :text].highlight(RUBY_TEST_CODE))
84
- assert_equal(RUBY_TEST_CODE,
85
- CodeRay::Duo[:plain => :text].highlight(RUBY_TEST_CODE))
86
- end
87
-
88
- def test_duo_stream
89
- assert_equal(RUBY_TEST_CODE,
90
- CodeRay::Duo[:plain, :text].highlight(RUBY_TEST_CODE, :stream => true))
91
- end
92
-
93
- def test_comment_filter
94
- assert_equal <<-EXPECTED, CodeRay.scan(<<-INPUT, :ruby).comment_filter.text
95
- #!/usr/bin/env ruby
96
-
97
- code
98
-
99
- more code
100
- EXPECTED
101
- #!/usr/bin/env ruby
102
- =begin
103
- A multi-line comment.
104
- =end
105
- code
106
- # A single-line comment.
107
- more code # and another comment, in-line.
108
- INPUT
109
- end
110
-
111
- def test_lines_of_code
112
- assert_equal 2, CodeRay.scan(<<-INPUT, :ruby).lines_of_code
113
- #!/usr/bin/env ruby
114
- =begin
115
- A multi-line comment.
116
- =end
117
- code
118
- # A single-line comment.
119
- more code # and another comment, in-line.
120
- INPUT
121
- rHTML = <<-RHTML
122
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
123
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
124
-
125
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
126
- <head>
127
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
128
- <title><%= controller.controller_name.titleize %>: <%= controller.action_name %></title>
129
- <%= stylesheet_link_tag 'scaffold' %>
130
- </head>
131
- <body>
132
-
133
- <p style="color: green"><%= flash[:notice] %></p>
134
-
135
- <div id="main">
136
- <%= yield %>
137
- </div>
138
-
139
- </body>
140
- </html>
141
- RHTML
142
- assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code
143
- assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code
144
- assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code
145
- assert_equal 4, CodeRay.scan(rHTML, :erb).lines_of_code
146
- end
147
-
148
- def test_list_of_encoders
149
- assert_kind_of(Array, CodeRay::Encoders.list)
150
- assert CodeRay::Encoders.list.include?(:count)
151
- end
152
-
153
- def test_list_of_scanners
154
- assert_kind_of(Array, CodeRay::Scanners.list)
155
- assert CodeRay::Scanners.list.include?(:text)
156
- end
157
-
158
- def test_token_kinds
159
- assert_kind_of Hash, CodeRay::TokenKinds
160
- for kind, css_class in CodeRay::TokenKinds
161
- assert_kind_of Symbol, kind
162
- if css_class != false
163
- assert_kind_of String, css_class, "TokenKinds[%p] == %p" % [kind, css_class]
164
- end
165
- end
166
- assert_equal 'reserved', CodeRay::TokenKinds[:reserved]
167
- assert_equal false, CodeRay::TokenKinds[:shibboleet]
168
- end
169
-
170
- class Milk < CodeRay::Encoders::Encoder
171
- FILE_EXTENSION = 'cocoa'
172
- end
173
-
174
- class HoneyBee < CodeRay::Encoders::Encoder
175
- end
176
-
177
- def test_encoder_file_extension
178
- assert_nothing_raised do
179
- assert_equal 'html', CodeRay::Encoders::Page::FILE_EXTENSION
180
- assert_equal 'cocoa', Milk::FILE_EXTENSION
181
- assert_equal 'cocoa', Milk.new.file_extension
182
- assert_equal 'honeybee', HoneyBee::FILE_EXTENSION
183
- assert_equal 'honeybee', HoneyBee.new.file_extension
184
- end
185
- assert_raise NameError do
186
- HoneyBee::MISSING_CONSTANT
187
- end
188
- end
189
-
190
- def test_encoder_tokens
191
- encoder = CodeRay::Encoders::Encoder.new
192
- encoder.send :setup, {}
193
- assert_raise(ArgumentError) { encoder.token :strange, '' }
194
- encoder.token 'test', :debug
195
- end
196
-
197
- def test_encoder_deprecated_interface
198
- encoder = CodeRay::Encoders::Encoder.new
199
- encoder.send :setup, {}
200
- assert_warning 'Using old Tokens#<< interface.' do
201
- encoder << ['test', :content]
202
- end
203
- assert_raise ArgumentError do
204
- encoder << [:strange, :input]
205
- end
206
- assert_raise ArgumentError do
207
- encoder.encode_tokens [['test', :token]]
208
- end
209
- end
210
-
211
- def encoder_token_interface_deprecation_warning_given
212
- CodeRay::Encoders::Encoder.send :class_variable_get, :@@CODERAY_TOKEN_INTERFACE_DEPRECATION_WARNING_GIVEN
213
- end
214
-
215
- def test_scanner_file_extension
216
- assert_equal 'rb', CodeRay::Scanners::Ruby.file_extension
217
- assert_equal 'rb', CodeRay::Scanners::Ruby.new.file_extension
218
- assert_equal 'java', CodeRay::Scanners::Java.file_extension
219
- assert_equal 'java', CodeRay::Scanners::Java.new.file_extension
220
- end
221
-
222
- def test_scanner_lang
223
- assert_equal :ruby, CodeRay::Scanners::Ruby.lang
224
- assert_equal :ruby, CodeRay::Scanners::Ruby.new.lang
225
- assert_equal :java, CodeRay::Scanners::Java.lang
226
- assert_equal :java, CodeRay::Scanners::Java.new.lang
227
- end
228
-
229
- def test_scanner_tokenize
230
- assert_equal ['foo', :plain], CodeRay::Scanners::Plain.new.tokenize('foo')
231
- assert_equal [['foo', :plain], ['bar', :plain]], CodeRay::Scanners::Plain.new.tokenize(['foo', 'bar'])
232
- CodeRay::Scanners::Plain.new.tokenize 42
233
- end
234
-
235
- def test_scanner_tokens
236
- scanner = CodeRay::Scanners::Plain.new
237
- scanner.tokenize('foo')
238
- assert_equal ['foo', :plain], scanner.tokens
239
- scanner.string = ''
240
- assert_equal ['', :plain], scanner.tokens
241
- end
242
-
243
- def test_scanner_line_and_column
244
- scanner = CodeRay::Scanners::Plain.new "foo\nbär+quux"
245
- assert_equal 0, scanner.pos
246
- assert_equal 1, scanner.line
247
- assert_equal 1, scanner.column
248
- scanner.scan(/foo/)
249
- assert_equal 3, scanner.pos
250
- assert_equal 1, scanner.line
251
- assert_equal 4, scanner.column
252
- scanner.scan(/\n/)
253
- assert_equal 4, scanner.pos
254
- assert_equal 2, scanner.line
255
- assert_equal 1, scanner.column
256
- scanner.scan(/b/)
257
- assert_equal 5, scanner.pos
258
- assert_equal 2, scanner.line
259
- assert_equal 2, scanner.column
260
- scanner.scan(/a/)
261
- assert_equal 5, scanner.pos
262
- assert_equal 2, scanner.line
263
- assert_equal 2, scanner.column
264
- scanner.scan(/ä/)
265
- assert_equal 7, scanner.pos
266
- assert_equal 2, scanner.line
267
- assert_equal 4, scanner.column
268
- scanner.scan(/r/)
269
- assert_equal 8, scanner.pos
270
- assert_equal 2, scanner.line
271
- assert_equal 5, scanner.column
272
- end
273
-
274
- def test_scanner_use_subclasses
275
- assert_raise NotImplementedError do
276
- CodeRay::Scanners::Scanner.new
277
- end
278
- end
279
-
280
- class InvalidScanner < CodeRay::Scanners::Scanner
281
- end
282
-
283
- def test_scanner_scan_tokens
284
- assert_raise NotImplementedError do
285
- InvalidScanner.new.tokenize ''
286
- end
287
- end
288
-
289
- class RaisingScanner < CodeRay::Scanners::Scanner
290
- def scan_tokens encoder, options
291
- raise_inspect 'message', [], :initial
292
- end
293
- end
294
-
295
- def test_scanner_raise_inspect
296
- assert_raise CodeRay::Scanners::Scanner::ScanError do
297
- RaisingScanner.new.tokenize ''
298
- end
299
- end
300
-
301
- def test_scan_a_frozen_string
302
- assert_nothing_raised do
303
- CodeRay.scan RUBY_VERSION, :ruby
304
- CodeRay.scan RUBY_VERSION, :plain
305
- end
306
- end
307
-
308
- def test_scan_a_non_string
309
- assert_nothing_raised do
310
- CodeRay.scan 42, :ruby
311
- CodeRay.scan nil, :ruby
312
- CodeRay.scan self, :ruby
313
- CodeRay.encode ENV.to_hash, :ruby, :page
314
- CodeRay.highlight CodeRay, :plain
315
- end
316
- end
317
-
318
- end