Sha256: a996a1474404fb4f9910a6f7acbe7dfe8ac46117ad194a12845553d1dcee52ad

Contents?: true

Size: 1.08 KB

Versions: 115

Compression:

Stored size: 1.08 KB

Contents

module Temple
  module ERB
    # Example ERB parser
    #
    # @api public
    class Parser < Temple::Parser
      ERB_PATTERN = /(\n|<%%|%%>)|<%(==?|\#)?(.*?)?-?%>/m

      def call(input)
        result = [:multi]
        pos = 0
        input.scan(ERB_PATTERN) do |token, indicator, code|
          text = input[pos...$~.begin(0)]
          pos  = $~.end(0)
          if token
            case token
            when "\n"
              result << [:static, "#{text}\n"] << [:newline]
            when '<%%', '%%>'
              result << [:static, text] unless text.empty?
              token.slice!(1)
              result << [:static, token]
            end
          else
            result << [:static, text] unless text.empty?
            case indicator
            when '#'
              result << [:code, "\n" * code.count("\n")]
            when /=/
              result << [:escape, indicator.size <= 1, [:dynamic, code]]
            else
              result << [:code, code]
            end
          end
        end
        result << [:static, input[pos..-1]]
      end
    end
  end
end

Version data entries

115 entries across 101 versions & 7 rubygems

Version Path
brakeman-3.7.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
temple-0.8.0 lib/temple/erb/parser.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/erb/parser.rb
temple-0.7.7 lib/temple/erb/parser.rb
brakeman-3.3.0 bundle/ruby/2.3.0/gems/temple-0.7.6/lib/temple/erb/parser.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/erb/parser.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/erb/parser.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/erb/parser.rb
temple-0.7.6 lib/temple/erb/parser.rb
temple-0.7.5 lib/temple/erb/parser.rb