diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/coderay/encoder.rb | 11 | ||||
-rw-r--r-- | lib/coderay/encoders/_map.rb | 3 | ||||
-rw-r--r-- | lib/coderay/encoders/page.rb | 12 | ||||
-rw-r--r-- | lib/coderay/for_redcloth.rb | 2 | ||||
-rw-r--r-- | lib/coderay/helpers/plugin.rb | 40 | ||||
-rw-r--r-- | lib/coderay/scanner.rb | 6 |
6 files changed, 45 insertions, 29 deletions
diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index e495ca0..85a2456 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -34,12 +34,17 @@ module CodeRay # downcase class name instead. def const_missing sym if sym == :FILE_EXTENSION - plugin_id.to_s + (@plugin_id || name[/\w+$/].downcase).to_s else super end end + # The default file extension for output file of this encoder class. + def file_extension + self::FILE_EXTENSION + end + end # Subclasses are to store their default options in this constant. @@ -85,9 +90,9 @@ module CodeRay # more clear to you. alias highlight encode - # Return the default file extension for outputs of this encoder. + # The default file extension for this encoder. def file_extension - self.class::FILE_EXTENSION + self.class.file_extension end def << token diff --git a/lib/coderay/encoders/_map.rb b/lib/coderay/encoders/_map.rb index b4b766a..c9a20cc 100644 --- a/lib/coderay/encoders/_map.rb +++ b/lib/coderay/encoders/_map.rb @@ -8,8 +8,7 @@ module Encoders :plain => :text, :plaintext => :text, :remove_comments => :comment_filter, - :stats => :statistic, - :tex => :latex + :stats => :statistic # No default because Tokens#nonsense would not raise NoMethodError. diff --git a/lib/coderay/encoders/page.rb b/lib/coderay/encoders/page.rb index 9f3538e..8db45cd 100644 --- a/lib/coderay/encoders/page.rb +++ b/lib/coderay/encoders/page.rb @@ -1,6 +1,6 @@ module CodeRay module Encoders - + load :html # Wraps the output into a HTML page, using CSS classes and @@ -8,17 +8,17 @@ module Encoders # # See Encoders::HTML for available options. class Page < HTML - + FILE_EXTENSION = 'html' - + register_for :page - + DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \ :css => :class, :wrap => :page, :line_numbers => :table - + end - + end end diff --git a/lib/coderay/for_redcloth.rb b/lib/coderay/for_redcloth.rb index 1946f8e..f9df32b 100644 --- a/lib/coderay/for_redcloth.rb +++ b/lib/coderay/for_redcloth.rb @@ -45,7 +45,7 @@ module CodeRay if !opts[:lang] && RedCloth::VERSION.to_s >= '4.2.0' # simulating pre-4.2 behavior if opts[:text].sub!(/\A\[(\w+)\]/, '') - if CodeRay::Scanners[$1].plugin_id == :text + if CodeRay::Scanners[$1].lang == :text opts[:text] = $& + opts[:text] else opts[:lang] = $1 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 diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index ec2b3aa..0e0723c 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -81,7 +81,7 @@ module CodeRay end # The typical filename suffix for this scanner's language. - def file_extension extension = plugin_id + def file_extension extension = lang @file_extension ||= extension.to_s end @@ -91,7 +91,9 @@ module CodeRay end # The lang of this Scanner class, which is equal to its Plugin ID. - alias lang plugin_id + def lang + @plugin_id + end protected |