diff options
-rw-r--r-- | demo/demo_encoder.out | 4 | ||||
-rw-r--r-- | lib/coderay/encoders/div.rb | 3 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 4 | ||||
-rw-r--r-- | lib/coderay/encoders/span.rb | 3 | ||||
-rw-r--r-- | lib/coderay/encoders/statistic.rb | 2 | ||||
-rw-r--r-- | lib/coderay/helpers/plugin.rb | 72 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 2 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby/patterns.rb (renamed from lib/coderay/scanners/ruby/helper.rb) | 0 | ||||
-rw-r--r-- | rake_helpers/coderay_rdoc_template.rb | 1 |
9 files changed, 26 insertions, 65 deletions
diff --git a/demo/demo_encoder.out b/demo/demo_encoder.out index bef3e86..3add7bc 100644 --- a/demo/demo_encoder.out +++ b/demo/demo_encoder.out @@ -14,8 +14,8 @@ Token Types (4): TOTAL 8 100.00 % 1.5
space 4 50.00 % 1.0
integer 2 25.00 % 1.5
- operator 1 12.50 % 1.0
ident 1 12.50 % 4.0
+ operator 1 12.50 % 1.0
Original text:
@@ -75,6 +75,6 @@ Token Types (4): TOTAL 800 100.00 % 1.5
space 400 50.00 % 1.0
integer 200 25.00 % 1.5
- operator 100 12.50 % 1.0
ident 100 12.50 % 4.0
+ operator 100 12.50 % 1.0
diff --git a/lib/coderay/encoders/div.rb b/lib/coderay/encoders/div.rb index d3e595d..2379a4c 100644 --- a/lib/coderay/encoders/div.rb +++ b/lib/coderay/encoders/div.rb @@ -1,6 +1,7 @@ module CodeRay module Encoders
- require 'coderay/encoders/html'
+ load :html
+
class Div < HTML
FILE_EXTENSION = 'div.html'
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index e456356..a755b47 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -82,9 +82,7 @@ module Encoders :hint => false,
}
- require 'coderay/encoders/html/classes'
- require 'coderay/encoders/html/output'
- require 'coderay/encoders/html/css'
+ helper :classes, :output, :css
attr_reader :css
diff --git a/lib/coderay/encoders/span.rb b/lib/coderay/encoders/span.rb index abd8a39..e222889 100644 --- a/lib/coderay/encoders/span.rb +++ b/lib/coderay/encoders/span.rb @@ -1,6 +1,7 @@ module CodeRay module Encoders
- require 'coderay/encoders/html'
+ load :html
+
class Span < HTML
FILE_EXTENSION = 'span.html'
diff --git a/lib/coderay/encoders/statistic.rb b/lib/coderay/encoders/statistic.rb index cd26272..b8905ff 100644 --- a/lib/coderay/encoders/statistic.rb +++ b/lib/coderay/encoders/statistic.rb @@ -64,7 +64,7 @@ Token Types (%d): @type_stats.each do |type, stat|
stat.size /= stat.count.to_f
end
- types_stats = @type_stats.sort_by { |k, v| -v.count }.map do |k, v|
+ types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
end.join
STATS % [
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb index f88fe7f..233dfd6 100644 --- a/lib/coderay/helpers/plugin.rb +++ b/lib/coderay/helpers/plugin.rb @@ -54,6 +54,12 @@ module PluginHost # Alias for +[]+.
alias load []
+ def require_helper plugin_id, helper_name
+ path = path_to File.join(plugin_id, helper_name)
+ #$stderr.puts 'Loading helper: ' + path
+ require path
+ end
+
class << self
# Adds the module/class to the PLUGIN_HOSTS list.
@@ -85,7 +91,7 @@ module PluginHost # The path where the plugins can be found.
def plugin_path *args
unless args.empty?
- @plugin_path = File.join(*args)
+ @plugin_path = File.expand_path File.join(*args)
load_map
end
@plugin_path
@@ -264,6 +270,16 @@ module Plugin self::PLUGIN_HOST
end
+ def helper *helpers
+ for helper in helpers
+ self::PLUGIN_HOST.require_helper plugin_id, helper.to_s
+ end
+ end
+
+ def plugin_id
+ name[/[\w_]+$/].downcase
+ end
+
end
@@ -280,57 +296,3 @@ def require_plugin path "No host for #{host_id.inspect} found." unless host
host.load plugin_id
end
-
-__END__
-# this is no good test.
-if $0 == __FILE__
- $VERBOSE = $DEBUG = true
- eval DATA.read, nil, $0, __LINE__+4
-end
-
-__END__
-
-require 'test/unit'
-
-class TC_PLUGINS < Test::Unit::TestCase
-
- class Generators
- extend PluginHost
- plugin_path File.dirname(__FILE__)
- map :foo => :bar,
- :bar => :fancy
- end
-
- class Generator
- extend Plugin
- plugin_host Generators
- end
-
- class FancyGenerator < Generator
- register_for :fancy
- end
-
- def test_plugin
- assert_nothing_raised do
- Generators[:fancy]
- end
- assert_equal FancyGenerator, Generators[:fancy]
- end
-
- def test_require
- assert_nothing_raised do
- require_plugin('TC_PLUGINS::Generators/fancy')
- end
- assert_equal FancyGenerator,
- require_plugin('TC_PLUGINS::Generators/fancy')
- end
-
- def test_map
- assert_nothing_raised do
- require_plugin('TC_PLUGINS::Generators/foo')
- end
- assert_equal FancyGenerator,
- require_plugin('TC_PLUGINS::Generators/foo')
- end
-
-end
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index a4d042f..6b4c8ea 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -18,7 +18,7 @@ module CodeRay module Scanners register_for :ruby
- require 'coderay/scanners/ruby/helper'
+ helper :patterns
DEFAULT_OPTIONS = {
:parse_regexps => true,
diff --git a/lib/coderay/scanners/ruby/helper.rb b/lib/coderay/scanners/ruby/patterns.rb index ad649da..ad649da 100644 --- a/lib/coderay/scanners/ruby/helper.rb +++ b/lib/coderay/scanners/ruby/patterns.rb diff --git a/rake_helpers/coderay_rdoc_template.rb b/rake_helpers/coderay_rdoc_template.rb index c16a494..479df81 100644 --- a/rake_helpers/coderay_rdoc_template.rb +++ b/rake_helpers/coderay_rdoc_template.rb @@ -28,7 +28,6 @@ Hy.ca <<CA >> CA -$: << 'lib' require 'coderay' STYLE = Hy.ca <<CSS + CodeRay::Encoders[:html]::CSS.new.stylesheet |