summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/coderay/tokens.rb13
-rw-r--r--lib/coderay/tokens_proxy.rb14
2 files changed, 14 insertions, 13 deletions
diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb
index b357199..ee28a4e 100644
--- a/lib/coderay/tokens.rb
+++ b/lib/coderay/tokens.rb
@@ -64,12 +64,7 @@ module CodeRay
#
# options are passed to the encoder.
def encode encoder, options = {}
- unless encoder.is_a? Encoders::Encoder
- if encoder.respond_to? :to_sym
- encoder_class = Encoders[encoder]
- end
- encoder = encoder_class.new options
- end
+ encoder = Encoders[encoder].new options if encoder.respond_to? :to_sym
encoder.encode_tokens self, options
end
@@ -83,15 +78,11 @@ module CodeRay
# For example, if you call +tokens.html+, the HTML encoder
# is used to highlight the tokens.
def method_missing meth, options = {}
- encode_with meth, options
+ encode meth, options
rescue PluginHost::PluginNotFound
super
end
- def encode_with encoder, options = {}
- Encoders[encoder].new(options).encode_tokens self
- end
-
# Returns the tokens compressed by joining consecutive
# tokens of the same kind.
#
diff --git a/lib/coderay/tokens_proxy.rb b/lib/coderay/tokens_proxy.rb
index 598ad2e..b333e57 100644
--- a/lib/coderay/tokens_proxy.rb
+++ b/lib/coderay/tokens_proxy.rb
@@ -1,13 +1,15 @@
module CodeRay
- class TokensProxy < Struct.new :code, :lang, :options, :block
+ class TokensProxy < Struct.new :input, :lang, :options, :block
def method_missing method, *args, &blk
+ encode method, *args
+ rescue PluginHost::PluginNotFound
tokens.send(method, *args, &blk)
end
def tokens
- @tokens ||= scanner.tokenize(code)
+ @tokens ||= scanner.tokenize(input)
end
def each *args, &blk
@@ -22,6 +24,14 @@ module CodeRay
@scanner ||= CodeRay.scanner(lang, options, &block)
end
+ def encode encoder, options = {}
+ if encoder.respond_to? :to_sym
+ CodeRay.encode(input, lang, encoder, options)
+ else
+ encoder.encode_tokens tokens, options
+ end
+ end
+
end
end