coderay 1.1.0 → 1.1.1.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.
- checksums.yaml +4 -4
- data/bin/coderay +1 -1
- data/lib/coderay.rb +9 -9
- data/lib/coderay/encoders.rb +18 -0
- data/lib/coderay/{encoder.rb → encoders/encoder.rb} +0 -11
- data/lib/coderay/encoders/html.rb +3 -2
- data/lib/coderay/helpers/plugin.rb +0 -219
- data/lib/coderay/helpers/plugin_host.rb +221 -0
- data/lib/coderay/scanners.rb +27 -0
- data/lib/coderay/scanners/diff.rb +1 -1
- data/lib/coderay/scanners/java.rb +1 -1
- data/lib/coderay/scanners/ruby.rb +13 -6
- data/lib/coderay/scanners/ruby/patterns.rb +1 -1
- data/lib/coderay/scanners/ruby/string_state.rb +8 -0
- data/lib/coderay/{scanner.rb → scanners/scanner.rb} +0 -18
- data/lib/coderay/scanners/sql.rb +17 -25
- data/lib/coderay/styles.rb +15 -0
- data/lib/coderay/styles/alpha.rb +2 -1
- data/lib/coderay/{style.rb → styles/style.rb} +1 -6
- data/lib/coderay/version.rb +1 -1
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db55e93b3bbf78f5735b2f773d6045bed6440396
|
4
|
+
data.tar.gz: e3a4924713b0ddeb0e020a7458bead68a3e8392b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dac94e6b64bb0b3539338dcb8d124516c0b00b4197a914fef9d6f005fb31f305672a01aba9a4b850e7ecd7d335e353edeb71a6b23697f65ea6fa5682630cdff
|
7
|
+
data.tar.gz: 7e22b33be218c07b18dbefd507dc5ef468c91c1d38e5bc5043114a11fa575b77e77f5d4e09f99c9e933c415b5505a22e242acd84c2eecad306a44e3a35366e8a
|
data/bin/coderay
CHANGED
@@ -35,7 +35,7 @@ defaults:
|
|
35
35
|
|
36
36
|
common:
|
37
37
|
coderay file.rb # highlight file to terminal
|
38
|
-
coderay file.rb > file.html
|
38
|
+
coderay file.rb -page > file.html # highlight file to HTML page
|
39
39
|
coderay file.rb -div > file.html # highlight file to HTML snippet
|
40
40
|
|
41
41
|
configure output:
|
data/lib/coderay.rb
CHANGED
@@ -134,7 +134,7 @@ module CodeRay
|
|
134
134
|
File.join CODERAY_PATH, *path
|
135
135
|
end
|
136
136
|
|
137
|
-
|
137
|
+
autoload :VERSION, 'coderay/version'
|
138
138
|
|
139
139
|
# helpers
|
140
140
|
autoload :FileType, coderay_path('helpers', 'file_type')
|
@@ -145,13 +145,13 @@ module CodeRay
|
|
145
145
|
autoload :TokenKinds, coderay_path('token_kinds')
|
146
146
|
|
147
147
|
# Plugin system
|
148
|
-
autoload :PluginHost, coderay_path('helpers', '
|
148
|
+
autoload :PluginHost, coderay_path('helpers', 'plugin_host')
|
149
149
|
autoload :Plugin, coderay_path('helpers', 'plugin')
|
150
150
|
|
151
151
|
# Plugins
|
152
|
-
autoload :Scanners, coderay_path('
|
153
|
-
autoload :Encoders, coderay_path('
|
154
|
-
autoload :Styles, coderay_path('
|
152
|
+
autoload :Scanners, coderay_path('scanners')
|
153
|
+
autoload :Encoders, coderay_path('encoders')
|
154
|
+
autoload :Styles, coderay_path('styles')
|
155
155
|
|
156
156
|
# convenience access and reusable Encoder/Scanner pair
|
157
157
|
autoload :Duo, coderay_path('duo')
|
@@ -166,7 +166,7 @@ module CodeRay
|
|
166
166
|
#
|
167
167
|
# See also demo/demo_simple.
|
168
168
|
def scan code, lang, options = {}, &block
|
169
|
-
TokensProxy.new code, lang, options, block
|
169
|
+
CodeRay::TokensProxy.new code, lang, options, block
|
170
170
|
end
|
171
171
|
|
172
172
|
# Scans +filename+ (a path to a code file) with the Scanner for +lang+.
|
@@ -181,7 +181,7 @@ module CodeRay
|
|
181
181
|
# require 'coderay'
|
182
182
|
# page = CodeRay.scan_file('some_c_code.c').html
|
183
183
|
def scan_file filename, lang = :auto, options = {}, &block
|
184
|
-
lang = FileType.fetch filename, :text, true if lang == :auto
|
184
|
+
lang = CodeRay::FileType.fetch filename, :text, true if lang == :auto
|
185
185
|
code = File.read filename
|
186
186
|
scan code, lang, options, &block
|
187
187
|
end
|
@@ -258,7 +258,7 @@ module CodeRay
|
|
258
258
|
# ]
|
259
259
|
# #-> 2 out of 4 tokens have the kind :integer.
|
260
260
|
def encoder format, options = {}
|
261
|
-
Encoders[format].new options
|
261
|
+
CodeRay::Encoders[format].new options
|
262
262
|
end
|
263
263
|
|
264
264
|
# Finds the Scanner class for +lang+ and creates an instance, passing
|
@@ -266,7 +266,7 @@ module CodeRay
|
|
266
266
|
#
|
267
267
|
# See Scanner.new.
|
268
268
|
def scanner lang, options = {}, &block
|
269
|
-
Scanners[lang].new '', options, &block
|
269
|
+
CodeRay::Scanners[lang].new '', options, &block
|
270
270
|
end
|
271
271
|
|
272
272
|
# Extract the options for the scanner from the +options+ hash.
|
@@ -0,0 +1,18 @@
|
|
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
|
+
|
12
|
+
extend PluginHost
|
13
|
+
plugin_path File.dirname(__FILE__), 'encoders'
|
14
|
+
|
15
|
+
autoload :Encoder, CodeRay.coderay_path('encoders', 'encoder')
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -1,17 +1,6 @@
|
|
1
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
2
|
module Encoders
|
11
3
|
|
12
|
-
extend PluginHost
|
13
|
-
plugin_path File.dirname(__FILE__), 'encoders'
|
14
|
-
|
15
4
|
# = Encoder
|
16
5
|
#
|
17
6
|
# The Encoder base class. Together with Scanner and
|
@@ -25,7 +25,8 @@ module Encoders
|
|
25
25
|
# == Options
|
26
26
|
#
|
27
27
|
# === :tab_width
|
28
|
-
# Convert \t characters to +n+ spaces (a number.)
|
28
|
+
# Convert \t characters to +n+ spaces (a number or false.)
|
29
|
+
# false will keep tab characters untouched.
|
29
30
|
#
|
30
31
|
# Default: 8
|
31
32
|
#
|
@@ -180,7 +181,7 @@ module Encoders
|
|
180
181
|
|
181
182
|
@break_lines = (options[:break_lines] == true)
|
182
183
|
|
183
|
-
@HTML_ESCAPE = HTML_ESCAPE.merge("\t" => ' ' * options[:tab_width])
|
184
|
+
@HTML_ESCAPE = HTML_ESCAPE.merge("\t" => options[:tab_width] ? ' ' * options[:tab_width] : "\t")
|
184
185
|
|
185
186
|
@opened = []
|
186
187
|
@last_opened = nil
|
@@ -1,224 +1,5 @@
|
|
1
1
|
module CodeRay
|
2
2
|
|
3
|
-
# = PluginHost
|
4
|
-
#
|
5
|
-
# A simple subclass/subfolder plugin system.
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
# class Generators
|
9
|
-
# extend PluginHost
|
10
|
-
# plugin_path 'app/generators'
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# class Generator
|
14
|
-
# extend Plugin
|
15
|
-
# PLUGIN_HOST = Generators
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# class FancyGenerator < Generator
|
19
|
-
# register_for :fancy
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# Generators[:fancy] #-> FancyGenerator
|
23
|
-
# # or
|
24
|
-
# CodeRay.require_plugin 'Generators/fancy'
|
25
|
-
# # or
|
26
|
-
# Generators::Fancy
|
27
|
-
module PluginHost
|
28
|
-
|
29
|
-
# Raised if Encoders::[] fails because:
|
30
|
-
# * a file could not be found
|
31
|
-
# * the requested Plugin is not registered
|
32
|
-
PluginNotFound = Class.new LoadError
|
33
|
-
HostNotFound = Class.new LoadError
|
34
|
-
|
35
|
-
PLUGIN_HOSTS = []
|
36
|
-
PLUGIN_HOSTS_BY_ID = {} # dummy hash
|
37
|
-
|
38
|
-
# Loads all plugins using list and load.
|
39
|
-
def load_all
|
40
|
-
for plugin in list
|
41
|
-
load plugin
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the Plugin for +id+.
|
46
|
-
#
|
47
|
-
# Example:
|
48
|
-
# yaml_plugin = MyPluginHost[:yaml]
|
49
|
-
def [] id, *args, &blk
|
50
|
-
plugin = validate_id(id)
|
51
|
-
begin
|
52
|
-
plugin = plugin_hash.[](plugin, *args, &blk)
|
53
|
-
end while plugin.is_a? String
|
54
|
-
plugin
|
55
|
-
end
|
56
|
-
|
57
|
-
alias load []
|
58
|
-
|
59
|
-
# Tries to +load+ the missing plugin by translating +const+ to the
|
60
|
-
# underscore form (eg. LinesOfCode becomes lines_of_code).
|
61
|
-
def const_missing const
|
62
|
-
id = const.to_s.
|
63
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
64
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
65
|
-
downcase
|
66
|
-
load id
|
67
|
-
end
|
68
|
-
|
69
|
-
class << self
|
70
|
-
|
71
|
-
# Adds the module/class to the PLUGIN_HOSTS list.
|
72
|
-
def extended mod
|
73
|
-
PLUGIN_HOSTS << mod
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
# The path where the plugins can be found.
|
79
|
-
def plugin_path *args
|
80
|
-
unless args.empty?
|
81
|
-
@plugin_path = File.expand_path File.join(*args)
|
82
|
-
end
|
83
|
-
@plugin_path ||= ''
|
84
|
-
end
|
85
|
-
|
86
|
-
# Map a plugin_id to another.
|
87
|
-
#
|
88
|
-
# Usage: Put this in a file plugin_path/_map.rb.
|
89
|
-
#
|
90
|
-
# class MyColorHost < PluginHost
|
91
|
-
# map :navy => :dark_blue,
|
92
|
-
# :maroon => :brown,
|
93
|
-
# :luna => :moon
|
94
|
-
# end
|
95
|
-
def map hash
|
96
|
-
for from, to in hash
|
97
|
-
from = validate_id from
|
98
|
-
to = validate_id to
|
99
|
-
plugin_hash[from] = to unless plugin_hash.has_key? from
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Define the default plugin to use when no plugin is found
|
104
|
-
# for a given id, or return the default plugin.
|
105
|
-
#
|
106
|
-
# See also map.
|
107
|
-
#
|
108
|
-
# class MyColorHost < PluginHost
|
109
|
-
# map :navy => :dark_blue
|
110
|
-
# default :gray
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# MyColorHost.default # loads and returns the Gray plugin
|
114
|
-
def default id = nil
|
115
|
-
if id
|
116
|
-
id = validate_id id
|
117
|
-
raise "The default plugin can't be named \"default\"." if id == :default
|
118
|
-
plugin_hash[:default] = id
|
119
|
-
else
|
120
|
-
load :default
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Every plugin must register itself for +id+ by calling register_for,
|
125
|
-
# which calls this method.
|
126
|
-
#
|
127
|
-
# See Plugin#register_for.
|
128
|
-
def register plugin, id
|
129
|
-
plugin_hash[validate_id(id)] = plugin
|
130
|
-
end
|
131
|
-
|
132
|
-
# A Hash of plugion_id => Plugin pairs.
|
133
|
-
def plugin_hash
|
134
|
-
@plugin_hash ||= (@plugin_hash = make_plugin_hash).tap { load_plugin_map }
|
135
|
-
end
|
136
|
-
|
137
|
-
# Returns an array of all .rb files in the plugin path.
|
138
|
-
#
|
139
|
-
# The extension .rb is not included.
|
140
|
-
def list
|
141
|
-
Dir[path_to('*')].select do |file|
|
142
|
-
File.basename(file)[/^(?!_)\w+\.rb$/]
|
143
|
-
end.map do |file|
|
144
|
-
File.basename(file, '.rb').to_sym
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Returns an array of all Plugins.
|
149
|
-
#
|
150
|
-
# Note: This loads all plugins using load_all.
|
151
|
-
def all_plugins
|
152
|
-
load_all
|
153
|
-
plugin_hash.values.grep(Class)
|
154
|
-
end
|
155
|
-
|
156
|
-
# Loads the map file (see map).
|
157
|
-
#
|
158
|
-
# This is done automatically when plugin_path is called.
|
159
|
-
def load_plugin_map
|
160
|
-
mapfile = path_to '_map'
|
161
|
-
if File.exist? mapfile
|
162
|
-
require mapfile
|
163
|
-
true
|
164
|
-
else
|
165
|
-
false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
protected
|
170
|
-
|
171
|
-
# Return a plugin hash that automatically loads plugins.
|
172
|
-
def make_plugin_hash
|
173
|
-
Hash.new do |h, plugin_id|
|
174
|
-
id = validate_id(plugin_id)
|
175
|
-
path = path_to id
|
176
|
-
begin
|
177
|
-
require path
|
178
|
-
rescue LoadError => boom
|
179
|
-
if h.has_key?(:default)
|
180
|
-
h[:default]
|
181
|
-
else
|
182
|
-
raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]
|
183
|
-
end
|
184
|
-
else
|
185
|
-
# Plugin should have registered by now
|
186
|
-
if h.has_key? id
|
187
|
-
h[id]
|
188
|
-
else
|
189
|
-
raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}."
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# Returns the expected path to the plugin file for the given id.
|
196
|
-
def path_to plugin_id
|
197
|
-
File.join plugin_path, "#{plugin_id}.rb"
|
198
|
-
end
|
199
|
-
|
200
|
-
# Converts +id+ to a valid plugin ID String, or returns +nil+.
|
201
|
-
#
|
202
|
-
# Raises +ArgumentError+ for all other objects, or if the
|
203
|
-
# given String includes non-alphanumeric characters (\W).
|
204
|
-
def validate_id id
|
205
|
-
case id
|
206
|
-
when Symbol
|
207
|
-
id.to_s
|
208
|
-
when String
|
209
|
-
if id[/\w+/] == id
|
210
|
-
id.downcase
|
211
|
-
else
|
212
|
-
raise ArgumentError, "Invalid id given: #{id}"
|
213
|
-
end
|
214
|
-
else
|
215
|
-
raise ArgumentError, "Symbol or String expected, but #{id.class} given."
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
end
|
220
|
-
|
221
|
-
|
222
3
|
# = Plugin
|
223
4
|
#
|
224
5
|
# Plugins have to include this module.
|
@@ -0,0 +1,221 @@
|
|
1
|
+
module CodeRay
|
2
|
+
|
3
|
+
# = PluginHost
|
4
|
+
#
|
5
|
+
# A simple subclass/subfolder plugin system.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# class Generators
|
9
|
+
# extend PluginHost
|
10
|
+
# plugin_path 'app/generators'
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# class Generator
|
14
|
+
# extend Plugin
|
15
|
+
# PLUGIN_HOST = Generators
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# class FancyGenerator < Generator
|
19
|
+
# register_for :fancy
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# Generators[:fancy] #-> FancyGenerator
|
23
|
+
# # or
|
24
|
+
# CodeRay.require_plugin 'Generators/fancy'
|
25
|
+
# # or
|
26
|
+
# Generators::Fancy
|
27
|
+
module PluginHost
|
28
|
+
|
29
|
+
# Raised if Encoders::[] fails because:
|
30
|
+
# * a file could not be found
|
31
|
+
# * the requested Plugin is not registered
|
32
|
+
PluginNotFound = Class.new LoadError
|
33
|
+
HostNotFound = Class.new LoadError
|
34
|
+
|
35
|
+
PLUGIN_HOSTS = []
|
36
|
+
PLUGIN_HOSTS_BY_ID = {} # dummy hash
|
37
|
+
|
38
|
+
# Loads all plugins using list and load.
|
39
|
+
def load_all
|
40
|
+
for plugin in list
|
41
|
+
load plugin
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the Plugin for +id+.
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
# yaml_plugin = MyPluginHost[:yaml]
|
49
|
+
def [] id, *args, &blk
|
50
|
+
plugin = validate_id(id)
|
51
|
+
begin
|
52
|
+
plugin = plugin_hash.[](plugin, *args, &blk)
|
53
|
+
end while plugin.is_a? String
|
54
|
+
plugin
|
55
|
+
end
|
56
|
+
|
57
|
+
alias load []
|
58
|
+
|
59
|
+
# Tries to +load+ the missing plugin by translating +const+ to the
|
60
|
+
# underscore form (eg. LinesOfCode becomes lines_of_code).
|
61
|
+
def const_missing const
|
62
|
+
id = const.to_s.
|
63
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
64
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
65
|
+
downcase
|
66
|
+
load id
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
|
71
|
+
# Adds the module/class to the PLUGIN_HOSTS list.
|
72
|
+
def extended mod
|
73
|
+
PLUGIN_HOSTS << mod
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
# The path where the plugins can be found.
|
79
|
+
def plugin_path *args
|
80
|
+
unless args.empty?
|
81
|
+
@plugin_path = File.expand_path File.join(*args)
|
82
|
+
end
|
83
|
+
@plugin_path ||= ''
|
84
|
+
end
|
85
|
+
|
86
|
+
# Map a plugin_id to another.
|
87
|
+
#
|
88
|
+
# Usage: Put this in a file plugin_path/_map.rb.
|
89
|
+
#
|
90
|
+
# class MyColorHost < PluginHost
|
91
|
+
# map :navy => :dark_blue,
|
92
|
+
# :maroon => :brown,
|
93
|
+
# :luna => :moon
|
94
|
+
# end
|
95
|
+
def map hash
|
96
|
+
for from, to in hash
|
97
|
+
from = validate_id from
|
98
|
+
to = validate_id to
|
99
|
+
plugin_hash[from] = to unless plugin_hash.has_key? from
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Define the default plugin to use when no plugin is found
|
104
|
+
# for a given id, or return the default plugin.
|
105
|
+
#
|
106
|
+
# See also map.
|
107
|
+
#
|
108
|
+
# class MyColorHost < PluginHost
|
109
|
+
# map :navy => :dark_blue
|
110
|
+
# default :gray
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# MyColorHost.default # loads and returns the Gray plugin
|
114
|
+
def default id = nil
|
115
|
+
if id
|
116
|
+
id = validate_id id
|
117
|
+
raise "The default plugin can't be named \"default\"." if id == :default
|
118
|
+
plugin_hash[:default] = id
|
119
|
+
else
|
120
|
+
load :default
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Every plugin must register itself for +id+ by calling register_for,
|
125
|
+
# which calls this method.
|
126
|
+
#
|
127
|
+
# See Plugin#register_for.
|
128
|
+
def register plugin, id
|
129
|
+
plugin_hash[validate_id(id)] = plugin
|
130
|
+
end
|
131
|
+
|
132
|
+
# A Hash of plugion_id => Plugin pairs.
|
133
|
+
def plugin_hash
|
134
|
+
@plugin_hash ||= (@plugin_hash = make_plugin_hash).tap { load_plugin_map }
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns an array of all .rb files in the plugin path.
|
138
|
+
#
|
139
|
+
# The extension .rb is not included.
|
140
|
+
def list
|
141
|
+
Dir[path_to('*')].select do |file|
|
142
|
+
File.basename(file)[/^(?!_)\w+\.rb$/]
|
143
|
+
end.map do |file|
|
144
|
+
File.basename(file, '.rb').to_sym
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns an array of all Plugins.
|
149
|
+
#
|
150
|
+
# Note: This loads all plugins using load_all.
|
151
|
+
def all_plugins
|
152
|
+
load_all
|
153
|
+
plugin_hash.values.grep(Class)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Loads the map file (see map).
|
157
|
+
#
|
158
|
+
# This is done automatically when plugin_path is called.
|
159
|
+
def load_plugin_map
|
160
|
+
mapfile = path_to '_map'
|
161
|
+
if File.exist? mapfile
|
162
|
+
require mapfile
|
163
|
+
true
|
164
|
+
else
|
165
|
+
false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
protected
|
170
|
+
|
171
|
+
# Return a plugin hash that automatically loads plugins.
|
172
|
+
def make_plugin_hash
|
173
|
+
Hash.new do |h, plugin_id|
|
174
|
+
id = validate_id(plugin_id)
|
175
|
+
path = path_to id
|
176
|
+
begin
|
177
|
+
require path
|
178
|
+
rescue LoadError => boom
|
179
|
+
if h.has_key?(:default)
|
180
|
+
h[:default]
|
181
|
+
else
|
182
|
+
raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]
|
183
|
+
end
|
184
|
+
else
|
185
|
+
# Plugin should have registered by now
|
186
|
+
if h.has_key? id
|
187
|
+
h[id]
|
188
|
+
else
|
189
|
+
raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}."
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Returns the expected path to the plugin file for the given id.
|
196
|
+
def path_to plugin_id
|
197
|
+
File.join plugin_path, "#{plugin_id}.rb"
|
198
|
+
end
|
199
|
+
|
200
|
+
# Converts +id+ to a valid plugin ID String, or returns +nil+.
|
201
|
+
#
|
202
|
+
# Raises +ArgumentError+ for all other objects, or if the
|
203
|
+
# given String includes non-alphanumeric characters (\W).
|
204
|
+
def validate_id id
|
205
|
+
case id
|
206
|
+
when Symbol
|
207
|
+
id.to_s
|
208
|
+
when String
|
209
|
+
if id[/\w+/] == id
|
210
|
+
id.downcase
|
211
|
+
else
|
212
|
+
raise ArgumentError, "Invalid id given: #{id}"
|
213
|
+
end
|
214
|
+
else
|
215
|
+
raise ArgumentError, "Symbol or String expected, but #{id.class} given."
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
module CodeRay
|
4
|
+
|
5
|
+
autoload :WordList, coderay_path('helpers', 'word_list')
|
6
|
+
|
7
|
+
# = Scanners
|
8
|
+
#
|
9
|
+
# This module holds the Scanner class and its subclasses.
|
10
|
+
# For example, the Ruby scanner is named CodeRay::Scanners::Ruby
|
11
|
+
# can be found in coderay/scanners/ruby.
|
12
|
+
#
|
13
|
+
# Scanner also provides methods and constants for the register
|
14
|
+
# mechanism and the [] method that returns the Scanner class
|
15
|
+
# belonging to the given lang.
|
16
|
+
#
|
17
|
+
# See PluginHost.
|
18
|
+
module Scanners
|
19
|
+
|
20
|
+
extend PluginHost
|
21
|
+
plugin_path File.dirname(__FILE__), 'scanners'
|
22
|
+
|
23
|
+
autoload :Scanner, CodeRay.coderay_path('scanners', 'scanner')
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -100,7 +100,7 @@ module Scanners
|
|
100
100
|
next
|
101
101
|
elsif match = scan(/-/)
|
102
102
|
deleted_lines_count += 1
|
103
|
-
if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/.*(?:\n\-.*)*/).count("\n")) && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/)
|
103
|
+
if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/.*(?:\n\-.*)*/).count("\n")) && changed_lines_count <= 100_000 && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/)
|
104
104
|
deleted_lines = Array.new(changed_lines_count) { |i| skip(/\n\-/) if i > 0; scan(/.*/) }
|
105
105
|
inserted_lines = Array.new(changed_lines_count) { |i| skip(/\n\+/) ; scan(/.*/) }
|
106
106
|
|
@@ -36,7 +36,7 @@ module Scanners
|
|
36
36
|
add(BuiltinTypes::List, :predefined_type).
|
37
37
|
add(BuiltinTypes::List.select { |builtin| builtin[/(Error|Exception)$/] }, :exception).
|
38
38
|
add(DIRECTIVES, :directive) # :nodoc:
|
39
|
-
|
39
|
+
|
40
40
|
ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
|
41
41
|
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
|
42
42
|
STRING_CONTENT_PATTERN = {
|
@@ -164,15 +164,19 @@ module Scanners
|
|
164
164
|
end
|
165
165
|
|
166
166
|
elsif match = scan(/ ' (?:(?>[^'\\]*) ')? | " (?:(?>[^"\\\#]*) ")? /mx)
|
167
|
-
encoder.begin_group :string
|
168
167
|
if match.size == 1
|
168
|
+
kind = check(self.class::StringState.simple_key_pattern(match)) ? :key : :string
|
169
|
+
encoder.begin_group kind
|
169
170
|
encoder.text_token match, :delimiter
|
170
|
-
state = self.class::StringState.new
|
171
|
+
state = self.class::StringState.new kind, match == '"', match # important for streaming
|
171
172
|
else
|
173
|
+
kind = value_expected == true && scan(/:/) ? :key : :string
|
174
|
+
encoder.begin_group kind
|
172
175
|
encoder.text_token match[0,1], :delimiter
|
173
176
|
encoder.text_token match[1..-2], :content if match.size > 2
|
174
177
|
encoder.text_token match[-1,1], :delimiter
|
175
|
-
encoder.end_group
|
178
|
+
encoder.end_group kind
|
179
|
+
encoder.text_token ':', :operator if kind == :key
|
176
180
|
value_expected = false
|
177
181
|
end
|
178
182
|
|
@@ -191,11 +195,14 @@ module Scanners
|
|
191
195
|
encoder.text_token match, :error
|
192
196
|
method_call_expected = false
|
193
197
|
else
|
194
|
-
|
198
|
+
kind = self[1] ? :float : :integer # TODO: send :hex/:octal/:binary
|
199
|
+
match << 'r' if match !~ /e/i && scan(/r/)
|
200
|
+
match << 'i' if scan(/i/)
|
201
|
+
encoder.text_token match, kind
|
195
202
|
end
|
196
203
|
value_expected = false
|
197
204
|
|
198
|
-
elsif match = scan(/ [-+!~^\/]=? | [:;] | [*|&]{1,2}=? | >>? /x)
|
205
|
+
elsif match = scan(/ [-+!~^\/]=? | [:;] | &\. | [*|&]{1,2}=? | >>? /x)
|
199
206
|
value_expected = true
|
200
207
|
encoder.text_token match, :operator
|
201
208
|
|
@@ -208,7 +215,7 @@ module Scanners
|
|
208
215
|
encoder.end_group kind
|
209
216
|
heredocs ||= [] # create heredocs if empty
|
210
217
|
heredocs << self.class::StringState.new(kind, quote != "'", delim,
|
211
|
-
self[1]
|
218
|
+
self[1] ? :indented : :linestart)
|
212
219
|
value_expected = false
|
213
220
|
|
214
221
|
elsif value_expected && match = scan(/#{patterns::FANCY_STRING_START}/o)
|
@@ -37,6 +37,14 @@ module Scanners
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def self.simple_key_pattern delim
|
41
|
+
if delim == "'"
|
42
|
+
/ (?> (?: [^\\']+ | \\. )* ) ' : /mx
|
43
|
+
else
|
44
|
+
/ (?> (?: [^\\"\#]+ | \\. | \#\$[\\"] | \#\{[^\{\}]+\} | \#(?!\{) )* ) " : /mx
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
40
48
|
def initialize kind, interpreted, delim, heredoc = false
|
41
49
|
if heredoc
|
42
50
|
pattern = heredoc_pattern delim, interpreted, heredoc == :indented
|
@@ -1,25 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'strscan'
|
3
2
|
|
4
3
|
module CodeRay
|
5
|
-
|
6
|
-
autoload :WordList, coderay_path('helpers', 'word_list')
|
7
|
-
|
8
|
-
# = Scanners
|
9
|
-
#
|
10
|
-
# This module holds the Scanner class and its subclasses.
|
11
|
-
# For example, the Ruby scanner is named CodeRay::Scanners::Ruby
|
12
|
-
# can be found in coderay/scanners/ruby.
|
13
|
-
#
|
14
|
-
# Scanner also provides methods and constants for the register
|
15
|
-
# mechanism and the [] method that returns the Scanner class
|
16
|
-
# belonging to the given lang.
|
17
|
-
#
|
18
|
-
# See PluginHost.
|
19
4
|
module Scanners
|
20
|
-
extend PluginHost
|
21
|
-
plugin_path File.dirname(__FILE__), 'scanners'
|
22
|
-
|
23
5
|
|
24
6
|
# = Scanner
|
25
7
|
#
|
data/lib/coderay/scanners/sql.rb
CHANGED
@@ -57,6 +57,12 @@ module Scanners
|
|
57
57
|
|
58
58
|
STRING_PREFIXES = /[xnb]|_\w+/i
|
59
59
|
|
60
|
+
STRING_CONTENT_PATTERN = {
|
61
|
+
'"' => / (?: [^\\"] | "" )+ /x,
|
62
|
+
"'" => / (?: [^\\'] | '' )+ /x,
|
63
|
+
'`' => / (?: [^\\`] | `` )+ /x,
|
64
|
+
}
|
65
|
+
|
60
66
|
def scan_tokens encoder, options
|
61
67
|
|
62
68
|
state = :initial
|
@@ -90,7 +96,7 @@ module Scanners
|
|
90
96
|
state = :string
|
91
97
|
encoder.text_token match, :delimiter
|
92
98
|
|
93
|
-
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /x)
|
99
|
+
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9\$]* /x)
|
94
100
|
encoder.text_token match, name_expected ? :ident : (match[0] == ?@ ? :variable : IDENT_KIND[match])
|
95
101
|
name_expected = false
|
96
102
|
|
@@ -115,40 +121,26 @@ module Scanners
|
|
115
121
|
end
|
116
122
|
|
117
123
|
elsif state == :string
|
118
|
-
if match = scan(
|
119
|
-
|
120
|
-
next
|
124
|
+
if match = scan(STRING_CONTENT_PATTERN[string_type])
|
125
|
+
encoder.text_token match, :content
|
121
126
|
elsif match = scan(/["'`]/)
|
122
127
|
if string_type == match
|
123
128
|
if peek(1) == string_type # doubling means escape
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
129
|
+
encoder.text_token match + getch, :content
|
130
|
+
else
|
131
|
+
encoder.text_token match, :delimiter
|
132
|
+
encoder.end_group :string
|
133
|
+
state = :initial
|
134
|
+
string_type = nil
|
130
135
|
end
|
131
|
-
encoder.text_token match, :delimiter
|
132
|
-
encoder.end_group :string
|
133
|
-
state = :initial
|
134
|
-
string_type = nil
|
135
136
|
else
|
136
|
-
|
137
|
+
encoder.text_token match, :content
|
137
138
|
end
|
138
139
|
elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
139
|
-
unless string_content.empty?
|
140
|
-
encoder.text_token string_content, :content
|
141
|
-
string_content = ''
|
142
|
-
end
|
143
140
|
encoder.text_token match, :char
|
144
141
|
elsif match = scan(/ \\ . /mox)
|
145
|
-
|
146
|
-
next
|
142
|
+
encoder.text_token match, :content
|
147
143
|
elsif match = scan(/ \\ | $ /x)
|
148
|
-
unless string_content.empty?
|
149
|
-
encoder.text_token string_content, :content
|
150
|
-
string_content = ''
|
151
|
-
end
|
152
144
|
encoder.text_token match, :error unless match.empty?
|
153
145
|
encoder.end_group :string
|
154
146
|
state = :initial
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CodeRay
|
2
|
+
|
3
|
+
# This module holds the Style class and its subclasses.
|
4
|
+
#
|
5
|
+
# See Plugin.
|
6
|
+
module Styles
|
7
|
+
|
8
|
+
extend PluginHost
|
9
|
+
plugin_path File.dirname(__FILE__), 'styles'
|
10
|
+
|
11
|
+
autoload :Style, CodeRay.coderay_path('styles', 'style')
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/coderay/styles/alpha.rb
CHANGED
@@ -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:#
|
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 }
|
data/lib/coderay/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.1.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:
|
11
|
+
date: 2016-02-13 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.
|
@@ -22,15 +22,17 @@ extra_rdoc_files:
|
|
22
22
|
files:
|
23
23
|
- README_INDEX.rdoc
|
24
24
|
- Rakefile
|
25
|
+
- bin/coderay
|
25
26
|
- lib/coderay.rb
|
26
27
|
- lib/coderay/duo.rb
|
27
|
-
- lib/coderay/
|
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/
|
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,14 +81,16 @@ 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/
|
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
|
@@ -94,31 +99,30 @@ files:
|
|
94
99
|
- test/functional/examples.rb
|
95
100
|
- test/functional/for_redcloth.rb
|
96
101
|
- test/functional/suite.rb
|
97
|
-
- bin/coderay
|
98
102
|
homepage: http://coderay.rubychan.de
|
99
103
|
licenses:
|
100
104
|
- MIT
|
101
105
|
metadata: {}
|
102
106
|
post_install_message:
|
103
107
|
rdoc_options:
|
104
|
-
- -SNw2
|
105
|
-
- -mREADME_INDEX.rdoc
|
106
|
-
- -t CodeRay Documentation
|
108
|
+
- "-SNw2"
|
109
|
+
- "-mREADME_INDEX.rdoc"
|
110
|
+
- "-t CodeRay Documentation"
|
107
111
|
require_paths:
|
108
112
|
- lib
|
109
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
114
|
requirements:
|
111
|
-
- -
|
115
|
+
- - ">="
|
112
116
|
- !ruby/object:Gem::Version
|
113
117
|
version: 1.8.6
|
114
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
119
|
requirements:
|
116
|
-
- -
|
120
|
+
- - ">"
|
117
121
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
122
|
+
version: 1.3.1
|
119
123
|
requirements: []
|
120
124
|
rubyforge_project: coderay
|
121
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.5.1
|
122
126
|
signing_key:
|
123
127
|
specification_version: 4
|
124
128
|
summary: Fast syntax highlighting for selected languages.
|