activesupport 2.3.5 → 2.3.6.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/CHANGELOG +23 -0
  2. data/lib/active_support.rb +1 -0
  3. data/lib/active_support/core_ext/date_time/conversions.rb +14 -3
  4. data/lib/active_support/core_ext/enumerable.rb +6 -0
  5. data/lib/active_support/core_ext/file/atomic.rb +2 -1
  6. data/lib/active_support/core_ext/numeric/conversions.rb +2 -2
  7. data/lib/active_support/core_ext/object.rb +1 -0
  8. data/lib/active_support/core_ext/object/metaclass.rb +6 -5
  9. data/lib/active_support/core_ext/object/singleton_class.rb +13 -0
  10. data/lib/active_support/core_ext/string.rb +0 -1
  11. data/lib/active_support/core_ext/string/output_safety.rb +148 -44
  12. data/lib/active_support/core_ext/time/calculations.rb +1 -1
  13. data/lib/active_support/inflector.rb +1 -1
  14. data/lib/active_support/json/backends/yajl.rb +40 -0
  15. data/lib/active_support/json/decoding.rb +16 -1
  16. data/lib/active_support/json/encoding.rb +11 -2
  17. data/lib/active_support/ordered_hash.rb +24 -1
  18. data/lib/active_support/vendor.rb +10 -2
  19. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +76 -0
  20. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/MIT-LICENSE +0 -0
  21. data/lib/active_support/vendor/i18n-0.3.3/README.textile +81 -0
  22. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +24 -0
  23. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +144 -0
  24. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +71 -0
  25. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +17 -0
  26. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +165 -0
  27. data/lib/active_support/vendor/i18n-0.3.3/init.rb +1 -0
  28. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n.rb +99 -21
  29. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb +17 -0
  30. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb +70 -0
  31. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb +67 -0
  32. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb +38 -0
  33. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb +83 -0
  34. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb +259 -0
  35. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb +75 -0
  36. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb +44 -0
  37. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb +74 -0
  38. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb +52 -0
  39. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb +68 -0
  40. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb +75 -0
  41. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb +80 -0
  42. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb +119 -0
  43. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb +73 -0
  44. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb +57 -0
  45. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb +22 -0
  46. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb +5 -0
  47. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb +99 -0
  48. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n/exceptions.rb +14 -6
  49. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb +25 -0
  50. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb +5 -0
  51. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb +64 -0
  52. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb +6 -0
  53. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb +98 -0
  54. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb +28 -0
  55. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb +24 -0
  56. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb +76 -0
  57. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb +41 -0
  58. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +3 -0
  59. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +8 -0
  60. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +15 -0
  61. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +40 -0
  62. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +92 -0
  63. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +55 -0
  64. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +91 -0
  65. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +90 -0
  66. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +54 -0
  67. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +84 -0
  68. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +45 -0
  69. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +35 -0
  70. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +40 -0
  71. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +29 -0
  72. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +40 -0
  73. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +31 -0
  74. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +26 -0
  75. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +33 -0
  76. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +31 -0
  77. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +33 -0
  78. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +21 -0
  79. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +60 -0
  80. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +52 -0
  81. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +72 -0
  82. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +66 -0
  83. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +64 -0
  84. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +57 -0
  85. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +50 -0
  86. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +26 -0
  87. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +107 -0
  88. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +67 -0
  89. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +43 -0
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +77 -0
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +94 -0
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +201 -0
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +91 -0
  94. data/lib/active_support/vendor/{i18n-0.1.3/test → i18n-0.3.3/test/cases}/i18n_exceptions_test.rb +8 -10
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +23 -0
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +172 -0
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +126 -0
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +143 -0
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +33 -0
  100. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +72 -0
  101. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +3 -0
  102. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +3 -0
  103. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +113 -0
  104. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +100 -0
  105. data/lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb +329 -0
  106. data/lib/active_support/version.rb +1 -1
  107. data/lib/active_support/whiny_nil.rb +1 -1
  108. data/lib/active_support/xml_mini/libxml.rb +23 -83
  109. data/lib/active_support/xml_mini/libxmlsax.rb +74 -0
  110. data/lib/active_support/xml_mini/nokogiri.rb +25 -22
  111. data/lib/active_support/xml_mini/nokogirisax.rb +73 -0
  112. metadata +108 -20
  113. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  114. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  115. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  116. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
  117. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  118. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  119. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  120. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  121. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
