summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/filter.rb
blob: a71e43ea846a29db2f0c7541a0f974d7febe4a25 (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
47
48
49
50
51
52
module CodeRay
module Encoders
  
  # A Filter encoder has another Tokens instance as output.
  # It can be subclass to select, remove, or modify tokens in the stream.
  # 
  # Subclasses of Filter are called "Filters" and can be chained.
  # 
  # == Options
  # 
  # === :tokens
  # 
  # The Tokens object which will receive the output.
  # 
  # Default: Tokens.new
  # 
  # See also: TokenKindFilter
  class Filter < Encoder
    
    register_for :filter
    
  protected
    def setup options
      @out = options[:tokens] || Tokens.new
    end
    
  public
    
    def text_token text, kind  # :nodoc:
      @out.text_token text, kind
    end
    
    def begin_group kind  # :nodoc:
      @out.begin_group kind
    end
    
    def begin_line kind  # :nodoc:
      @out.begin_line kind
    end
    
    def end_group kind  # :nodoc:
      @out.end_group kind
    end
    
    def end_line kind  # :nodoc:
      @out.end_line kind
    end
    
  end
  
end
end