Permalink
Browse files

Bug #6: merge ConradIrwin's approach with korny's

  • Loading branch information...
1 parent b3807c5 commit 5c4c0065784c6420224516e13a0c50d86e792363 @korny korny committed Dec 27, 2011
Showing with 24 additions and 28 deletions.
  1. +18 −22 lib/coderay.rb
  2. +3 −3 lib/coderay/encoders/html.rb
  3. +1 −1 lib/coderay/scanners/java.rb
  4. +2 −2 lib/coderay/scanners/ruby.rb
View
@@ -127,38 +127,34 @@ module CodeRay
$CODERAY_DEBUG ||= false
- # Assuming the rel_path is a subpath of lib/
- def self.abs_path(rel_path)
- File.join(File.dirname(__FILE__), rel_path)
- end
-
- # In order to work in environments that alter $:, we need to
- # set the absolute path when autoloading files.
- def self.autoload(const_name, rel_path)
- super const_name, abs_path(rel_path)
+ require 'coderay/version'
+
+ CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay'
+
+ # Assuming the path is a subpath of lib/coderay/
+ def self.coderay_path *path
+ File.join CODERAY_PATH, *path
end
-
- require abs_path('coderay/version')
# helpers
- autoload :FileType, 'coderay/helpers/file_type'
+ autoload :FileType, coderay_path('helpers', 'file_type')
# Tokens
- autoload :Tokens, 'coderay/tokens'
- autoload :TokensProxy, 'coderay/tokens_proxy'
- autoload :TokenKinds, 'coderay/token_kinds'
+ autoload :Tokens, coderay_path('tokens')
+ autoload :TokensProxy, coderay_path('tokens_proxy')
+ autoload :TokenKinds, coderay_path('token_kinds')
# Plugin system
- autoload :PluginHost, 'coderay/helpers/plugin'
- autoload :Plugin, 'coderay/helpers/plugin'
+ autoload :PluginHost, coderay_path('helpers', 'plugin')
+ autoload :Plugin, coderay_path('helpers', 'plugin')
# Plugins
- autoload :Scanners, 'coderay/scanner'
- autoload :Encoders, 'coderay/encoder'
- autoload :Styles, 'coderay/style'
+ autoload :Scanners, coderay_path('scanner')
+ autoload :Encoders, coderay_path('encoder')
+ autoload :Styles, coderay_path('style')
- # Convenience access and reusable Encoder/Scanner pair
- autoload :Duo, 'coderay/duo'
+ # convenience access and reusable Encoder/Scanner pair
+ autoload :Duo, coderay_path('duo')
class << self
@@ -109,9 +109,9 @@ class HTML < Encoder
:hint => false,
}
- autoload :Output, CodeRay.abs_path('coderay/encoders/html/output')
- autoload :CSS, CodeRay.abs_path('coderay/encoders/html/css')
- autoload :Numbering, CodeRay.abs_path('coderay/encoders/html/numbering')
+ autoload :Output, CodeRay.coderay_path('encoders', 'html', 'output')
+ autoload :CSS, CodeRay.coderay_path('encoders', 'html', 'css')
+ autoload :Numbering, CodeRay.coderay_path('encoders', 'html', 'numbering')
attr_reader :css
@@ -6,7 +6,7 @@ class Java < Scanner
register_for :java
- autoload :BuiltinTypes, CodeRay.abs_path('coderay/scanners/java/builtin_types')
+ autoload :BuiltinTypes, CodeRay.coderay_path('scanners', 'java', 'builtin_types')
# http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
KEYWORDS = %w[
@@ -13,8 +13,8 @@ class Ruby < Scanner
register_for :ruby
file_extension 'rb'
- autoload :Patterns, CodeRay.abs_path('coderay/scanners/ruby/patterns')
- autoload :StringState, CodeRay.abs_path('coderay/scanners/ruby/string_state')
+ autoload :Patterns, CodeRay.coderay_path('scanners', 'ruby', 'patterns')
+ autoload :StringState, CodeRay.coderay_path('scanners', 'ruby', 'string_state')
def interpreted_string_state
StringState.new :string, true, '"'

0 comments on commit 5c4c006

Please sign in to comment.