data/CHANGELOG CHANGED
@@ -1,17 +1,40 @@
1
+ *2.3.6 (pending)*
2
+
3
+ * Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. [Jeremy Kemper]
4
+
5
+ * JSON backend for YAJL. Preferred if available. #2666 [Brian Lopez]
6
+
7
+ * Introduce String#html_safe for rails_xss plugin and forward-compatibility with Rails 3. [Michael Koziarski, Santiago Pastorino, José Ignacio Costa]
8
+
9
+ * Time#- with a DateTime argument behaves the same as with a Time argument, i.e. returns the difference between self and arg as a Float #3476 [Geoff Buesing]
10
+
11
+ * YAML serialization for OrderedHash. #3608 [Gregor Schmidt]
12
+
13
+ * Update bundled TZInfo to v0.3.16 [Geoff Buesing]
14
+
15
+ * Georgetown TimeZone is now mapped to "America/Guyana" instead of "America/Argentina/San_Juan" #1821 [Geoff Buesing, Reuben Sivan]
16
+
17
+ * Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]
18
+
19
+
1
20
  *2.3.5 (November 25, 2009)*
2
21
 
3
22
  * Minor Bug Fixes and deprecation warnings
4
23
 
24
+ * Update Edinburgh TimeZone to use "Europe/London" instead of "Europe/Dublin" #3310 [Phil Ross]
25
+
5
26
  * Fixes for the Nokogiri backend for XmlMini
6
27
 
7
28
  * Ruby 1.9 Compatibility
8
29
 
30
+
9
31
  *2.3.4 (September 4, 2009)*
10
32
 
11
33
  * Introduce ActiveSupport::Multibyte.clean to clean invalid multibyte strings.
12
34
 
13
35
  * Bug fixes
14
36
 
37
+
15
38
  *2.3.3 (July 12, 2009)*
16
39
 
17
40
  * JSON: +Object#to_json+ calls +as_json+ to coerce itself into something natively encodable like +Hash+, +Integer+, or +String+. Override +as_json+ instead of +to_json+ so you're JSON-library-agnostic. [Jeremy Kemper]
@@ -44,6 +44,7 @@ module ActiveSupport
44
44
  autoload :OrderedHash, 'active_support/ordered_hash'
45
45
  autoload :OrderedOptions, 'active_support/ordered_options'
46
46
  autoload :Rescuable, 'active_support/rescuable'
47
+ autoload :SafeBuffer, 'active_support/core_ext/string/output_safety'
47
48
  autoload :SecureRandom, 'active_support/secure_random'
48
49
  autoload :StringInquirer, 'active_support/string_inquirer'
49
50
  autoload :TimeWithZone, 'active_support/time_with_zone'
@@ -84,11 +84,22 @@ module ActiveSupport #:nodoc:
84
84
  def xmlschema
85
85
  strftime("%Y-%m-%dT%H:%M:%S%Z")
86
86
  end if RUBY_VERSION < '1.9'
87
-
87
+
88
88
  # Converts self to a floating-point number of seconds since the Unix epoch
89
89
  def to_f
90
- days_since_unix_epoch = self - ::DateTime.civil(1970)
91
- (days_since_unix_epoch * 86_400).to_f
90
+ seconds_since_unix_epoch.to_f
91
+ end
92
+
93
+ # Converts self to an integer number of seconds since the Unix epoch
94
+ def to_i
95
+ seconds_since_unix_epoch.to_i
96
+ end
97
+
98
+ private
99
+
100
+ def seconds_since_unix_epoch
101
+ seconds_per_day = 86_400
102
+ (self - ::DateTime.civil(1970)) * seconds_per_day
92
103
  end
93
104
  end
94
105
  end
@@ -111,4 +111,10 @@ module Enumerable
111
111
  def none?(&block)
