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-4.7.2 bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
brakeman-4.7.1 bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
brakeman-4.7.0 bundle/ruby/2.6.0/gems/temple-0.8.2/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
temple-0.8.2 lib/temple/erb/parser.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/erb/parser.rb