# ERB::Compiler (Class)

In: | erb.rb
Parent: | Object

## Methods

compile make_scanner new prepare_trim_mode

## Attributes

percent | [R] |
post_cmd | [RW] |
pre_cmd | [RW] |
put_cmd | [RW] |
trim_mode | [R] |

## Classes and Modules

Class ERB::Compiler::Buffer
Class ERB::Compiler::ExplicitScanner
Class ERB::Compiler::PercentLine
Class ERB::Compiler::PercentScanner
Class ERB::Compiler::Scanner
Class ERB::Compiler::SimpleScanner
Class ERB::Compiler::SimpleScanner2
Class ERB::Compiler::TrimScanner

## Public Class methods

new(trim_mode)

[Source]

    # File erb.rb, line 372
        def initialize(trim_mode)
          @percent, @trim_mode = prepare_trim_mode(trim_mode)
          @put_cmd = 'print'
          @pre_cmd = []
          @post_cmd = []
        end

## Public Instance methods

compile(s)

[Source]

    # File erb.rb, line 284
        def compile(s)
          out = Buffer.new(self)

          content = ''
          scanner = make_scanner(s)
          scanner.scan do |token|
            if scanner.stag.nil?
              case token
              when PercentLine
                out.push("#{@put_cmd} #{content.dump}") if content.size > 0
                content = ''
                out.push(token.to_s)
                out.cr
              when :cr
                out.cr
              when '<%', '<%=', '<%#'
                scanner.stag = token
                out.push("#{@put_cmd} #{content.dump}") if content.size > 0
                content = ''
              when "\n"
                content << "\n"
                out.push("#{@put_cmd} #{content.dump}")
                out.cr
                content = ''
              when '<%%'
                content << '<%'
              else
                content << token
              end
            else
              case token
              when '%>'
                case scanner.stag
                when '<%'
                  if content[-1] == ?\n
                    content.chop!
                    out.push(content)
                    out.cr
                  else
                    out.push(content)
                  end
                when '<%='
                  out.push("#{@put_cmd}((#{content}).to_s)")
                when '<%#'
                  # out.push("# #{content.dump}")

                end
                scanner.stag = nil
                content = ''
              when '%%>'
                content << '%>'
              else
                content << token
              end
            end
          end
          out.push("#{@put_cmd} #{content.dump}") if content.size > 0
          out.close
          out.script
        end

prepare_trim_mode(mode)

[Source]

    # File erb.rb, line 344
        def prepare_trim_mode(mode)
          case mode
          when 1
            return [false, '>']
          when 2
            return [false, '<>']
          when 0
            return [false, nil]
          when String
            perc = mode.include?('%')
            if mode.include?('-')
              return [perc, '-']
            elsif mode.include?('<>')
              return [perc, '<>']
            elsif mode.include?('>')
              return [perc, '>']
            else
              [perc, nil]
            end
          else
            return [false, nil]
          end
        end

make_scanner(src)

[Source]

    # File erb.rb, line 368
        def make_scanner(src)
          Scanner.make_scanner(src, @trim_mode, @percent)
        end

[Validate]