112
112
  !any?(&block)
113
113
  end unless [].respond_to?(:none?)
114
+
115
+
116
+ # The negative of the Enumerable#include?. Returns true if the collection does not include the object.
117
+ def exclude?(object)
118
+ !include?(object)
119
+ end
114
120
  end
@@ -17,6 +17,7 @@ module ActiveSupport #:nodoc:
17
17
  # end
18
18
  def atomic_write(file_name, temp_dir = Dir.tmpdir)
19
19
  require 'tempfile' unless defined?(Tempfile)
20
+ require 'fileutils' unless defined?(FileUtils)
20
21
 
21
22
  temp_file = Tempfile.new(basename(file_name), temp_dir)
22
23
  yield temp_file
@@ -34,7 +35,7 @@ module ActiveSupport #:nodoc:
34
35
  end
35
36
 
36
37
  # Overwrite original file with temp file
37
- rename(temp_file.path, file_name)
38
+ FileUtils.mv(temp_file.path, file_name)
38
39
 
39
40
  # Set correct permissions on new file
40
41
  chown(old_stat.uid, old_stat.gid, file_name)
@@ -8,10 +8,10 @@ module ActiveSupport #:nodoc:
8
8
  # -21_600.to_utc_offset_s # => "-06:00"
9
9
  def to_utc_offset_s(colon=true)
10
10
  seconds = self
11
- sign = (seconds < 0 ? -1 : 1)
11
+ sign = (seconds < 0 ? '-' : '+')
12
12
  hours = seconds.abs / 3600
13
13
  minutes = (seconds.abs % 3600) / 60
14
- "%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ]
14
+ "%s%02d%s%02d" % [ sign, hours, colon ? ":" : "", minutes ]
15
15
  end
16
16
  end
17
17
  end
@@ -3,4 +3,5 @@ require 'active_support/core_ext/object/conversions'
3
3
  require 'active_support/core_ext/object/extending'
4
4
  require 'active_support/core_ext/object/instance_variables'
5
5
  require 'active_support/core_ext/object/metaclass'
6
+ require 'active_support/core_ext/object/singleton_class'
6
7
  require 'active_support/core_ext/object/misc'
@@ -1,13 +1,14 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  class Object
2
- # Get object's meta (ghost, eigenclass, singleton) class
4
+ # Get object's meta (ghost, eigenclass, singleton) class.
5
+ #
6
+ # Deprecated in favor of Object#singleton_class.
3
7
  def metaclass
4
8
  class << self
5
9
  self
6
10
  end
7
11
  end
8
12
 
9
- # If class_eval is called on an object, add those methods to its metaclass
10
- def class_eval(*args, &block)
11
- metaclass.class_eval(*args, &block)
12
- end
13
+ deprecate :metaclass => :singleton_class
13
14
  end
@@ -0,0 +1,13 @@
1
+ class Object
2
+ # Returns the object's singleton class.
3
+ def singleton_class
4
+ class << self
5
+ self
6
+ end
7
+ end unless respond_to?(:singleton_class)
8
+
9
+ # class_eval on an object acts like singleton_class_eval.
10
+ def class_eval(*args, &block)
11
+ singleton_class.class_eval(*args, &block)
12
+ end
13
+ end
@@ -21,5 +21,4 @@ class String #:nodoc:
21
21
  include ActiveSupport::CoreExtensions::String::Iterators
22
22
  include ActiveSupport::CoreExtensions::String::Behavior
23
23
  include ActiveSupport::CoreExtensions::String::Multibyte
24
- include ActiveSupport::CoreExtensions::String::OutputSafety
25
24
  end
