Skip to content

Commit 5c4c006

Browse files
committed
Bug rubychan#6: merge ConradIrwin's approach with korny's
1 parent b3807c5 commit 5c4c006

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

lib/coderay.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,34 @@ module CodeRay
127127

128128
$CODERAY_DEBUG ||= false
129129

130-
# Assuming the rel_path is a subpath of lib/
131-
def self.abs_path(rel_path)
132-
File.join(File.dirname(__FILE__), rel_path)
133-
end
134-
135-
# In order to work in environments that alter $:, we need to
136-
# set the absolute path when autoloading files.
137-
def self.autoload(const_name, rel_path)
138-
super const_name, abs_path(rel_path)
130+
require 'coderay/version'
131+
132+
CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay'
133+
134+
# Assuming the path is a subpath of lib/coderay/
135+
def self.coderay_path *path
136+
File.join CODERAY_PATH, *path
139137
end
140-
141-
require abs_path('coderay/version')
142138

143139
# helpers
144-
autoload :FileType, 'coderay/helpers/file_type'
140+
autoload :FileType, coderay_path('helpers', 'file_type')
145141

146142
# Tokens
147-
autoload :Tokens, 'coderay/tokens'
148-
autoload :TokensProxy, 'coderay/tokens_proxy'
149-
autoload :TokenKinds, 'coderay/token_kinds'
143+
autoload :Tokens, coderay_path('tokens')
144+
autoload :TokensProxy, coderay_path('tokens_proxy')
145+
autoload :TokenKinds, coderay_path('token_kinds')
150146

151147
# Plugin system
152-
autoload :PluginHost, 'coderay/helpers/plugin'
153-
autoload :Plugin, 'coderay/helpers/plugin'
148+
autoload :PluginHost, coderay_path('helpers', 'plugin')
149+
autoload :Plugin, coderay_path('helpers', 'plugin')
154150

155151
# Plugins
156-
autoload :Scanners, 'coderay/scanner'
157-
autoload :Encoders, 'coderay/encoder'
158-
autoload :Styles, 'coderay/style'
152+
autoload :Scanners, coderay_path('scanner')
153+
autoload :Encoders, coderay_path('encoder')
154+
autoload :Styles, coderay_path('style')
159155

160-
# Convenience access and reusable Encoder/Scanner pair
161-
autoload :Duo, 'coderay/duo'
156+
# convenience access and reusable Encoder/Scanner pair
157+
autoload :Duo, coderay_path('duo')
162158

163159
class << self
164160

lib/coderay/encoders/html.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class HTML < Encoder
109109
:hint => false,
110110
}
111111

112-
autoload :Output, CodeRay.abs_path('coderay/encoders/html/output')
113-
autoload :CSS, CodeRay.abs_path('coderay/encoders/html/css')
114-
autoload :Numbering, CodeRay.abs_path('coderay/encoders/html/numbering')
112+
autoload :Output, CodeRay.coderay_path('encoders', 'html', 'output')
113+
autoload :CSS, CodeRay.coderay_path('encoders', 'html', 'css')
114+
autoload :Numbering, CodeRay.coderay_path('encoders', 'html', 'numbering')
115115

116116
attr_reader :css
117117

lib/coderay/scanners/java.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Java < Scanner
66

77
register_for :java
88

9-
autoload :BuiltinTypes, CodeRay.abs_path('coderay/scanners/java/builtin_types')
9+
autoload :BuiltinTypes, CodeRay.coderay_path('scanners', 'java', 'builtin_types')
1010

1111
# http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
1212
KEYWORDS = %w[

lib/coderay/scanners/ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Ruby < Scanner
1313
register_for :ruby
1414
file_extension 'rb'
1515

16-
autoload :Patterns, CodeRay.abs_path('coderay/scanners/ruby/patterns')
17-
autoload :StringState, CodeRay.abs_path('coderay/scanners/ruby/string_state')
16+
autoload :Patterns, CodeRay.coderay_path('scanners', 'ruby', 'patterns')
17+
autoload :StringState, CodeRay.coderay_path('scanners', 'ruby', 'string_state')
1818

1919
def interpreted_string_state
2020
StringState.new :string, true, '"'

0 commit comments

Comments
 (0)