Sha256: a1ab7c6308ed25c5f722fe29245e8a5615f5f9798a199d118290b612b721a76a

Contents?: true

Size: 970 Bytes

Versions: 7

Compression:

Stored size: 970 Bytes

Contents

module Temple
  module CoffeeScript
    module Filters
      class Escapable < Filter
        # Activate the usage of html_safe? if it is available (for Rails 3 for example)
        set_default_options :use_html_safe => ''.respond_to?(:html_safe?),
                            :disable_escape => false

        def initialize(opts = {})
          super
          @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(#{value})" : value]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
skim-0.8.6 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.5 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.4 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.3 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.2 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.1 lib/temple/coffee_script/filters/escapable.rb
skim-0.8.0 lib/temple/coffee_script/filters/escapable.rb