Module: Formtastic::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/formtastic/util.rb

Instance Method Summary collapse

Instance Method Details

#html_safe(text) ⇒ String

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`.

Parameters:

  • text (String)

Returns:

  • (String)

    ‘text`, marked as HTML-safe



15
16
17
18
19
20
# File 'lib/formtastic/util.rb', line 15

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

#rails3?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/formtastic/util.rb', line 30

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

#rails_safe_buffer_classObject



22
23
24
25
26
27
28
# File 'lib/formtastic/util.rb', line 22

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