@@ -1,48 +1,152 @@
1
+ require 'erb'
2
+
3
+ class ERB
4
+ undef :set_eoutvar
5
+ def set_eoutvar(compiler, eoutvar = '_erbout')
6
+ compiler.put_cmd = "#{eoutvar}.safe_concat"
7
+ compiler.insert_cmd = "#{eoutvar}.safe_concat"
8
+
9
+ cmd = []
10
+ cmd.push "#{eoutvar} = ActiveSupport::SafeBuffer.new"
11
+
12
+ compiler.pre_cmd = cmd
13
+
14
+ cmd = []
15
+ cmd.push(eoutvar)
16
+
17
+ compiler.post_cmd = cmd
18
+ end
19
+
20
+ module Util
21
+ HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
22
+ JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
23
+
24
+ # A utility method for escaping HTML tag characters.
25
+ # This method is also aliased as <tt>h</tt>.
26
+ #
27
+ # In your ERb templates, use this method to escape any unsafe content. For example:
28
+ # <%=h @person.name %>
29
+ #
30
+ # ==== Example:
31
+ # puts html_escape("is a > 0 & a < 10?")
32
+ # # => is a &gt; 0 &amp; a &lt; 10?
33
+ def html_escape(s)
34
+ s = s.to_s
35
+ if s.html_safe?
36
+ s
37
+ else
38
+ s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }.html_safe
39
+ end
40
+ end
41
+
42
+ undef :h
43
+ alias h html_escape
44
+
45
+ module_function :html_escape
46
+ module_function :h
47
+
48
+ # A utility method for escaping HTML entities in JSON strings.
49
+ # This method is also aliased as <tt>j</tt>.
50
+ #
51
+ # In your ERb templates, use this method to escape any HTML entities:
52
+ # <%=j @person.to_json %>
53
+ #
54
+ # ==== Example:
55
+ # puts json_escape("is a > 0 & a < 10?")
56
+ # # => is a \u003E 0 \u0026 a \u003C 10?
57
+ def json_escape(s)
58
+ s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
59
+ end
60
+
61
+ alias j json_escape
62
+ module_function :j
63
+ module_function :json_escape
64
+ end
65
+ end
66
+
67
+ class Object
68
+ def html_safe?
69
+ false
70
+ end
71
+ end
72
+
73
+ class Fixnum
74
+ def html_safe?
75
+ true
76
+ end
77
+ end
78
+
1
79
  module ActiveSupport #:nodoc:
2
- module CoreExtensions #:nodoc:
3
- module String #:nodoc:
4
- module OutputSafety
5
- def self.included(base)
6
- base.class_eval do
7
- alias_method :add_without_safety, :+
8
- alias_method :+, :add_with_safety
9
- alias_method_chain :concat, :safety
10
- undef_method :<<
11
- alias_method :<<, :concat_with_safety
12
- end
13
- end
14
-
15
- def html_safe?
16
- defined?(@_rails_html_safe) && @_rails_html_safe
17
- end
18
-
19
- def html_safe!
20
- @_rails_html_safe = true
21
- self
22
- end
23
-
24
- def add_with_safety(other)
25
- result = add_without_safety(other)
26
- if html_safe? && also_html_safe?(other)
27
- result.html_safe!
28
- else
29
- result
30
- end
31
- end
32
-
33
- def concat_with_safety(other_or_fixnum)
34
- result = concat_without_safety(other_or_fixnum)
35
- unless html_safe? && also_html_safe?(other_or_fixnum)
36
- @_rails_html_safe = false
37
- end
38
- result
39
- end
40
-
41
- private
42
- def also_html_safe?(other)
43
- other.respond_to?(:html_safe?) && other.html_safe?
44
- end
80
+ class SafeBuffer < String
81
+ alias safe_concat concat
82
+
83
+ def concat(value)
84
+ if value.html_safe?
85
+ super(value)
86
+ else
87
+ super(ERB::Util.h(value))
45
88
  end
46
89
  end
90
+ alias << concat
91
+
92
+ def +(other)
93
+ dup.concat(other)
94
+ end
95
+
96
+ def html_safe?
97
+ true
98
+ end
99
+
100
+ def html_safe
101
+ self
102
+ end
103
+
104
+ def to_s
105
+ self
106
+ end
107
+ end
108
+ end
109
+
110
+ class String
111
+ alias_method :add_without_safety, :+
112
+
113
+ def html_safe
114
+ ActiveSupport::SafeBuffer.new(self)
47
115
  end
