Sha256: eaab36aeb7413996fb2999c47e2e7779765762d99bff823e16aac652860f5989

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module String #:nodoc:
      module OutputSafety
        def self.included(base)
          base.class_eval do
            alias_method :add_without_safety, :+
            alias_method :+, :add_with_safety
            alias_method_chain :concat, :safety
            undef_method :<<
            alias_method :<<, :concat_with_safety
          end
        end

        def html_safe?
          defined?(@_rails_html_safe) && @_rails_html_safe
        end

        def html_safe!
          @_rails_html_safe = true
          self
        end

        def add_with_safety(other)
          result = add_without_safety(other)
          if html_safe? && also_html_safe?(other)
            result.html_safe!
          else
            result
          end
        end

        def concat_with_safety(other_or_fixnum)
          result = concat_without_safety(other_or_fixnum)
          unless html_safe? && also_html_safe?(other_or_fixnum)
            @_rails_html_safe = false
          end
          result
        end

        private
          def also_html_safe?(other)
            other.respond_to?(:html_safe?) && other.html_safe?
          end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 5 rubygems

Version Path
activesupport_csi-2.3.5.p8 lib/active_support/core_ext/string/output_safety.rb
activesupport_csi-2.3.5.p7 lib/active_support/core_ext/string/output_safety.rb
activesupport_csi-2.3.5.p6 lib/active_support/core_ext/string/output_safety.rb
webroar-0.5.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb
webroar-0.4.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb
radiant-0.9.0.rc2 vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb
webroar-0.3.1 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb
webroar-0.3.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb
activesupport-2.3.5 lib/active_support/core_ext/string/output_safety.rb