Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 39 lines (34 sloc) 1.116 kB
433dae2 @yabawock Whitespace Cleanup
yabawock authored
1 # encoding: utf-8
2
d52d829 @yabawock Mark formtastic outputs as html_safe
yabawock authored
3 # Adapted from the rails3 compatibility shim in Haml 2.2
4 module Formtastic
5 module Util
6 extend self
7 ## Rails XSS Safety
8
9 # Returns the given text, marked as being HTML-safe.
10 # With older versions of the Rails XSS-safety mechanism,
11 # this destructively modifies the HTML-safety of `text`.
12 #
13 # @param text [String]
14 # @return [String] `text`, marked as HTML-safe
15 def html_safe(text)
16 return text if text.nil?
17 return text.html_safe if defined?(ActiveSupport::SafeBuffer)
c8a48c2 @yabawock Only call html_safe! if it's supported
yabawock authored
18 return text.html_safe! if text.respond_to?(:html_safe!)
19 text
d52d829 @yabawock Mark formtastic outputs as html_safe
yabawock authored
20 end
21
22 def rails_safe_buffer_class
32e8aa1 @yabawock New method to find out if we are running under rails3 since SafeBuffe…
yabawock authored
23 # It's important that we check ActiveSupport first,
24 # because in Rails 2.3.6 ActionView::SafeBuffer exists
25 # but is a deprecated proxy object.
26 return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
27 return ActionView::SafeBuffer
d52d829 @yabawock Mark formtastic outputs as html_safe
yabawock authored
28 end
29
32e8aa1 @yabawock New method to find out if we are running under rails3 since SafeBuffe…
yabawock authored
30 def rails3?
58bbf0a @yabawock Revert "Refactoring on Formtastic::Util.rails3?"
yabawock authored
31 version=
32 if defined?(ActionPack::VERSION::MAJOR)
33 ActionPack::VERSION::MAJOR
34 end
35 !version.blank? && version >= 3
32e8aa1 @yabawock New method to find out if we are running under rails3 since SafeBuffe…
yabawock authored
36 end
d52d829 @yabawock Mark formtastic outputs as html_safe
yabawock authored
37 end
38 end
Something went wrong with that request. Please try again.