48
- end
116
+
117
+ def html_safe?
118
+ defined?(@_rails_html_safe) && @_rails_html_safe
119
+ end
120
+
121
+ def html_safe!
122
+ ActiveSupport::Deprecation.warn("Use html_safe with your strings instead of html_safe! See http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/ for the full story.", caller)
123
+ @_rails_html_safe = true
124
+ self
125
+ end
126
+
127
+ def add_with_safety(other)
128
+ result = add_without_safety(other)
129
+ if html_safe? && also_html_safe?(other)
130
+ result.html_safe!
131
+ else
132
+ result
133
+ end
134
+ end
135
+ alias_method :+, :add_with_safety
136
+
137
+ def concat_with_safety(other_or_fixnum)
138
+ result = concat_without_safety(other_or_fixnum)
139
+ unless html_safe? && also_html_safe?(other_or_fixnum)
140
+ @_rails_html_safe = false
141
+ end
142
+ result
143
+ end
144
+ alias_method_chain :concat, :safety
145
+ undef_method :<<
146
+ alias_method :<<, :concat_with_safety
147
+
148
+ private
149
+ def also_html_safe?(other)
150
+ other.respond_to?(:html_safe?) && other.html_safe?
151
+ end
152
+ end
@@ -283,7 +283,7 @@ module ActiveSupport #:nodoc:
283
283
  # are coerced into values that Time#- will recognize
284
284
  def minus_with_coercion(other)
285
285
  other = other.comparable_time if other.respond_to?(:comparable_time)
286
- minus_without_coercion(other)
286
+ other.is_a?(::DateTime) ? to_f - other.to_f : minus_without_coercion(other)
287
287
  end
288
288
 
289
289
  # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
@@ -260,7 +260,7 @@ module ActiveSupport
260
260
  # replace accented chars with ther ascii equivalents
261
261
  parameterized_string = transliterate(string)
262
262
  # Turn unwanted chars into the seperator
263
- parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
263
+ parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep)
264
264
  unless sep.blank?
265
265
  re_sep = Regexp.escape(sep)
266
266
  # No more than one of the separator in a row.
@@ -0,0 +1,40 @@
1
+ require 'yajl-ruby' unless defined?(Yajl)
2
+
3
+ module ActiveSupport
4
+ module JSON
5
+ module Backends
6
+ module Yajl
7
+ ParseError = ::Yajl::ParseError
8
+ extend self
9
+
10
+ # Parses a JSON string or IO and convert it into an object
11
+ def decode(json)
12
+ data = ::Yajl::Parser.new.parse(json)
13
+ if ActiveSupport.parse_json_times
14
+ convert_dates_from(data)
15
+ else
16
+ data
17
+ end
18
+ end
19
+
20
+ private
21
+ def convert_dates_from(data)
22
+ case data
23
+ when nil
24
+ nil
25
+ when DATE_REGEX
26
+ DateTime.parse(data)
27
+ when Array
28
+ data.map! { |d| convert_dates_from(d) }
29
+ when Hash
30
+ data.each do |key, value|
31
+ data[key] = convert_dates_from(value)
32
+ end
33
+ else
34
+ data
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -5,12 +5,15 @@ module ActiveSupport
5
5
  mattr_accessor :parse_json_times
6
6
 
7
7
  module JSON
8
+ # Listed in order of preference.
9
+ DECODERS = %w(Yajl JSONGem Yaml)
10
+
8
11
  class << self
9
12
  attr_reader :parse_error
10
13
  delegate :decode, :to => :backend
11
14
 
12
15
  def backend
13
- self.backend = "Yaml" unless defined?(@backend)
16
+ set_default_backend unless defined?(@backend)
14
17
  @backend
15
18
  end
16
19
 
@@ -30,6 +33,18 @@ module ActiveSupport
30
33
  ensure
31
34
  self.backend = old_backend
32
35
  end
36
+
37
+ def set_default_backend
38
+ DECODERS.find do |name|
39
+ begin
40
+ self.backend = name
41
+ true
42
+ rescue LoadError
43
+ # Try next decoder.
44
+ false
45
+ end
46
+ end
47
+ end
33
48
  end
34
49
  end
35
50
  end