From a3b4ad06b992bd418a1d34bfb271c09fd9bedf11 Mon Sep 17 00:00:00 2001 From: murphy Date: Tue, 21 Mar 2006 14:46:34 +0000 Subject: =?UTF-8?q?CodeRay::Duo=20added=20for=20cool=20caching!=20bench/ca?= =?UTF-8?q?ching.rb=20added=20t=C2=B4for=20demonstrating=20this.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTML Encoder: creates unwrapped output by default (still problems with that.) Numerizing changed (doesn't try to prevent nesting errors) Speedup: "::String" is faster. --- lib/coderay/duo.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/coderay/duo.rb (limited to 'lib/coderay/duo.rb') 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 -- cgit v1.2.1