summaryrefslogtreecommitdiff
path: root/lib/coderay/helpers
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2011-06-25 18:23:07 +0000
committermurphy <murphy@rubychan.de>2011-06-25 18:23:07 +0000
commit498df2b7654c210c8f47e2757efc33cd94689b57 (patch)
treebda6e10d3eadbf22f1a1a1a2d4e8d0cf7844a3b0 /lib/coderay/helpers
parentd6fe4e777a4f543c8828dbf77e955ab38e6c2803 (diff)
downloadcoderay-498df2b7654c210c8f47e2757efc33cd94689b57.tar.gz
coderay list subcommand and cleanups/fixes in Plugin helper (issue #45)
Diffstat (limited to 'lib/coderay/helpers')
-rw-r--r--lib/coderay/helpers/plugin.rb40
1 files changed, 25 insertions, 15 deletions
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb
index e2b6616..b0dda0c 100644
--- a/lib/coderay/helpers/plugin.rb
+++ b/lib/coderay/helpers/plugin.rb
@@ -152,11 +152,25 @@ module CodeRay
plugin_hash.values.grep(Class)
end
+ # Loads the map file (see map).
+ #
+ # This is done automatically when plugin_path is called.
+ def load_plugin_map
+ mapfile = path_to '_map'
+ @plugin_map_loaded = true
+ if File.exist? mapfile
+ require mapfile
+ true
+ else
+ false
+ end
+ end
+
protected
# Return a plugin hash that automatically loads plugins.
def make_plugin_hash
- map_loaded = false
+ @plugin_map_loaded ||= false
Hash.new do |h, plugin_id|
id = validate_id(plugin_id)
path = path_to id
@@ -164,15 +178,14 @@ module CodeRay
raise LoadError, "#{path} not found" unless File.exist? path
require path
rescue LoadError => boom
- if map_loaded
+ if @plugin_map_loaded
if h.has_key?(nil) # default plugin
h[nil]
else
raise PluginNotFound, 'Could not load plugin %p: %s' % [id, boom]
end
else
- load_map
- map_loaded = true
+ load_plugin_map
h[plugin_id]
end
else
@@ -186,14 +199,6 @@ module CodeRay
end
end
- # Loads the map file (see map).
- #
- # This is done automatically when plugin_path is called.
- def load_map
- mapfile = path_to '_map'
- require mapfile if File.exist? mapfile
- end
-
# Returns the expected path to the plugin file for the given id.
def path_to plugin_id
File.join plugin_path, "#{plugin_id}.rb"
@@ -230,6 +235,8 @@ module CodeRay
# See CodeRay::PluginHost for examples.
module Plugin
+ attr_reader :plugin_id
+
# Register this class for the given +id+.
#
# Example:
@@ -262,9 +269,12 @@ module CodeRay
self::PLUGIN_HOST
end
- # Returns the plugin id used by the engine.
- def plugin_id
- @plugin_id ||= name[/\w+$/].downcase
+ def aliases
+ plugin_host.load_plugin_map
+ plugin_host.plugin_hash.inject [] do |aliases, (key, value)|
+ aliases << key if plugin_host[key] == self
+ aliases
+ end
end
end