summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2011-12-27 02:39:02 +0100
committerKornelius Kalnbach <murphy@rubychan.de>2011-12-27 02:39:02 +0100
commit5c4c0065784c6420224516e13a0c50d86e792363 (patch)
treef150f672a18b306896b3db3234ec2d5bdbab42ee
parentb3807c5aa09901f50dca09b7927f37b1902ee32f (diff)
downloadcoderay-5c4c0065784c6420224516e13a0c50d86e792363.tar.gz
Bug #6: merge ConradIrwin's approach with korny's
-rw-r--r--lib/coderay.rb40
-rw-r--r--lib/coderay/encoders/html.rb6
-rw-r--r--lib/coderay/scanners/java.rb2
-rw-r--r--lib/coderay/scanners/ruby.rb4
4 files changed, 24 insertions, 28 deletions
diff --git a/lib/coderay.rb b/lib/coderay.rb
index 63ec555..e54a73b 100644
--- a/lib/coderay.rb
+++ b/lib/coderay.rb
@@ -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
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index c5d680c..c32dbd1 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -109,9 +109,9 @@ module Encoders
: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
diff --git a/lib/coderay/scanners/java.rb b/lib/coderay/scanners/java.rb
index 50c82c2..c1490ac 100644
--- a/lib/coderay/scanners/java.rb
+++ b/lib/coderay/scanners/java.rb
@@ -6,7 +6,7 @@ module Scanners
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[
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb
index e2e3d1b..2be98a6 100644
--- a/lib/coderay/scanners/ruby.rb
+++ b/lib/coderay/scanners/ruby.rb
@@ -13,8 +13,8 @@ module Scanners
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, '"'