Class CodeRay::Encoders::TokenKindFilter
In: lib/coderay/encoders/token_kind_filter.rb
Parent: Filter

A Filter that selects tokens based on their token kind.

Options

:exclude

One or many symbols (in an Array) which shall be excluded.

Default: []

:include

One or many symbols (in an array) which shall be included.

Default: :all, which means all tokens are included.

Exclusion wins over inclusion.

See also: CommentFilter

Methods

Constants

DEFAULT_OPTIONS = { :exclude => [], :include => :all

Public Instance methods

Add the token group to the output stream if kind matches the conditions.

If it does not, all tokens inside the group are excluded from the stream, even if their kinds match.

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 66
66:     def begin_group kind
67:       if @group_excluded
68:         @group_excluded += 1
69:       elsif include_group? kind
70:         super
71:       else
72:         @group_excluded = 1
73:       end
74:     end

See begin_group.

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 77
77:     def begin_line kind
78:       if @group_excluded
79:         @group_excluded += 1
80:       elsif include_group? kind
81:         super
82:       else
83:         @group_excluded = 1
84:       end
85:     end

Take care of re-enabling the delegation of tokens to the output stream if an exluded group has ended.

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 89
89:     def end_group kind
90:       if @group_excluded
91:         @group_excluded -= 1
92:         @group_excluded = false if @group_excluded.zero?
93:       else
94:         super
95:       end
96:     end

See end_group.

[Source]

     # File lib/coderay/encoders/token_kind_filter.rb, line 99
 99:     def end_line kind
100:       if @group_excluded
101:         @group_excluded -= 1
102:         @group_excluded = false if @group_excluded.zero?
103:       else
104:         super
105:       end
106:     end

Add the token to the output stream if kind matches the conditions.

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 57
57:     def text_token text, kind
58:       super if !@group_excluded && include_text_token?(text, kind)
59:     end

Protected Instance methods

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 49
49:     def include_group? kind
50:        (@include == :all || @include.include?(kind)) &&
51:       !(@exclude == :all || @exclude.include?(kind))
52:     end

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 45
45:     def include_text_token? text, kind
46:       include_group? kind
47:     end

[Source]

    # File lib/coderay/encoders/token_kind_filter.rb, line 35
35:     def setup options
36:       super
37:       
38:       @group_excluded = false
39:       @exclude = options[:exclude]
40:       @exclude = Array(@exclude) unless @exclude == :all
41:       @include = options[:include]
42:       @include = Array(@include) unless @include == :all
43:     end

[Validate]