diff config/initializers/10-patches.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents dffacf8a6908
children
line wrap: on
line diff
--- a/config/initializers/10-patches.rb	Mon Mar 17 08:57:04 2014 +0000
+++ b/config/initializers/10-patches.rb	Thu Sep 11 12:46:20 2014 +0100
@@ -91,6 +91,43 @@
 
 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
 
+# HTML5: <option value=""></option> is invalid, use <option value="">&nbsp;</option> instead
+module ActionView
+  module Helpers
+    class InstanceTag
+      private
+      def add_options_with_non_empty_blank_option(option_tags, options, value = nil)
+        if options[:include_blank] == true
+          options = options.dup
+          options[:include_blank] = '&nbsp;'.html_safe
+        end
+        add_options_without_non_empty_blank_option(option_tags, options, value)
+      end
+      alias_method_chain :add_options, :non_empty_blank_option
+    end
+
+    module FormTagHelper
+      def select_tag_with_non_empty_blank_option(name, option_tags = nil, options = {})
+        if options.delete(:include_blank)
+          options[:prompt] = '&nbsp;'.html_safe
+        end
+        select_tag_without_non_empty_blank_option(name, option_tags, options)
+      end
+      alias_method_chain :select_tag, :non_empty_blank_option
+    end
+
+    module FormOptionsHelper
+      def options_for_select_with_non_empty_blank_option(container, selected = nil)
+        if container.is_a?(Array)
+          container = container.map {|element| element.blank? ? ["&nbsp;".html_safe, ""] : element}
+        end
+        options_for_select_without_non_empty_blank_option(container, selected)
+      end
+      alias_method_chain :options_for_select, :non_empty_blank_option
+    end
+  end
+end
+
 require 'mail'
 
 module DeliveryMethods
@@ -165,3 +202,59 @@
     end
   end
 end
+
+if Rails::VERSION::MAJOR < 4 && RUBY_VERSION >= "2.1"
+  module ActiveSupport
+    class HashWithIndifferentAccess
+      def select(*args, &block)
+        dup.tap { |hash| hash.select!(*args, &block) }
+      end
+
+      def reject(*args, &block)
+        dup.tap { |hash| hash.reject!(*args, &block) }
+      end
+    end
+
+    class OrderedHash
+      def select(*args, &block)
+        dup.tap { |hash| hash.select!(*args, &block) }
+      end
+
+      def reject(*args, &block)
+        dup.tap { |hash| hash.reject!(*args, &block) }
+      end
+    end
+  end
+end
+
+require 'awesome_nested_set/version'
+
+module CollectiveIdea
+  module Acts
+    module NestedSet
+      module Model
+        def leaf_with_new_record?
+          new_record? || leaf_without_new_record?
+        end
+        alias_method_chain :leaf?, :new_record
+        # Reload is needed because children may have updated
+        # their parent (self) during deletion.
+        if ::AwesomeNestedSet::VERSION > "2.1.6"
+          module Prunable
+            def destroy_descendants_with_reload
+              destroy_descendants_without_reload
+              reload
+            end
+            alias_method_chain :destroy_descendants, :reload
+          end
+        else
+          def destroy_descendants_with_reload
+            destroy_descendants_without_reload
+            reload
+          end
+          alias_method_chain :destroy_descendants, :reload
+        end
+      end
+    end
+  end
+end