summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-19 18:03:25 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-19 18:03:25 +0000
commit9244f67e286233d80ea7f55c368db1a38704b8ef (patch)
treedae37191a1465d790e9a033ee3e5c6535bbb48b8
parent7356e18d36a6501ff0bce2434a5162f7a47ecb1a (diff)
downloadredmine-9244f67e286233d80ea7f55c368db1a38704b8ef.tar.gz
redmine-9244f67e286233d80ea7f55c368db1a38704b8ef.zip
Extract classes to their own files to prevent loading issues (#20508).
git-svn-id: http://svn.redmine.org/redmine/trunk@14694 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--lib/redmine.rb2
-rw-r--r--lib/redmine/hook.rb71
-rw-r--r--lib/redmine/hook/listener.rb32
-rw-r--r--lib/redmine/hook/view_listener.rb78
4 files changed, 112 insertions, 71 deletions
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 5e5525ddb..a7e29c891 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -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"
diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb
index fc5692cab..1328a4413 100644
--- a/lib/redmine/hook.rb
+++ b/lib/redmine/hook.rb
@@ -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
index 000000000..d495a9bc9
--- /dev/null
+++ b/lib/redmine/hook/listener.rb
@@ -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
index 000000000..998bff088
--- /dev/null
+++ b/lib/redmine/hook/view_listener.rb
@@ -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