mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make ActionController::Base.modules_for_helpers and ActionController::Base.all_helpers_from_path public methods
This commit is contained in:
parent
820c0feda3
commit
d4bea35f1a
3 changed files with 41 additions and 41 deletions
|
@ -112,17 +112,6 @@ module AbstractController
|
|||
default_helper_module! unless anonymous?
|
||||
end
|
||||
|
||||
private
|
||||
# Makes all the (instance) methods in the helper module available to templates
|
||||
# rendered through this controller.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>module</tt> - The module to include into the current helper module
|
||||
# for the class
|
||||
def add_template_helper(mod)
|
||||
_helpers.module_eval { include mod }
|
||||
end
|
||||
|
||||
# Returns a list of modules, normalized from the acceptable kinds of
|
||||
# helpers with the following behavior:
|
||||
#
|
||||
|
@ -155,6 +144,17 @@ module AbstractController
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Makes all the (instance) methods in the helper module available to templates
|
||||
# rendered through this controller.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>module</tt> - The module to include into the current helper module
|
||||
# for the class
|
||||
def add_template_helper(mod)
|
||||
_helpers.module_eval { include mod }
|
||||
end
|
||||
|
||||
def default_helper_module!
|
||||
module_name = name.sub(/Controller$/, '')
|
||||
module_path = module_name.underscore
|
||||
|
|
|
@ -76,35 +76,35 @@ module ActionController
|
|||
@helper_proxy ||= ActionView::Base.new.extend(_helpers)
|
||||
end
|
||||
|
||||
# Overwrite modules_for_helpers to accept :all as argument, which loads
|
||||
# all helpers in helpers_path.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>args</tt> - A list of helpers
|
||||
#
|
||||
# ==== Returns
|
||||
# * <tt>array</tt> - A normalized list of modules for the list of helpers provided.
|
||||
def modules_for_helpers(args)
|
||||
args += all_application_helpers if args.delete(:all)
|
||||
super(args)
|
||||
end
|
||||
|
||||
def all_helpers_from_path(path)
|
||||
helpers = []
|
||||
Array.wrap(path).each do |_path|
|
||||
extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
|
||||
helpers += Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
|
||||
end
|
||||
helpers.sort!
|
||||
helpers.uniq!
|
||||
helpers
|
||||
end
|
||||
|
||||
private
|
||||
# Overwrite modules_for_helpers to accept :all as argument, which loads
|
||||
# all helpers in helpers_path.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * <tt>args</tt> - A list of helpers
|
||||
#
|
||||
# ==== Returns
|
||||
# * <tt>array</tt> - A normalized list of modules for the list of helpers provided.
|
||||
def modules_for_helpers(args)
|
||||
args += all_application_helpers if args.delete(:all)
|
||||
super(args)
|
||||
end
|
||||
|
||||
# Extract helper names from files in <tt>app/helpers/**/*_helper.rb</tt>
|
||||
def all_application_helpers
|
||||
all_helpers_from_path(helpers_path)
|
||||
end
|
||||
|
||||
def all_helpers_from_path(path)
|
||||
helpers = []
|
||||
Array.wrap(path).each do |_path|
|
||||
extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
|
||||
helpers += Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
|
||||
end
|
||||
helpers.sort!
|
||||
helpers.uniq!
|
||||
helpers
|
||||
end
|
||||
# Extract helper names from files in <tt>app/helpers/**/*_helper.rb</tt>
|
||||
def all_application_helpers
|
||||
all_helpers_from_path(helpers_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -415,8 +415,8 @@ module Rails
|
|||
paths["app/helpers"].existent
|
||||
end
|
||||
|
||||
all = ActionController::Base.send(:all_helpers_from_path, helpers_paths)
|
||||
ActionController::Base.send(:modules_for_helpers, all).each do |mod|
|
||||
all = ActionController::Base.all_helpers_from_path(helpers_paths)
|
||||
ActionController::Base.modules_for_helpers(all).each do |mod|
|
||||
helpers.send(:include, mod)
|
||||
end
|
||||
helpers
|
||||
|
|
Loading…
Reference in a new issue