summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/text.rb
blob: 15c66f9c725687f0b94eae260e5f83f20b44c31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module CodeRay
module Encoders
  
  # Concats the tokens into a single string, resulting in the original
  # code string if no tokens were removed.
  # 
  # Alias: +plain+, +plaintext+
  # 
  # == Options
  # 
  # === :separator
  # A separator string to join the tokens.
  # 
  # Default: empty String
  class Text < Encoder
    
    register_for :text
    
    FILE_EXTENSION = 'txt'
    
    DEFAULT_OPTIONS = {
      :separator => nil
    }
    
    def text_token text, kind
      super
      
      if @first
        @first = false
      else
        @out << @sep
      end if @sep
    end
    
  protected
    def setup options
      super
      
      @first = true
      @sep = options[:separator]
    end
    
  end
  
end
end