Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 38 lines (34 sloc) 1.116 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# encoding: utf-8

# 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
Something went wrong with that request. Please try again.