Sha256: c226259bb57a3a4c53d868e5ebd374efb5830f447d27aaf3a7dd1b6d0e6d4f9a

Contents?: true

Size: 903 Bytes

Versions: 47

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

module Haml
  # A module to count lines of expected code. This would be faster than actual code generation
  # and counting newlines in it.
  module TempleLineCounter
    class UnexpectedExpression < StandardError; end

    def self.count_lines(exp)
      type, *args = exp
      case type
      when :multi
        args.map { |a| count_lines(a) }.reduce(:+) || 0
      when :dynamic, :code
        args.first.count("\n")
      when :static
        0 # It has not real newline "\n" but escaped "\\n".
      when :case
        arg, *cases = args
        arg.count("\n") + cases.map do |cond, e|
          (cond == :else ? 0 : cond.count("\n")) + count_lines(e)
        end.reduce(:+)
      when :escape
        count_lines(args[1])
      else
        raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression '#{type}' is given!")
      end
    end
  end
end

Version data entries

47 entries across 44 versions & 3 rubygems

Version Path
brakeman-6.2.2 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.1.2 bundle/ruby/3.3.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/temple_line_counter.rb
haml-5.2.2 lib/haml/temple_line_counter.rb
brakeman-5.1.1 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/temple_line_counter.rb