Sha256: 9a96b68b6a9bbfdb5da12147cc7c33a29f0928e25e070ac2e4865e93aa37725e

Contents?: true

Size: 1.18 KB

Versions: 106

Compression:

Stored size: 1.18 KB

Contents

module Temple
  module Filters
    # Escape dynamic or static expressions.
    # This filter must be used after Temple::HTML::* and before the generators.
    # It can be enclosed with Temple::Filters::DynamicInliner filters to
    # reduce calls to Temple::Utils#escape_html.
    #
    # @api public
    class Escapable < Filter
      # Activate the usage of html_safe? if it is available (for Rails 3 for example)
      define_options :escape_code,
                     :disable_escape,
                     use_html_safe: ''.respond_to?(:html_safe?)

      def initialize(opts = {})
        super
        @escape_code = options[:escape_code] ||
          "::Temple::Utils.escape_html#{options[:use_html_safe] ? '_safe' : ''}((%s))"
        @escaper = eval("proc {|v| #{@escape_code % 'v'} }")
        @escape = false
      end

      def on_escape(flag, exp)
        old = @escape
        @escape = flag && !options[:disable_escape]
        compile(exp)
      ensure
        @escape = old
      end

      def on_static(value)
        [:static, @escape ? @escaper[value] : value]
      end

      def on_dynamic(value)
        [:dynamic, @escape ? @escape_code % value : value]
      end
    end
  end
end

Version data entries

106 entries across 92 versions & 7 rubygems

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