Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 58 lines (46 sloc) 1.175 kb
433dae2 Morton Jonuschat Whitespace Cleanup
yabawock authored
1 # encoding: utf-8
2
d52d829 Morton Jonuschat Mark formtastic outputs as html_safe
yabawock authored
3 # Adapted from the rails3 compatibility shim in Haml 2.2
4 module Formtastic
2f81ae4 Justin French hid a bunch of internal modules from YARD with @private tags
authored
5 # @private
d52d829 Morton Jonuschat Mark formtastic outputs as html_safe
yabawock authored
6 module Util
7 extend self
8 ## Rails XSS Safety
9
10 # Returns the given text, marked as being HTML-safe.
11 # With older versions of the Rails XSS-safety mechanism,
12 # this destructively modifies the HTML-safety of `text`.
13 #
14 # @param text [String]
15 # @return [String] `text`, marked as HTML-safe
16 def html_safe(text)
457b098 Gabriel Sobrinho Refactoring on Formtastic::Util.html_safe
sobrinho authored
17 if text.respond_to?(:html_safe)
18 text.html_safe
19 else
20 text
21 end
d52d829 Morton Jonuschat Mark formtastic outputs as html_safe
yabawock authored
22 end
73bc907 Timo Schilling refector version compaireing
timoschilling authored
23
b0f368c Justin French add Util.rails3?
authored
24 def rails3?
73bc907 Timo Schilling refector version compaireing
timoschilling authored
25 match?(rails_version, "~> 3.0")
b0f368c Justin French add Util.rails3?
authored
26 end
40f9faf Justin French add Util.rails_4? and Util.rails_4_1? for detecting Rails version variat...
authored
27
28 def rails4?
73bc907 Timo Schilling refector version compaireing
timoschilling authored
29 match?(rails_version, "~> 4.0")
40f9faf Justin French add Util.rails_4? and Util.rails_4_1? for detecting Rails version variat...
authored
30 end
73bc907 Timo Schilling refector version compaireing
timoschilling authored
31
e411fe1 Thomas Walpole enable tests to pass on rails edge
twalpole authored
32 def rails4_0?
73bc907 Timo Schilling refector version compaireing
timoschilling authored
33 match?(rails_version, "~> 4.0.0")
e411fe1 Thomas Walpole enable tests to pass on rails edge
twalpole authored
34 end
40f9faf Justin French add Util.rails_4? and Util.rails_4_1? for detecting Rails version variat...
authored
35
36 def rails4_1?
73bc907 Timo Schilling refector version compaireing
timoschilling authored
37 match?(rails_version, "~> 4.1.0")
40f9faf Justin French add Util.rails_4? and Util.rails_4_1? for detecting Rails version variat...
authored
38 end
73bc907 Timo Schilling refector version compaireing
timoschilling authored
39
d740ee1 Justin French add deprecation notice for supporting rails < 3.2
authored
40 def deprecated_version_of_rails?
7611837 Justin French extract minimum rails version out to a method and use that in deprecatio...
authored
41 match?(rails_version, "< #{minimum_version_of_rails}")
42 end
43
44 def minimum_version_of_rails
45 "4.1.0"
e0ff956 Justin French add failing spec and fix rails version check
authored
46 end
47
48 def rails_version
73bc907 Timo Schilling refector version compaireing
timoschilling authored
49 ::Rails::VERSION::STRING
50 end
51
52 def match?(version, dependency)
53 Gem::Dependency.new("formtastic", dependency).match?("formtastic", version)
d740ee1 Justin French add deprecation notice for supporting rails < 3.2
authored
54 end
4347a85 Gabriel Sobrinho Strip whitespaces
sobrinho authored
55
d52d829 Morton Jonuschat Mark formtastic outputs as html_safe
yabawock authored
56 end
57 end
Something went wrong with that request. Please try again.