/
util.rb
57 lines (46 loc) · 1.15 KB
/
util.rb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# encoding: utf-8
# Adapted from the rails3 compatibility shim in Haml 2.2
module Formtastic
# @private
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)
if text.respond_to?(:html_safe)
text.html_safe
else
text
end
end
def rails3?
match?(rails_version, "~> 3.0")
end
def rails4?
match?(rails_version, "~> 4.0")
end
def rails4_0?
match?(rails_version, "~> 4.0.0")
end
def rails4_1?
match?(rails_version, "~> 4.1.0")
end
def deprecated_version_of_rails?
match?(rails_version, "< #{minimum_version_of_rails}")
end
def minimum_version_of_rails
"4.1.0"
end
def rails_version
::Rails::VERSION::STRING
end
def match?(version, dependency)
Gem::Dependency.new("formtastic", dependency).match?("formtastic", version)
end
end
end