]> source.dussan.org Git - redmine.git/commitdiff
Extract classes to their own files to prevent loading issues (#20508).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Oct 2015 18:03:25 +0000 (18:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Oct 2015 18:03:25 +0000 (18:03 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14694 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine.rb
lib/redmine/hook.rb
lib/redmine/hook/listener.rb [new file with mode: 0644]
lib/redmine/hook/view_listener.rb [new file with mode: 0644]

index 5e5525ddbd9027a38c2929fa3382baa5630d45bf..a7e29c8918e3696c5c96040b0db1ce889f969a1a 100644 (file)
@@ -60,6 +60,8 @@ require 'redmine/views/builders'
 
 require 'redmine/themes'
 require 'redmine/hook'
+require 'redmine/hook/listener'
+require 'redmine/hook/view_listener'
 require 'redmine/plugin'
 
 Redmine::Scm::Base.add "Subversion"
index fc5692caba74c578da565b813cc445e0f0cae6de..1328a4413961833d41734cf1991cd9b2ab0a67bb 100644 (file)
@@ -64,77 +64,6 @@ module Redmine
       end
     end
 
-    # Base class for hook listeners.
-    class Listener
-      include Singleton
-      include Redmine::I18n
-
-      # Registers the listener
-      def self.inherited(child)
-        Redmine::Hook.add_listener(child)
-        super
-      end
-
-    end
-
-    # Listener class used for views hooks.
-    # Listeners that inherit this class will include various helpers by default.
-    class ViewListener < Listener
-      include ERB::Util
-      include ActionView::Helpers::TagHelper
-      include ActionView::Helpers::FormHelper
-      include ActionView::Helpers::FormTagHelper
-      include ActionView::Helpers::FormOptionsHelper
-      include ActionView::Helpers::JavaScriptHelper
-      include ActionView::Helpers::NumberHelper
-      include ActionView::Helpers::UrlHelper
-      include ActionView::Helpers::AssetTagHelper
-      include ActionView::Helpers::TextHelper
-      include Rails.application.routes.url_helpers
-      include ApplicationHelper
-
-      # Default to creating links using only the path.  Subclasses can
-      # change this default as needed
-      def self.default_url_options
-        {:only_path => true, :script_name => Redmine::Utils.relative_url_root}
-      end
-
-      # Helper method to directly render using the context,
-      # render_options must be valid #render options.
-      #
-      #   class MyHook < Redmine::Hook::ViewListener
-      #     render_on :view_issues_show_details_bottom, :partial => "show_more_data"
-      #   end
-      #
-      #   class MultipleHook < Redmine::Hook::ViewListener
-      #     render_on :view_issues_show_details_bottom,
-      #       {:partial => "show_more_data"},
-      #       {:partial => "show_even_more_data"}
-      #   end
-      #
-      def self.render_on(hook, *render_options)
-        define_method hook do |context|
-          render_options.map do |options|
-            if context[:hook_caller].respond_to?(:render)
-              context[:hook_caller].send(:render, {:locals => context}.merge(options))
-            elsif context[:controller].is_a?(ActionController::Base)
-              context[:controller].send(:render_to_string, {:locals => context}.merge(options))
-            else
-              raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}"
-            end
-          end
-        end
-      end
-      
-      def controller
-        nil
-      end
-      
-      def config
-        ActionController::Base.config
-      end
-    end
-
     # Helper module included in ApplicationHelper and ActionController so that
     # hooks can be called in views like this:
     #
diff --git a/lib/redmine/hook/listener.rb b/lib/redmine/hook/listener.rb
new file mode 100644 (file)
index 0000000..d495a9b
--- /dev/null
@@ -0,0 +1,32 @@
+# Redmine - project management software
+# Copyright (C) 2006-2015  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+module Redmine
+  module Hook
+    # Base class for hook listeners.
+    class Listener
+      include Singleton
+      include Redmine::I18n
+
+      # Registers the listener
+      def self.inherited(child)
+        Redmine::Hook.add_listener(child)
+        super
+      end
+    end
+  end
+end
\ No newline at end of file
diff --git a/lib/redmine/hook/view_listener.rb b/lib/redmine/hook/view_listener.rb
new file mode 100644 (file)
index 0000000..998bff0
--- /dev/null
@@ -0,0 +1,78 @@
+# Redmine - project management software
+# Copyright (C) 2006-2015  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+module Redmine
+  module Hook
+    # Listener class used for views hooks.
+    # Listeners that inherit this class will include various helpers by default.
+    class ViewListener < Listener
+      include ERB::Util
+      include ActionView::Helpers::TagHelper
+      include ActionView::Helpers::FormHelper
+      include ActionView::Helpers::FormTagHelper
+      include ActionView::Helpers::FormOptionsHelper
+      include ActionView::Helpers::JavaScriptHelper
+      include ActionView::Helpers::NumberHelper
+      include ActionView::Helpers::UrlHelper
+      include ActionView::Helpers::AssetTagHelper
+      include ActionView::Helpers::TextHelper
+      include Rails.application.routes.url_helpers
+      include ApplicationHelper
+
+      # Default to creating links using only the path.  Subclasses can
+      # change this default as needed
+      def self.default_url_options
+        {:only_path => true, :script_name => Redmine::Utils.relative_url_root}
+      end
+
+      # Helper method to directly render using the context,
+      # render_options must be valid #render options.
+      #
+      #   class MyHook < Redmine::Hook::ViewListener
+      #     render_on :view_issues_show_details_bottom, :partial => "show_more_data"
+      #   end
+      #
+      #   class MultipleHook < Redmine::Hook::ViewListener
+      #     render_on :view_issues_show_details_bottom,
+      #       {:partial => "show_more_data"},
+      #       {:partial => "show_even_more_data"}
+      #   end
+      #
+      def self.render_on(hook, *render_options)
+        define_method hook do |context|
+          render_options.map do |options|
+            if context[:hook_caller].respond_to?(:render)
+              context[:hook_caller].send(:render, {:locals => context}.merge(options))
+            elsif context[:controller].is_a?(ActionController::Base)
+              context[:controller].send(:render_to_string, {:locals => context}.merge(options))
+            else
+              raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}"
+            end
+          end
+        end
+      end
+      
+      def controller
+        nil
+      end
+      
+      def config
+        ActionController::Base.config
+      end
+    end
+  end
+end