summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-06-01 18:07:33 +0000
committermurphy <murphy@rubychan.de>2010-06-01 18:07:33 +0000
commit5bf55e552d7dc3eac362e2b881afaa8039995a59 (patch)
tree3a5fd490a92f0782a6157294788f09339a3e07c6
parenteeba23ef0a8fea352d3af8c0b8e01a5c1920202c (diff)
downloadcoderay-5bf55e552d7dc3eac362e2b881afaa8039995a59.tar.gz
Fixed Text Encoder.
-rw-r--r--Changes.textile4
-rw-r--r--lib/coderay/encoders/text.rb27
2 files changed, 29 insertions, 2 deletions
diff --git a/Changes.textile b/Changes.textile
index ad1bd59..99ba2a9 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -76,6 +76,10 @@ h3. @Encoders::Terminal@
* *REMOVED* colors for obsolete token kinds.
* *FIXED* handling of line tokens.
+h3. @Encoders::Text@
+
+* *FIXED* default behavior of stripping the trailing newline.
+
h3. *RENAMED*: @Encoders::TokenKindFilter@
Renamed from @TokenClassFilter@.
diff --git a/lib/coderay/encoders/text.rb b/lib/coderay/encoders/text.rb
index 2dfb224..c146038 100644
--- a/lib/coderay/encoders/text.rb
+++ b/lib/coderay/encoders/text.rb
@@ -1,3 +1,4 @@
+($:.unshift '../..'; require 'coderay') unless defined? CodeRay
module CodeRay
module Encoders
@@ -19,11 +20,12 @@ module Encoders
FILE_EXTENSION = 'txt'
DEFAULT_OPTIONS = {
- :separator => ''
+ :separator => nil
}
def text_token text, kind
- @out << text + @sep
+ @out << text
+ @out << @sep if @sep
end
protected
@@ -40,3 +42,24 @@ module Encoders
end
end
+
+if $0 == __FILE__
+ $VERBOSE = true
+ $: << File.join(File.dirname(__FILE__), '..')
+ eval DATA.read, nil, $0, __LINE__ + 4
+end
+
+__END__
+require 'test/unit'
+
+class CountTest < Test::Unit::TestCase
+
+ def test_count
+ ruby = <<-RUBY
+puts "Hello world!"
+ RUBY
+ tokens = CodeRay.scan ruby, :ruby
+ assert_equal ruby, tokens.encode_with(:text)
+ end
+
+end \ No newline at end of file