diff options
| author | no author <noone@nowhere> | 2005-09-26 23:59:46 +0000 | 
|---|---|---|
| committer | no author <noone@nowhere> | 2005-09-26 23:59:46 +0000 | 
| commit | 346c0ee2e0ce91942691d60c873237cc146a4b70 (patch) | |
| tree | 6191ea28ee86aecc459a682f1ef87cc0fa88b8d5 /lib/coderay | |
| parent | a7dde9232704ea11bc9acd0bfd29c15ba4a7e943 (diff) | |
| download | coderay-346c0ee2e0ce91942691d60c873237cc146a4b70.tar.gz | |
Added $Id$ keyword.
Diffstat (limited to 'lib/coderay')
| -rw-r--r-- | lib/coderay/encoder.rb | 40 | ||||
| -rw-r--r-- | lib/coderay/scanner.rb | 8 | 
2 files changed, 28 insertions, 20 deletions
diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index 5f6d511..b6a22f0 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -1,6 +1,6 @@  module CodeRay
 -  # This module holds class Encoder and its subclasses.
 +  # This module holds the Encoder class and its subclasses.
    # For example, the HTML encoder is named CodeRay::Encoders::HTML
    # can be found in coderay/encoders/html.
    # 
 @@ -10,27 +10,31 @@ module CodeRay    module Encoders
      # Raised if Encoders[] fails because:
 -    # * an file could not be found
 +    # * a file could not be found
      # * the requested Encoder is not registered
      EncoderNotFound = Class.new Exception
 -    # Loaded Encoders are saved here.
 -    ENCODERS = Hash.new do |h, lang|
 -      path = Encoders.path_to lang
 -      lang = lang.to_sym
 -      begin
 -        require path
 -      rescue LoadError
 -        raise EncoderNotFound, "#{path} not found."
 -      else
 -        # Encoder should have registered by now
 -        unless h[lang]
 -          raise EncoderNotFound, "No Encoder for #{lang} found in #{path}."
 +    def Encoders.create_encoders_hash
 +      Hash.new do |h, lang|
 +        path = Encoders.path_to lang
 +        lang = lang.to_sym
 +        begin
 +          require path
 +        rescue LoadError
 +          raise EncoderNotFound, "#{path} not found."
 +        else
 +          # Encoder should have registered by now
 +          unless h[lang]
 +            raise EncoderNotFound, "No Encoder for #{lang} found in #{path}."
 +          end
          end
 +        h[lang]
        end
 -      h[lang]
      end
 +    # Loaded Encoders are saved here.
 +    ENCODERS = create_encoders_hash
 +
      class << self
        # Every Encoder class must register itself for one or more +formats+
 @@ -63,8 +67,10 @@ module CodeRay      end
 -    # The Encoder base class. Together with CodeRay::Scanner and
 -    # CodeRay::Tokens, it forms the highlighting triad.
 +    # = Encoder
 +    #
 +    # The Encoder base class. Together with Scanner and
 +    # Tokens, it forms the highlighting triad.
      #
      # Encoder instances take a Tokens object and do something with it.
      #
 diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 1cca607..a74a736 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -131,12 +131,14 @@ Known scanners: #{SCANNERS}      require 'strscan'
 +    # = Scanner
 +    #
      # The base class for all Scanners.
      #
      # It is a subclass of Ruby's great +StringScanner+, which
      # makes it easy to access the scanning methods inside.
      #
 -    # It is also +Enumerable+, so you can do this:
 +    # It is also +Enumerable+, so you can use it like an Array of Tokens:
      #
      #   require 'coderay'
      #   
 @@ -148,8 +150,8 @@ Known scanners: #{SCANNERS}      #   
      #   # prints: (*==)++;
      # 
 -    # OK, this is not a very good example :)
 -    # You can also use map, any?, find and even sort_by.
 +    # OK, this is a very simple example :)
 +    # You can also use +map+, +any?+, +find+ and even +sort_by+, if you want.
      class Scanner < StringScanner
        # Raised if a Scanner fails while scanning
  | 
