# ERB::Compiler::TrimScanner (Class)

In: | erb.rb
Parent: | Scanner

## Methods

explicit_trim_line is_erb_stag? new percent_line scan scan_line trim_line1 trim_line2

## Constants

TrimSplitRegexp | = | /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>\n)|(%>)|(\n)/
ExplicitTrimRegexp | = | /(^[ \t]*<%-)|(-%>\n?\z)|(<%-)|(-%>)|(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
ERB_STAG | = | %w(<%= <%# <%)

## Attributes

stag | [RW] |

## Public Class methods

new(src, trim_mode, percent)

[Source]

    # File erb.rb, line 53
          def initialize(src, trim_mode, percent)
            super
            @trim_mode = trim_mode
            @percent = percent
            if @trim_mode == '>'
              @scan_line = self.method(:trim_line1)
            elsif @trim_mode == '<>'
              @scan_line = self.method(:trim_line2)
            elsif @trim_mode == '-'
              @scan_line = self.method(:explicit_trim_line)
            else
              @scan_line = self.method(:scan_line)
            end
          end

## Public Instance methods

scan(&block)

[Source]

    # File erb.rb, line 69
          def scan(&block)
            @stag = nil
            if @percent
              @src.each do |line|
                percent_line(line, &block)
              end
            else
              @src.each do |line|
                @scan_line.call(line, &block)
              end
            end
            nil
          end

percent_line(line, &block) {|PercentLine.new(line.chomp)| ...}

[Source]

    # File erb.rb, line 83
          def percent_line(line, &block)
            if @stag || line[0] != ?%
              return @scan_line.call(line, &block)
            end

            line[0] = ''
            if line[0] == ?%
              @scan_line.call(line, &block)
            else
              yield(PercentLine.new(line.chomp))
            end
          end

scan_line(line) {|token| ...}

[Source]

    # File erb.rb, line 96
          def scan_line(line)
            line.split(SplitRegexp).each do |token|
              next if token.empty?
              yield(token)
            end
          end

trim_line1(line) {|'%>'| ...}

[Source]

    # File erb.rb, line 103
          def trim_line1(line)
            line.split(TrimSplitRegexp).each do |token|
              next if token.empty?
              if token == "%>\n"
                yield('%>')
                yield(:cr)
                break
              end
              yield(token)
            end
          end

trim_line2(line) {|'%>'| ...}

[Source]

    # File erb.rb, line 115
          def trim_line2(line)
            head = nil
            line.split(TrimSplitRegexp).each do |token|
              next if token.empty?
              head = token unless head
              if token == "%>\n"
                yield('%>')
                if  is_erb_stag?(head)
                  yield(:cr)
                else
                  yield("\n")
                end
                break
              end
              yield(token)
            end
          end

explicit_trim_line(line) {|'<%'| ...}

[Source]

    # File erb.rb, line 134
          def explicit_trim_line(line)
            line.split(ExplicitTrimRegexp).each do |token|
              next if token.empty?
              if @stag.nil? && /[ \t]*<%-/ =~ token
                yield('<%')
              elsif @stag && /-%>\n/ =~ token
                yield('%>')
                yield(:cr)
              elsif @stag && token == '-%>'
                yield('%>')
              else
                yield(token)
              end
            end
          end

is_erb_stag?(s)

[Source]

    # File erb.rb, line 151
          def is_erb_stag?(s)
            ERB_STAG.member?(s)
          end

[Validate]