summaryrefslogtreecommitdiff
path: root/lib/coderay/duo.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2006-03-21 14:46:34 +0000
committermurphy <murphy@rubychan.de>2006-03-21 14:46:34 +0000
commita3b4ad06b992bd418a1d34bfb271c09fd9bedf11 (patch)
tree722d341f4065b4614b2cfc55cee6ccd3c66fb69a /lib/coderay/duo.rb
parent13255135d7539fd542cf831d6a98f1ba8a5d43ae (diff)
downloadcoderay-a3b4ad06b992bd418a1d34bfb271c09fd9bedf11.tar.gz
CodeRay::Duo added for cool caching!
bench/caching.rb added t“for demonstrating this. HTML Encoder: creates unwrapped output by default (still problems with that.) Numerizing changed (doesn't try to prevent nesting errors) Speedup: "::String" is faster.
Diffstat (limited to 'lib/coderay/duo.rb')
-rw-r--r--lib/coderay/duo.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb
new file mode 100644
index 0000000..8187277
--- /dev/null
+++ b/lib/coderay/duo.rb
@@ -0,0 +1,23 @@
+module CodeRay
+
+ class Duo
+
+ attr_accessor :scanner, :encoder
+
+ def initialize lang, format, options = {}
+ @scanner = CodeRay.scanner lang, CodeRay.get_scanner_options(options)
+ @encoder = CodeRay.encoder format, options
+ end
+
+ class << self
+ alias [] new
+ end
+
+ def encode code
+ @scanner.string = code
+ @encoder.encode_tokens(scanner.tokenize)
+ end
+
+ end
+
+end