Sha256: 5ed7cca40f177458e19afcf976b24a6e8f5d3e421f2ab17e296e73118176bcad

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# Adapted from the rails3 compatibility shim in Haml 2.2
module Formtastic
  module Util
    extend self
    ## Rails XSS Safety

    # Returns the given text, marked as being HTML-safe.
    # With older versions of the Rails XSS-safety mechanism,
    # this destructively modifies the HTML-safety of `text`.
    #
    # @param text [String]
    # @return [String] `text`, marked as HTML-safe
    def html_safe(text)
      return text if text.nil?
      return text.html_safe if defined?(ActiveSupport::SafeBuffer)
      return text.html_safe! if text.respond_to?(:html_safe!)
      text
    end

    def rails_safe_buffer_class
      # It's important that we check ActiveSupport first,
      # because in Rails 2.3.6 ActionView::SafeBuffer exists
      # but is a deprecated proxy object.
      return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
      return ActionView::SafeBuffer
    end

    def rails3?
      version=
        if defined?(ActionPack::VERSION::MAJOR)
          ActionPack::VERSION::MAJOR
        end
      !version.blank? && version >= 3
    end
  end
end

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
formtastic-1.1.0 lib/formtastic/util.rb
formtastic-1.1.0.beta lib/formtastic/util.rb
sensis-formtastic-rails3-1.d4e5326 lib/formtastic/util.rb
techthumb-formtastic-1.rails3.sha lib/formtastic/util.rb
formtastic-rails3-1.0.0.beta3 lib/formtastic/util.rb