Sha256: 4e065624730a383fc42d27643d2fed0df479a67d72c44b2976dc86e9511f41ac

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Haml
  # Like Temple::Filters::Escapable, but with support for escaping by
  # Haml::Herlpers.html_escape and Haml::Herlpers.escape_once.
  class Escapable < Temple::Filter
    def initialize(*)
      super
      @escape_code = "::Haml::Helpers.html_escape((%s))"
      @escaper = eval("proc {|v| #{@escape_code % 'v'} }")
      @once_escape_code = "::Haml::Helpers.escape_once((%s))"
      @once_escaper = eval("proc {|v| #{@once_escape_code % 'v'} }")
      @escape = false
    end

    def on_escape(flag, exp)
      old = @escape
      @escape = flag
      compile(exp)
    ensure
      @escape = old
    end

    # The same as Haml::AttributeBuilder.build_attributes
    def on_static(value)
      [:static,
       if @escape == :once
         @once_escaper[value]
       elsif @escape
         @escaper[value]
       else
         value
       end
      ]
    end

    # The same as Haml::AttributeBuilder.build_attributes
    def on_dynamic(value)
      [:dynamic,
       if @escape == :once
         @once_escape_code % value
       elsif @escape
         @escape_code % value
       else
         "(#{value}).to_s"
       end
      ]
    end
  end
end

Version data entries

18 entries across 15 versions & 3 rubygems

Version Path
brakeman-4.10.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.9.1 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.9.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.8.2 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.8.1 bundle/ruby/2.4.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.8.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.2/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.7.2 bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.7.1 bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
brakeman-4.7.0 bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/escapable.rb
haml-5.1.2 lib/haml/escapable.rb
haml-5.1.1 lib/haml/escapable.rb
haml-5.1.0 lib/haml/escapable.rb