summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--demo/demo_load_encoder.out3
-rw-r--r--demo/demo_load_encoder.rb4
-rw-r--r--demo/demo_load_scanner.out3
-rw-r--r--demo/demo_load_scanner.rb4
-rw-r--r--lib/coderay/encoders/_map.rb8
-rw-r--r--lib/coderay/helpers/plugin.rb38
-rw-r--r--lib/coderay/scanners/_map.rb10
8 files changed, 68 insertions, 5 deletions
diff --git a/TODO b/TODO
index b1b2fba..296d17f 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,7 @@ Category = X (done), / (partly done), T (test), (else)
Project:
Documentation:
3/4 0 2 Do Doc the interface
+ 0 2 Cleanup/Read Doc
3/4 0 1 Sa2 write examples
1 2 Mi Code Cleanup: Indentation, Docu
@@ -22,7 +23,7 @@ Plugins:
Scanners:
- 1 2 More Languages! (See Roadmap)
+L 1 2 More Languages! (See Roadmap)
Ruby:
L 3 2 Regexp comment highlighting
diff --git a/demo/demo_load_encoder.out b/demo/demo_load_encoder.out
index 74b5f22..9ab11c2 100644
--- a/demo/demo_load_encoder.out
+++ b/demo/demo_load_encoder.out
@@ -3,5 +3,6 @@ Now it is loaded: CodeRay::Encoders::YAML
See?
Require is also possible: CodeRay::Encoders::Tokens
See?
+Now load some mapped encoders: stats and plain.
Require all Encoders:
-[[:count, CodeRay::Encoders::Count], [:debug, CodeRay::Encoders::Debug], [:div, CodeRay::Encoders::Div], [:html, CodeRay::Encoders::HTML], [:null, CodeRay::Encoders::Null], [:span, CodeRay::Encoders::Span], [:statistic, CodeRay::Encoders::Statistic], [:stats, CodeRay::Encoders::Statistic], [:text, CodeRay::Encoders::Text], [:tokens, CodeRay::Encoders::Tokens], [:xml, CodeRay::Encoders::XML], [:yaml, CodeRay::Encoders::YAML]]
+[[:count, CodeRay::Encoders::Count], [:debug, CodeRay::Encoders::Debug], [:div, CodeRay::Encoders::Div], [:html, CodeRay::Encoders::HTML], [:null, CodeRay::Encoders::Null], [:plain, :text], [:span, CodeRay::Encoders::Span], [:statistic, CodeRay::Encoders::Statistic], [:stats, CodeRay::Encoders::Statistic], [:text, CodeRay::Encoders::Text], [:tokens, CodeRay::Encoders::Tokens], [:xml, CodeRay::Encoders::XML], [:yaml, CodeRay::Encoders::YAML]]
diff --git a/demo/demo_load_encoder.rb b/demo/demo_load_encoder.rb
index 2df59d3..39d310d 100644
--- a/demo/demo_load_encoder.rb
+++ b/demo/demo_load_encoder.rb
@@ -16,6 +16,10 @@ print 'Require is also possible: '
p tokens_encoder
puts 'See?'
+puts 'Now load some mapped encoders: stats and plain.'
+require_plugin 'CodeRay::Encoders/stats'
+require_plugin 'CodeRay::Encoders/plain'
+
puts 'Require all Encoders:'
CodeRay::Encoders.load_all
p CodeRay::Encoders.plugin_hash.sort_by { |k,v| k.to_s }
diff --git a/demo/demo_load_scanner.out b/demo/demo_load_scanner.out
index 95dd36b..67ecac3 100644
--- a/demo/demo_load_scanner.out
+++ b/demo/demo_load_scanner.out
@@ -3,5 +3,6 @@ Now it is loaded: CodeRay::Scanners::Ruby
See?
Require is also possible: CodeRay::Scanners::C
See?
+Now load some mapped scanners: cpp and plain.
Require all Scanners:
-[[:c, CodeRay::Scanners::C], [:delphi, CodeRay::Scanners::Delphi], [:plain, CodeRay::Scanners::Plaintext], [:plaintext, CodeRay::Scanners::Plaintext], [:ruby, CodeRay::Scanners::Ruby]]
+[[:c, CodeRay::Scanners::C], [:cpp, :c], [:delphi, CodeRay::Scanners::Delphi], [:irb, :ruby], [:pascal, :delphi], [:plain, CodeRay::Scanners::Plaintext], [:plaintext, CodeRay::Scanners::Plaintext], [:ruby, CodeRay::Scanners::Ruby]]
diff --git a/demo/demo_load_scanner.rb b/demo/demo_load_scanner.rb
index 66a3929..5e503f0 100644
--- a/demo/demo_load_scanner.rb
+++ b/demo/demo_load_scanner.rb
@@ -16,6 +16,10 @@ print 'Require is also possible: '
p c_scanner
puts 'See?'
+puts 'Now load some mapped scanners: cpp and plain.'
+require_plugin 'CodeRay::Scanners/cpp'
+require_plugin 'CodeRay::Scanners/plain'
+
puts 'Require all Scanners:'
CodeRay::Scanners.load_all
p CodeRay::Scanners.plugin_hash.sort_by { |k,v| k.to_s }
diff --git a/lib/coderay/encoders/_map.rb b/lib/coderay/encoders/_map.rb
new file mode 100644
index 0000000..b9fe5af
--- /dev/null
+++ b/lib/coderay/encoders/_map.rb
@@ -0,0 +1,8 @@
+module CodeRay
+ module Encoders
+
+ map :stats => :statistic,
+ :plain => :text
+
+ end
+end
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb
index 63c3739..6fcfe35 100644
--- a/lib/coderay/helpers/plugin.rb
+++ b/lib/coderay/helpers/plugin.rb
@@ -69,6 +69,7 @@ module PluginHost
def plugin_path *args
unless args.empty?
@plugin_path = File.join(*args)
+ load_map
end
@plugin_path
end
@@ -110,6 +111,7 @@ module PluginHost
@plugin_hash ||= create_plugin_hash
end
+ # Makes a map of all loaded scanners.
def inspect
map = plugin_hash.dup
map.each do |id, plugin|
@@ -118,6 +120,32 @@ module PluginHost
map.inspect
end
+ # Map a plugin_id to another.
+ #
+ # Usage: Put this in a file plugin_path/_map.rb.
+ #
+ # class MyColorHost < PluginHost
+ # map :navy => :dark_blue,
+ # :maroon => :brown,
+ # :luna => :moon
+ # end
+
+ def map hash
+ for from, to in hash
+ from = validate_id from
+ to = validate_id to
+ plugin_hash[from] = to unless plugin_hash.has_key? from
+ end
+ end
+
+ def load_map
+ begin
+ require path_to('_map')
+ rescue LoadError
+ warn 'no _map.rb found for %s' % name if $DEBUG
+ end
+ end
+
# Every plugin must register itself for one or more
# +ids+ by calling register_for, which calls this method.
@@ -138,7 +166,9 @@ module PluginHost
#
# The extension .rb is not included.
def all_plugin_names
- Dir[path_to('*')].map do |file|
+ Dir[path_to('*')].select do |file|
+ File.basename(file)[/^(?!_)\w+\.rb$/]
+ end.map do |file|
File.basename file, '.rb'
end
end
@@ -156,7 +186,11 @@ module PluginHost
# Example:
# yaml_plugin = MyPluginHost[:yaml]
def [] id, *args, &blk
- plugin_hash.[] validate_id(id), *args, &blk
+ plugin = validate_id(id)
+ begin
+ plugin = plugin_hash.[] plugin, *args, &blk
+ end while plugin.is_a? Symbol
+ plugin
end
# Alias for +[]+.
diff --git a/lib/coderay/scanners/_map.rb b/lib/coderay/scanners/_map.rb
new file mode 100644
index 0000000..811546b
--- /dev/null
+++ b/lib/coderay/scanners/_map.rb
@@ -0,0 +1,10 @@
+module CodeRay
+ module Scanners
+
+ map :cpp => :c,
+ :plain => :plaintext,
+ :pascal => :delphi,
+ :irb => :ruby
+
+ end
+end