From 71638e6760bed0445e5fefc185924b07076fef47 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 6 Aug 2009 22:51:24 -0300 Subject: Move AbstractController to a top-level component --- actionpack/lib/abstract_controller.rb | 16 ++ actionpack/lib/abstract_controller/base.rb | 159 ++++++++++++++++++++ actionpack/lib/abstract_controller/benchmarker.rb | 38 +++++ actionpack/lib/abstract_controller/callbacks.rb | 115 +++++++++++++++ actionpack/lib/abstract_controller/exceptions.rb | 12 ++ actionpack/lib/abstract_controller/helpers.rb | 82 +++++++++++ actionpack/lib/abstract_controller/layouts.rb | 164 +++++++++++++++++++++ actionpack/lib/abstract_controller/logger.rb | 52 +++++++ actionpack/lib/abstract_controller/renderer.rb | 156 ++++++++++++++++++++ actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/abstract.rb | 16 -- actionpack/lib/action_controller/abstract/base.rb | 159 -------------------- .../lib/action_controller/abstract/benchmarker.rb | 38 ----- .../lib/action_controller/abstract/callbacks.rb | 115 --------------- .../lib/action_controller/abstract/exceptions.rb | 12 -- .../lib/action_controller/abstract/helpers.rb | 82 ----------- .../lib/action_controller/abstract/layouts.rb | 164 --------------------- .../lib/action_controller/abstract/logger.rb | 52 ------- .../lib/action_controller/abstract/renderer.rb | 156 -------------------- actionpack/lib/action_controller/metal.rb | 2 - actionpack/test/abstract_controller/test_helper.rb | 2 +- actionpack/test/abstract_unit.rb | 1 - 22 files changed, 796 insertions(+), 799 deletions(-) create mode 100644 actionpack/lib/abstract_controller.rb create mode 100644 actionpack/lib/abstract_controller/base.rb create mode 100644 actionpack/lib/abstract_controller/benchmarker.rb create mode 100644 actionpack/lib/abstract_controller/callbacks.rb create mode 100644 actionpack/lib/abstract_controller/exceptions.rb create mode 100644 actionpack/lib/abstract_controller/helpers.rb create mode 100644 actionpack/lib/abstract_controller/layouts.rb create mode 100644 actionpack/lib/abstract_controller/logger.rb create mode 100644 actionpack/lib/abstract_controller/renderer.rb delete mode 100644 actionpack/lib/action_controller/abstract.rb delete mode 100644 actionpack/lib/action_controller/abstract/base.rb delete mode 100644 actionpack/lib/action_controller/abstract/benchmarker.rb delete mode 100644 actionpack/lib/action_controller/abstract/callbacks.rb delete mode 100644 actionpack/lib/action_controller/abstract/exceptions.rb delete mode 100644 actionpack/lib/action_controller/abstract/helpers.rb delete mode 100644 actionpack/lib/action_controller/abstract/layouts.rb delete mode 100644 actionpack/lib/action_controller/abstract/logger.rb delete mode 100644 actionpack/lib/action_controller/abstract/renderer.rb (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb new file mode 100644 index 0000000000..f020abaa45 --- /dev/null +++ b/actionpack/lib/abstract_controller.rb @@ -0,0 +1,16 @@ +require "active_support/core_ext/module/attr_internal" +require "active_support/core_ext/module/delegation" + +module AbstractController + autoload :Base, "abstract_controller/base" + autoload :Benchmarker, "abstract_controller/benchmarker" + autoload :Callbacks, "abstract_controller/callbacks" + autoload :Helpers, "abstract_controller/helpers" + autoload :Layouts, "abstract_controller/layouts" + autoload :Logger, "abstract_controller/logger" + autoload :Renderer, "abstract_controller/renderer" + # === Exceptions + autoload :ActionNotFound, "abstract_controller/exceptions" + autoload :DoubleRenderError, "abstract_controller/exceptions" + autoload :Error, "abstract_controller/exceptions" +end diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb new file mode 100644 index 0000000000..b93e6ce634 --- /dev/null +++ b/actionpack/lib/abstract_controller/base.rb @@ -0,0 +1,159 @@ +module AbstractController + + class Base + attr_internal :response_body + attr_internal :action_name + + class << self + attr_reader :abstract + alias_method :abstract?, :abstract + + # Define a controller as abstract. See internal_methods for more + # details. + def abstract! + @abstract = true + end + + def inherited(klass) + ::AbstractController::Base.descendants << klass.to_s + super + end + + # A list of all descendents of AbstractController::Base. This is + # useful for initializers which need to add behavior to all controllers. + def descendants + @descendants ||= [] + end + + # A list of all internal methods for a controller. This finds the first + # abstract superclass of a controller, and gets a list of all public + # instance methods on that abstract class. Public instance methods of + # a controller would normally be considered action methods, so we + # are removing those methods on classes declared as abstract + # (ActionController::Metal and ActionController::Base are defined + # as abstract) + def internal_methods + controller = self + controller = controller.superclass until controller.abstract? + controller.public_instance_methods(true) + end + + # The list of hidden actions to an empty Array. Defaults to an + # empty Array. This can be modified by other modules or subclasses + # to specify particular actions as hidden. + # + # ==== Returns + # Array[String]:: An array of method names that should not be + # considered actions. + def hidden_actions + [] + end + + # A list of method names that should be considered actions. This + # includes all public instance methods on a controller, less + # any internal methods (see #internal_methods), adding back in + # any methods that are internal, but still exist on the class + # itself. Finally, #hidden_actions are removed. + # + # ==== Returns + # Array[String]:: A list of all methods that should be considered + # actions. + def action_methods + @action_methods ||= + # All public instance methods of this class, including ancestors + public_instance_methods(true).map { |m| m.to_s }.to_set - + # Except for public instance methods of Base and its ancestors + internal_methods.map { |m| m.to_s } + + # Be sure to include shadowed public instance methods of this class + public_instance_methods(false).map { |m| m.to_s } - + # And always exclude explicitly hidden actions + hidden_actions + end + end + + abstract! + + # Calls the action going through the entire action dispatch stack. + # + # The actual method that is called is determined by calling + # #method_for_action. If no method can handle the action, then an + # ActionNotFound error is raised. + # + # ==== Returns + # self + def process(action) + @_action_name = action_name = action.to_s + + unless action_name = method_for_action(action_name) + raise ActionNotFound, "The action '#{action}' could not be found" + end + + process_action(action_name) + self + end + + private + # Returns true if the name can be considered an action. This can + # be overridden in subclasses to modify the semantics of what + # can be considered an action. + # + # ==== Parameters + # name:: The name of an action to be tested + # + # ==== Returns + # TrueClass, FalseClass + def action_method?(name) + self.class.action_methods.include?(name) + end + + # Call the action. Override this in a subclass to modify the + # behavior around processing an action. This, and not #process, + # is the intended way to override action dispatching. + def process_action(method_name) + send_action(method_name) + end + + # Actually call the method associated with the action. Override + # this method if you wish to change how action methods are called, + # not to add additional behavior around it. For example, you would + # override #send_action if you want to inject arguments into the + # method. + alias send_action send + + # If the action name was not found, but a method called "action_missing" + # was found, #method_for_action will return "_handle_action_missing". + # This method calls #action_missing with the current action name. + def _handle_action_missing + action_missing(@_action_name) + end + + # Takes an action name and returns the name of the method that will + # handle the action. In normal cases, this method returns the same + # name as it receives. By default, if #method_for_action receives + # a name that is not an action, it will look for an #action_missing + # method and return "_handle_action_missing" if one is found. + # + # Subclasses may override this method to add additional conditions + # that should be considered an action. For instance, an HTTP controller + # with a template matching the action name is considered to exist. + # + # If you override this method to handle additional cases, you may + # also provide a method (like _handle_method_missing) to handle + # the case. + # + # If none of these conditions are true, and method_for_action + # returns nil, an ActionNotFound exception will be raised. + # + # ==== Parameters + # action_name:: An action name to find a method name for + # + # ==== Returns + # String:: The name of the method that handles the action + # nil:: No method name could be found. Raise ActionNotFound. + def method_for_action(action_name) + if action_method?(action_name) then action_name + elsif respond_to?(:action_missing, true) then "_handle_action_missing" + end + end + end +end diff --git a/actionpack/lib/abstract_controller/benchmarker.rb b/actionpack/lib/abstract_controller/benchmarker.rb new file mode 100644 index 0000000000..58e9564c2f --- /dev/null +++ b/actionpack/lib/abstract_controller/benchmarker.rb @@ -0,0 +1,38 @@ +module AbstractController + module Benchmarker + extend ActiveSupport::Concern + + include Logger + + module ClassMethods + # Execute the passed in block, timing the duration of the block in ms. + # + # ==== Parameters + # title<#to_s>:: The title of block to benchmark + # log_level:: A valid log level. Defaults to Logger::DEBUG + # use_silence:: Whether or not to silence the + # logger for the duration of the block. + # + # ==== Returns + # Object:: The result of the block + def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) + if logger && logger.level >= log_level + result = nil + ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } + logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") + result + else + yield + end + end + + # Silences the logger for the duration of the block. + def silence + old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger + yield + ensure + logger.level = old_logger_level if logger + end + end + end +end diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb new file mode 100644 index 0000000000..ea4b59466e --- /dev/null +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -0,0 +1,115 @@ +require "active_support/new_callbacks" + +module AbstractController + module Callbacks + extend ActiveSupport::Concern + + # Uses ActiveSupport::NewCallbacks as the base functionality. For + # more details on the whole callback system, read the documentation + # for ActiveSupport::NewCallbacks. + include ActiveSupport::NewCallbacks + + included do + define_callbacks :process_action, "response_body" + end + + # Override AbstractController::Base's process_action to run the + # process_action callbacks around the normal behavior. + def process_action(method_name) + _run_process_action_callbacks(method_name) do + super + end + end + + module ClassMethods + # If :only or :accept are used, convert the options into the + # primitive form (:per_key) used by ActiveSupport::Callbacks. + # The basic idea is that :only => :index gets converted to + # :if => proc {|c| c.action_name == "index" }, but that the + # proc is only evaluated once per action for the lifetime of + # a Rails process. + # + # ==== Options + # :only<#to_s>:: The callback should be run only for this action + # :except<#to_s>:: The callback should be run for all actions + # except this action + def _normalize_callback_options(options) + if only = options[:only] + only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ") + options[:per_key] = {:if => only} + end + if except = options[:except] + except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") + options[:per_key] = {:unless => except} + end + end + + # Skip before, after, and around filters matching any of the names + # + # ==== Parameters + # *names:: A list of valid names that could be used for + # callbacks. Note that skipping uses Ruby equality, so it's + # impossible to skip a callback defined using an anonymous proc + # using #skip_filter + def skip_filter(*names, &blk) + skip_before_filter(*names) + skip_after_filter(*names) + skip_around_filter(*names) + end + + # Take callback names and an optional callback proc, normalize them, + # then call the block with each callback. This allows us to abstract + # the normalization across several methods that use it. + # + # ==== Parameters + # callbacks:: A list of callbacks, with an optional + # options hash as the last parameter. + # block:: A proc that should be added to the callbacks. + # + # ==== Block Parameters + # name:: The callback to be added + # options:: A list of options to be used when adding the callback + def _insert_callbacks(callbacks, block) + options = callbacks.last.is_a?(Hash) ? callbacks.pop : {} + _normalize_callback_options(options) + callbacks.push(block) if block + callbacks.each do |callback| + yield callback, options + end + end + + # set up before_filter, prepend_before_filter, skip_before_filter, etc. + # for each of before, after, and around. + [:before, :after, :around].each do |filter| + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 + # Append a before, after or around filter. See _insert_callbacks + # for details on the allowed parameters. + def #{filter}_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| + set_callback(:process_action, :#{filter}, name, options) + end + end + + # Prepend a before, after or around filter. See _insert_callbacks + # for details on the allowed parameters. + def prepend_#{filter}_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| + set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) + end + end + + # Skip a before, after or around filter. See _insert_callbacks + # for details on the allowed parameters. + def skip_#{filter}_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| + skip_callback(:process_action, :#{filter}, name, options) + end + end + + # *_filter is the same as append_*_filter + alias_method :append_#{filter}_filter, :#{filter}_filter + RUBY_EVAL + end + end + end +end diff --git a/actionpack/lib/abstract_controller/exceptions.rb b/actionpack/lib/abstract_controller/exceptions.rb new file mode 100644 index 0000000000..b671516de1 --- /dev/null +++ b/actionpack/lib/abstract_controller/exceptions.rb @@ -0,0 +1,12 @@ +module AbstractController + class Error < StandardError; end + class ActionNotFound < StandardError; end + + class DoubleRenderError < Error + DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"." + + def initialize(message = nil) + super(message || DEFAULT_MESSAGE) + end + end +end diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb new file mode 100644 index 0000000000..5efa37fde3 --- /dev/null +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -0,0 +1,82 @@ +module AbstractController + module Helpers + extend ActiveSupport::Concern + + include Renderer + + included do + extlib_inheritable_accessor(:_helpers) { Module.new } + end + + module ClassMethods + # When a class is inherited, wrap its helper module in a new module. + # This ensures that the parent class's module can be changed + # independently of the child class's. + def inherited(klass) + helpers = _helpers + klass._helpers = Module.new { include helpers } + + super + end + + # Declare a controller method as a helper. For example, the following + # makes the +current_user+ controller method available to the view: + # class ApplicationController < ActionController::Base + # helper_method :current_user, :logged_in? + # + # def current_user + # @current_user ||= User.find_by_id(session[:user]) + # end + # + # def logged_in? + # current_user != nil + # end + # end + # + # In a view: + # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%> + # + # ==== Parameters + # meths:: The name of a method on the controller + # to be made available on the view. + def helper_method(*meths) + meths.flatten.each do |meth| + _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 + def #{meth}(*args, &blk) + controller.send(%(#{meth}), *args, &blk) + end + ruby_eval + end + end + + # Make a number of helper modules part of this class' default + # helpers. + # + # ==== Parameters + # *args:: Modules to be included + # block:: Evalulate the block in the context + # of the helper module. Any methods defined in the block + # will be helpers. + def helper(*args, &block) + args.flatten.each do |arg| + case arg + when Module + add_template_helper(arg) + end + end + _helpers.module_eval(&block) if block_given? + end + + private + # Makes all the (instance) methods in the helper module available to templates + # rendered through this controller. + # + # ==== Parameters + # mod:: The module to include into the current helper module + # for the class + def add_template_helper(mod) + _helpers.module_eval { include mod } + end + end + end +end diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb new file mode 100644 index 0000000000..f021dd8b62 --- /dev/null +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -0,0 +1,164 @@ +module AbstractController + module Layouts + extend ActiveSupport::Concern + + include Renderer + + included do + extlib_inheritable_accessor(:_layout_conditions) { Hash.new } + _write_layout_method + end + + module ClassMethods + def inherited(klass) + super + klass._write_layout_method + end + + # Specify the layout to use for this class. + # + # If the specified layout is a: + # String:: the String is the template name + # Symbol:: call the method specified by the symbol, which will return + # the template name + # false:: There is no layout + # true:: raise an ArgumentError + # + # ==== Parameters + # layout:: The layout to use. + # + # ==== Options (conditions) + # :only<#to_s, Array[#to_s]>:: A list of actions to apply this layout to. + # :except<#to_s, Array[#to_s]>:: Apply this layout to all actions but this one + def layout(layout, conditions = {}) + conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} } + self._layout_conditions = conditions + + @_layout = layout || false # Converts nil to false + _write_layout_method + end + + # If no layout is supplied, look for a template named the return + # value of this method. + # + # ==== Returns + # String:: A template name + def _implied_layout_name + name.underscore + end + + # Takes the specified layout and creates a _layout method to be called + # by _default_layout + # + # If there is no explicit layout specified: + # If a layout is found in the view paths with the controller's + # name, return that string. Otherwise, use the superclass' + # layout (which might also be implied) + def _write_layout_method + case @_layout + when String + self.class_eval %{def _layout(details) #{@_layout.inspect} end} + when Symbol + self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 + def _layout(details) + #{@_layout}.tap do |layout| + unless layout.is_a?(String) || !layout + raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ + "should have returned a String, false, or nil" + end + end + end + ruby_eval + when false + self.class_eval %{def _layout(details) end} + when true + raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" + when nil + self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 + def _layout(details) + if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts") + "#{_implied_layout_name}" + else + super + end + end + ruby_eval + end + self.class_eval { private :_layout } + end + end + + private + # This will be overwritten by _write_layout_method + def _layout(details) end + + # Determine the layout for a given name and details. + # + # ==== Parameters + # name:: The name of the template + # details Object}>:: A list of details to restrict + # the lookup to. By default, layout lookup is limited to the + # formats specified for the current request. + def _layout_for_name(name, details = {:formats => formats}) + name && _find_layout(name, details) + end + + # Take in the name and details and find a Template. + # + # ==== Parameters + # name:: The name of the template to retrieve + # details:: A list of details to restrict the search by. This + # might include details like the format or locale of the template. + # + # ==== Returns + # Template:: A template object matching the name and details + def _find_layout(name, details) + # TODO: Make prefix actually part of details in ViewPath#find_by_parts + prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts" + view_paths.find_by_parts(name, details, prefix) + end + + # Returns the default layout for this controller and a given set of details. + # Optionally raises an exception if the layout could not be found. + # + # ==== Parameters + # details:: A list of details to restrict the search by. This + # might include details like the format or locale of the template. + # require_layout:: If this is true, raise an ArgumentError + # with details about the fact that the exception could not be + # found (defaults to false) + # + # ==== Returns + # Template:: The template object for the default layout (or nil) + def _default_layout(details, require_layout = false) + if require_layout && _action_has_layout? && !_layout(details) + raise ArgumentError, + "There was no default layout for #{self.class} in #{view_paths.inspect}" + end + + begin + _layout_for_name(_layout(details), details) if _action_has_layout? + rescue NameError => e + raise NoMethodError, + "You specified #{@_layout.inspect} as the layout, but no such method was found" + end + end + + # Determines whether the current action has a layout by checking the + # action name against the :only and :except conditions set on the + # layout. + # + # ==== Returns + # Boolean:: True if the action has a layout, false otherwise. + def _action_has_layout? + conditions = _layout_conditions + if only = conditions[:only] + only.include?(action_name) + elsif except = conditions[:except] + !except.include?(action_name) + else + true + end + end + end +end diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb new file mode 100644 index 0000000000..fd33bd2ddd --- /dev/null +++ b/actionpack/lib/abstract_controller/logger.rb @@ -0,0 +1,52 @@ +require 'active_support/core_ext/logger' + +module AbstractController + module Logger + extend ActiveSupport::Concern + + # A class that allows you to defer expensive processing + # until the logger actually tries to log. Otherwise, you are + # forced to do the processing in advance, and send the + # entire processed String to the logger, which might + # just discard the String if the log level is too low. + # + # TODO: Require that Rails loggers accept a block. + class DelayedLog + def initialize(&blk) + @blk = blk + end + + def to_s + @blk.call + end + alias to_str to_s + end + + included do + cattr_accessor :logger + end + + # Override process_action in the AbstractController::Base + # to log details about the method. + def process_action(action) + super + + if logger + log = DelayedLog.new do + "\n\nProcessing #{self.class.name}\##{action_name} " \ + "to #{request.formats} " \ + "(for #{request_origin}) [#{request.method.to_s.upcase}]" + end + + logger.info(log) + end + end + + private + def request_origin + # this *needs* to be cached! + # otherwise you'd get different results if calling it more than once + @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" + end + end +end diff --git a/actionpack/lib/abstract_controller/renderer.rb b/actionpack/lib/abstract_controller/renderer.rb new file mode 100644 index 0000000000..4e368a099a --- /dev/null +++ b/actionpack/lib/abstract_controller/renderer.rb @@ -0,0 +1,156 @@ +require "abstract_controller/logger" + +module AbstractController + module Renderer + extend ActiveSupport::Concern + + include AbstractController::Logger + + included do + attr_internal :formats + + extlib_inheritable_accessor :_view_paths + + self._view_paths ||= ActionView::PathSet.new + end + + # An instance of a view class. The default view class is ActionView::Base + # + # The view class must have the following methods: + # View.for_controller[controller] Create a new ActionView instance for a + # controller + # View#render_partial[options] + # - responsible for setting options[:_template] + # - Returns String with the rendered partial + # options:: see _render_partial in ActionView::Base + # View#render_template[template, layout, options, partial] + # - Returns String with the rendered template + # template:: The template to render + # layout:: The layout to render around the template + # options:: See _render_template_with_layout in ActionView::Base + # partial:: Whether or not the template to render is a partial + # + # Override this method in a to change the default behavior. + def view_context + @_view_context ||= ActionView::Base.for_controller(self) + end + + # Mostly abstracts the fact that calling render twice is a DoubleRenderError. + # Delegates render_to_body and sticks the result in self.response_body. + def render(*args) + if response_body + raise AbstractController::DoubleRenderError, "OMG" + end + + self.response_body = render_to_body(*args) + end + + # Raw rendering of a template to a Rack-compatible body. + # + # ==== Options + # _partial_object:: The object that is being rendered. If this + # exists, we are in the special case of rendering an object as a partial. + # + # :api: plugin + def render_to_body(options = {}) + # TODO: Refactor so we can just use the normal template logic for this + if options[:_partial_object] + view_context.render_partial(options) + else + _determine_template(options) + _render_template(options) + end + end + + # Raw rendering of a template to a string. Just convert the results of + # render_to_body into a String. + # + # :api: plugin + def render_to_string(options = {}) + AbstractController::Renderer.body_to_s(render_to_body(options)) + end + + # Renders the template from an object. + # + # ==== Options + # _template:: The template to render + # _layout:: The layout to wrap the template in (optional) + # _partial:: Whether or not the template to be rendered is a partial + def _render_template(options) + view_context.render_template(options[:_template], options[:_layout], options, options[:_partial]) + end + + # The list of view paths for this controller. See ActionView::ViewPathSet for + # more details about writing custom view paths. + def view_paths + _view_paths + end + + # Return a string representation of a Rack-compatible response body. + def self.body_to_s(body) + if body.respond_to?(:to_str) + body + else + strings = [] + body.each { |part| strings << part.to_s } + body.close if body.respond_to?(:close) + strings.join + end + end + + private + # Take in a set of options and determine the template to render + # + # ==== Options + # _template:: If this is provided, the search is over + # _template_name<#to_s>:: The name of the template to look up. Otherwise, + # use the current action name. + # _prefix:: The prefix to look inside of. In a file system, this corresponds + # to a directory. + # _partial:: Whether or not the file to look up is a partial + def _determine_template(options) + name = (options[:_template_name] || action_name).to_s + + options[:_template] ||= view_paths.find_by_parts( + name, { :formats => formats }, options[:_prefix], options[:_partial] + ) + end + + module ClassMethods + # Append a path to the list of view paths for this controller. + # + # ==== Parameters + # path:: If a String is provided, it gets converted into + # the default view path. You may also provide a custom view path + # (see ActionView::ViewPathSet for more information) + def append_view_path(path) + self.view_paths << path + end + + # Prepend a path to the list of view paths for this controller. + # + # ==== Parameters + # path:: If a String is provided, it gets converted into + # the default view path. You may also provide a custom view path + # (see ActionView::ViewPathSet for more information) + def prepend_view_path(path) + self.view_paths.unshift(path) + end + + # A list of all of the default view paths for this controller. + def view_paths + self._view_paths + end + + # Set the view paths. + # + # ==== Parameters + # paths:: If a ViewPathSet is provided, use that; + # otherwise, process the parameter into a ViewPathSet. + def view_paths=(paths) + self._view_paths = paths.is_a?(ActionView::PathSet) ? + paths : ActionView::Base.process_view_paths(paths) + end + end + end +end diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 2b2c7ef725..22c2c4f499 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -56,7 +56,7 @@ module ActionController end autoload :HTML, 'action_controller/vendor/html-scanner' -autoload :AbstractController, 'action_controller/abstract' +autoload :AbstractController, 'abstract_controller' autoload :Rack, 'action_dispatch' autoload :ActionDispatch, 'action_dispatch' diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb deleted file mode 100644 index d0eba253b8..0000000000 --- a/actionpack/lib/action_controller/abstract.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "active_support/core_ext/module/attr_internal" -require "active_support/core_ext/module/delegation" - -module AbstractController - autoload :Base, "action_controller/abstract/base" - autoload :Benchmarker, "action_controller/abstract/benchmarker" - autoload :Callbacks, "action_controller/abstract/callbacks" - autoload :Helpers, "action_controller/abstract/helpers" - autoload :Layouts, "action_controller/abstract/layouts" - autoload :Logger, "action_controller/abstract/logger" - autoload :Renderer, "action_controller/abstract/renderer" - # === Exceptions - autoload :ActionNotFound, "action_controller/abstract/exceptions" - autoload :DoubleRenderError, "action_controller/abstract/exceptions" - autoload :Error, "action_controller/abstract/exceptions" -end diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb deleted file mode 100644 index b93e6ce634..0000000000 --- a/actionpack/lib/action_controller/abstract/base.rb +++ /dev/null @@ -1,159 +0,0 @@ -module AbstractController - - class Base - attr_internal :response_body - attr_internal :action_name - - class << self - attr_reader :abstract - alias_method :abstract?, :abstract - - # Define a controller as abstract. See internal_methods for more - # details. - def abstract! - @abstract = true - end - - def inherited(klass) - ::AbstractController::Base.descendants << klass.to_s - super - end - - # A list of all descendents of AbstractController::Base. This is - # useful for initializers which need to add behavior to all controllers. - def descendants - @descendants ||= [] - end - - # A list of all internal methods for a controller. This finds the first - # abstract superclass of a controller, and gets a list of all public - # instance methods on that abstract class. Public instance methods of - # a controller would normally be considered action methods, so we - # are removing those methods on classes declared as abstract - # (ActionController::Metal and ActionController::Base are defined - # as abstract) - def internal_methods - controller = self - controller = controller.superclass until controller.abstract? - controller.public_instance_methods(true) - end - - # The list of hidden actions to an empty Array. Defaults to an - # empty Array. This can be modified by other modules or subclasses - # to specify particular actions as hidden. - # - # ==== Returns - # Array[String]:: An array of method names that should not be - # considered actions. - def hidden_actions - [] - end - - # A list of method names that should be considered actions. This - # includes all public instance methods on a controller, less - # any internal methods (see #internal_methods), adding back in - # any methods that are internal, but still exist on the class - # itself. Finally, #hidden_actions are removed. - # - # ==== Returns - # Array[String]:: A list of all methods that should be considered - # actions. - def action_methods - @action_methods ||= - # All public instance methods of this class, including ancestors - public_instance_methods(true).map { |m| m.to_s }.to_set - - # Except for public instance methods of Base and its ancestors - internal_methods.map { |m| m.to_s } + - # Be sure to include shadowed public instance methods of this class - public_instance_methods(false).map { |m| m.to_s } - - # And always exclude explicitly hidden actions - hidden_actions - end - end - - abstract! - - # Calls the action going through the entire action dispatch stack. - # - # The actual method that is called is determined by calling - # #method_for_action. If no method can handle the action, then an - # ActionNotFound error is raised. - # - # ==== Returns - # self - def process(action) - @_action_name = action_name = action.to_s - - unless action_name = method_for_action(action_name) - raise ActionNotFound, "The action '#{action}' could not be found" - end - - process_action(action_name) - self - end - - private - # Returns true if the name can be considered an action. This can - # be overridden in subclasses to modify the semantics of what - # can be considered an action. - # - # ==== Parameters - # name:: The name of an action to be tested - # - # ==== Returns - # TrueClass, FalseClass - def action_method?(name) - self.class.action_methods.include?(name) - end - - # Call the action. Override this in a subclass to modify the - # behavior around processing an action. This, and not #process, - # is the intended way to override action dispatching. - def process_action(method_name) - send_action(method_name) - end - - # Actually call the method associated with the action. Override - # this method if you wish to change how action methods are called, - # not to add additional behavior around it. For example, you would - # override #send_action if you want to inject arguments into the - # method. - alias send_action send - - # If the action name was not found, but a method called "action_missing" - # was found, #method_for_action will return "_handle_action_missing". - # This method calls #action_missing with the current action name. - def _handle_action_missing - action_missing(@_action_name) - end - - # Takes an action name and returns the name of the method that will - # handle the action. In normal cases, this method returns the same - # name as it receives. By default, if #method_for_action receives - # a name that is not an action, it will look for an #action_missing - # method and return "_handle_action_missing" if one is found. - # - # Subclasses may override this method to add additional conditions - # that should be considered an action. For instance, an HTTP controller - # with a template matching the action name is considered to exist. - # - # If you override this method to handle additional cases, you may - # also provide a method (like _handle_method_missing) to handle - # the case. - # - # If none of these conditions are true, and method_for_action - # returns nil, an ActionNotFound exception will be raised. - # - # ==== Parameters - # action_name:: An action name to find a method name for - # - # ==== Returns - # String:: The name of the method that handles the action - # nil:: No method name could be found. Raise ActionNotFound. - def method_for_action(action_name) - if action_method?(action_name) then action_name - elsif respond_to?(:action_missing, true) then "_handle_action_missing" - end - end - end -end diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb deleted file mode 100644 index 58e9564c2f..0000000000 --- a/actionpack/lib/action_controller/abstract/benchmarker.rb +++ /dev/null @@ -1,38 +0,0 @@ -module AbstractController - module Benchmarker - extend ActiveSupport::Concern - - include Logger - - module ClassMethods - # Execute the passed in block, timing the duration of the block in ms. - # - # ==== Parameters - # title<#to_s>:: The title of block to benchmark - # log_level:: A valid log level. Defaults to Logger::DEBUG - # use_silence:: Whether or not to silence the - # logger for the duration of the block. - # - # ==== Returns - # Object:: The result of the block - def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) - if logger && logger.level >= log_level - result = nil - ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } - logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") - result - else - yield - end - end - - # Silences the logger for the duration of the block. - def silence - old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger - yield - ensure - logger.level = old_logger_level if logger - end - end - end -end diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb deleted file mode 100644 index ea4b59466e..0000000000 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ /dev/null @@ -1,115 +0,0 @@ -require "active_support/new_callbacks" - -module AbstractController - module Callbacks - extend ActiveSupport::Concern - - # Uses ActiveSupport::NewCallbacks as the base functionality. For - # more details on the whole callback system, read the documentation - # for ActiveSupport::NewCallbacks. - include ActiveSupport::NewCallbacks - - included do - define_callbacks :process_action, "response_body" - end - - # Override AbstractController::Base's process_action to run the - # process_action callbacks around the normal behavior. - def process_action(method_name) - _run_process_action_callbacks(method_name) do - super - end - end - - module ClassMethods - # If :only or :accept are used, convert the options into the - # primitive form (:per_key) used by ActiveSupport::Callbacks. - # The basic idea is that :only => :index gets converted to - # :if => proc {|c| c.action_name == "index" }, but that the - # proc is only evaluated once per action for the lifetime of - # a Rails process. - # - # ==== Options - # :only<#to_s>:: The callback should be run only for this action - # :except<#to_s>:: The callback should be run for all actions - # except this action - def _normalize_callback_options(options) - if only = options[:only] - only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ") - options[:per_key] = {:if => only} - end - if except = options[:except] - except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") - options[:per_key] = {:unless => except} - end - end - - # Skip before, after, and around filters matching any of the names - # - # ==== Parameters - # *names:: A list of valid names that could be used for - # callbacks. Note that skipping uses Ruby equality, so it's - # impossible to skip a callback defined using an anonymous proc - # using #skip_filter - def skip_filter(*names, &blk) - skip_before_filter(*names) - skip_after_filter(*names) - skip_around_filter(*names) - end - - # Take callback names and an optional callback proc, normalize them, - # then call the block with each callback. This allows us to abstract - # the normalization across several methods that use it. - # - # ==== Parameters - # callbacks:: A list of callbacks, with an optional - # options hash as the last parameter. - # block:: A proc that should be added to the callbacks. - # - # ==== Block Parameters - # name:: The callback to be added - # options:: A list of options to be used when adding the callback - def _insert_callbacks(callbacks, block) - options = callbacks.last.is_a?(Hash) ? callbacks.pop : {} - _normalize_callback_options(options) - callbacks.push(block) if block - callbacks.each do |callback| - yield callback, options - end - end - - # set up before_filter, prepend_before_filter, skip_before_filter, etc. - # for each of before, after, and around. - [:before, :after, :around].each do |filter| - class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 - # Append a before, after or around filter. See _insert_callbacks - # for details on the allowed parameters. - def #{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - set_callback(:process_action, :#{filter}, name, options) - end - end - - # Prepend a before, after or around filter. See _insert_callbacks - # for details on the allowed parameters. - def prepend_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) - end - end - - # Skip a before, after or around filter. See _insert_callbacks - # for details on the allowed parameters. - def skip_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - skip_callback(:process_action, :#{filter}, name, options) - end - end - - # *_filter is the same as append_*_filter - alias_method :append_#{filter}_filter, :#{filter}_filter - RUBY_EVAL - end - end - end -end diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/action_controller/abstract/exceptions.rb deleted file mode 100644 index b671516de1..0000000000 --- a/actionpack/lib/action_controller/abstract/exceptions.rb +++ /dev/null @@ -1,12 +0,0 @@ -module AbstractController - class Error < StandardError; end - class ActionNotFound < StandardError; end - - class DoubleRenderError < Error - DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"." - - def initialize(message = nil) - super(message || DEFAULT_MESSAGE) - end - end -end diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb deleted file mode 100644 index 5efa37fde3..0000000000 --- a/actionpack/lib/action_controller/abstract/helpers.rb +++ /dev/null @@ -1,82 +0,0 @@ -module AbstractController - module Helpers - extend ActiveSupport::Concern - - include Renderer - - included do - extlib_inheritable_accessor(:_helpers) { Module.new } - end - - module ClassMethods - # When a class is inherited, wrap its helper module in a new module. - # This ensures that the parent class's module can be changed - # independently of the child class's. - def inherited(klass) - helpers = _helpers - klass._helpers = Module.new { include helpers } - - super - end - - # Declare a controller method as a helper. For example, the following - # makes the +current_user+ controller method available to the view: - # class ApplicationController < ActionController::Base - # helper_method :current_user, :logged_in? - # - # def current_user - # @current_user ||= User.find_by_id(session[:user]) - # end - # - # def logged_in? - # current_user != nil - # end - # end - # - # In a view: - # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%> - # - # ==== Parameters - # meths:: The name of a method on the controller - # to be made available on the view. - def helper_method(*meths) - meths.flatten.each do |meth| - _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 - def #{meth}(*args, &blk) - controller.send(%(#{meth}), *args, &blk) - end - ruby_eval - end - end - - # Make a number of helper modules part of this class' default - # helpers. - # - # ==== Parameters - # *args:: Modules to be included - # block:: Evalulate the block in the context - # of the helper module. Any methods defined in the block - # will be helpers. - def helper(*args, &block) - args.flatten.each do |arg| - case arg - when Module - add_template_helper(arg) - end - end - _helpers.module_eval(&block) if block_given? - end - - private - # Makes all the (instance) methods in the helper module available to templates - # rendered through this controller. - # - # ==== Parameters - # mod:: The module to include into the current helper module - # for the class - def add_template_helper(mod) - _helpers.module_eval { include mod } - end - end - end -end diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb deleted file mode 100644 index f021dd8b62..0000000000 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ /dev/null @@ -1,164 +0,0 @@ -module AbstractController - module Layouts - extend ActiveSupport::Concern - - include Renderer - - included do - extlib_inheritable_accessor(:_layout_conditions) { Hash.new } - _write_layout_method - end - - module ClassMethods - def inherited(klass) - super - klass._write_layout_method - end - - # Specify the layout to use for this class. - # - # If the specified layout is a: - # String:: the String is the template name - # Symbol:: call the method specified by the symbol, which will return - # the template name - # false:: There is no layout - # true:: raise an ArgumentError - # - # ==== Parameters - # layout:: The layout to use. - # - # ==== Options (conditions) - # :only<#to_s, Array[#to_s]>:: A list of actions to apply this layout to. - # :except<#to_s, Array[#to_s]>:: Apply this layout to all actions but this one - def layout(layout, conditions = {}) - conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} } - self._layout_conditions = conditions - - @_layout = layout || false # Converts nil to false - _write_layout_method - end - - # If no layout is supplied, look for a template named the return - # value of this method. - # - # ==== Returns - # String:: A template name - def _implied_layout_name - name.underscore - end - - # Takes the specified layout and creates a _layout method to be called - # by _default_layout - # - # If there is no explicit layout specified: - # If a layout is found in the view paths with the controller's - # name, return that string. Otherwise, use the superclass' - # layout (which might also be implied) - def _write_layout_method - case @_layout - when String - self.class_eval %{def _layout(details) #{@_layout.inspect} end} - when Symbol - self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 - def _layout(details) - #{@_layout}.tap do |layout| - unless layout.is_a?(String) || !layout - raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \ - "should have returned a String, false, or nil" - end - end - end - ruby_eval - when false - self.class_eval %{def _layout(details) end} - when true - raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" - when nil - self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 - def _layout(details) - if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts") - "#{_implied_layout_name}" - else - super - end - end - ruby_eval - end - self.class_eval { private :_layout } - end - end - - private - # This will be overwritten by _write_layout_method - def _layout(details) end - - # Determine the layout for a given name and details. - # - # ==== Parameters - # name:: The name of the template - # details Object}>:: A list of details to restrict - # the lookup to. By default, layout lookup is limited to the - # formats specified for the current request. - def _layout_for_name(name, details = {:formats => formats}) - name && _find_layout(name, details) - end - - # Take in the name and details and find a Template. - # - # ==== Parameters - # name:: The name of the template to retrieve - # details:: A list of details to restrict the search by. This - # might include details like the format or locale of the template. - # - # ==== Returns - # Template:: A template object matching the name and details - def _find_layout(name, details) - # TODO: Make prefix actually part of details in ViewPath#find_by_parts - prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts" - view_paths.find_by_parts(name, details, prefix) - end - - # Returns the default layout for this controller and a given set of details. - # Optionally raises an exception if the layout could not be found. - # - # ==== Parameters - # details:: A list of details to restrict the search by. This - # might include details like the format or locale of the template. - # require_layout:: If this is true, raise an ArgumentError - # with details about the fact that the exception could not be - # found (defaults to false) - # - # ==== Returns - # Template:: The template object for the default layout (or nil) - def _default_layout(details, require_layout = false) - if require_layout && _action_has_layout? && !_layout(details) - raise ArgumentError, - "There was no default layout for #{self.class} in #{view_paths.inspect}" - end - - begin - _layout_for_name(_layout(details), details) if _action_has_layout? - rescue NameError => e - raise NoMethodError, - "You specified #{@_layout.inspect} as the layout, but no such method was found" - end - end - - # Determines whether the current action has a layout by checking the - # action name against the :only and :except conditions set on the - # layout. - # - # ==== Returns - # Boolean:: True if the action has a layout, false otherwise. - def _action_has_layout? - conditions = _layout_conditions - if only = conditions[:only] - only.include?(action_name) - elsif except = conditions[:except] - !except.include?(action_name) - else - true - end - end - end -end diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb deleted file mode 100644 index fd33bd2ddd..0000000000 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'active_support/core_ext/logger' - -module AbstractController - module Logger - extend ActiveSupport::Concern - - # A class that allows you to defer expensive processing - # until the logger actually tries to log. Otherwise, you are - # forced to do the processing in advance, and send the - # entire processed String to the logger, which might - # just discard the String if the log level is too low. - # - # TODO: Require that Rails loggers accept a block. - class DelayedLog - def initialize(&blk) - @blk = blk - end - - def to_s - @blk.call - end - alias to_str to_s - end - - included do - cattr_accessor :logger - end - - # Override process_action in the AbstractController::Base - # to log details about the method. - def process_action(action) - super - - if logger - log = DelayedLog.new do - "\n\nProcessing #{self.class.name}\##{action_name} " \ - "to #{request.formats} " \ - "(for #{request_origin}) [#{request.method.to_s.upcase}]" - end - - logger.info(log) - end - end - - private - def request_origin - # this *needs* to be cached! - # otherwise you'd get different results if calling it more than once - @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" - end - end -end diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb deleted file mode 100644 index fe556281ab..0000000000 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ /dev/null @@ -1,156 +0,0 @@ -require "action_controller/abstract/logger" - -module AbstractController - module Renderer - extend ActiveSupport::Concern - - include AbstractController::Logger - - included do - attr_internal :formats - - extlib_inheritable_accessor :_view_paths - - self._view_paths ||= ActionView::PathSet.new - end - - # An instance of a view class. The default view class is ActionView::Base - # - # The view class must have the following methods: - # View.for_controller[controller] Create a new ActionView instance for a - # controller - # View#render_partial[options] - # - responsible for setting options[:_template] - # - Returns String with the rendered partial - # options:: see _render_partial in ActionView::Base - # View#render_template[template, layout, options, partial] - # - Returns String with the rendered template - # template:: The template to render - # layout:: The layout to render around the template - # options:: See _render_template_with_layout in ActionView::Base - # partial:: Whether or not the template to render is a partial - # - # Override this method in a to change the default behavior. - def view_context - @_view_context ||= ActionView::Base.for_controller(self) - end - - # Mostly abstracts the fact that calling render twice is a DoubleRenderError. - # Delegates render_to_body and sticks the result in self.response_body. - def render(*args) - if response_body - raise AbstractController::DoubleRenderError, "OMG" - end - - self.response_body = render_to_body(*args) - end - - # Raw rendering of a template to a Rack-compatible body. - # - # ==== Options - # _partial_object:: The object that is being rendered. If this - # exists, we are in the special case of rendering an object as a partial. - # - # :api: plugin - def render_to_body(options = {}) - # TODO: Refactor so we can just use the normal template logic for this - if options[:_partial_object] - view_context.render_partial(options) - else - _determine_template(options) - _render_template(options) - end - end - - # Raw rendering of a template to a string. Just convert the results of - # render_to_body into a String. - # - # :api: plugin - def render_to_string(options = {}) - AbstractController::Renderer.body_to_s(render_to_body(options)) - end - - # Renders the template from an object. - # - # ==== Options - # _template:: The template to render - # _layout:: The layout to wrap the template in (optional) - # _partial:: Whether or not the template to be rendered is a partial - def _render_template(options) - view_context.render_template(options[:_template], options[:_layout], options, options[:_partial]) - end - - # The list of view paths for this controller. See ActionView::ViewPathSet for - # more details about writing custom view paths. - def view_paths - _view_paths - end - - # Return a string representation of a Rack-compatible response body. - def self.body_to_s(body) - if body.respond_to?(:to_str) - body - else - strings = [] - body.each { |part| strings << part.to_s } - body.close if body.respond_to?(:close) - strings.join - end - end - - private - # Take in a set of options and determine the template to render - # - # ==== Options - # _template:: If this is provided, the search is over - # _template_name<#to_s>:: The name of the template to look up. Otherwise, - # use the current action name. - # _prefix:: The prefix to look inside of. In a file system, this corresponds - # to a directory. - # _partial:: Whether or not the file to look up is a partial - def _determine_template(options) - name = (options[:_template_name] || action_name).to_s - - options[:_template] ||= view_paths.find_by_parts( - name, { :formats => formats }, options[:_prefix], options[:_partial] - ) - end - - module ClassMethods - # Append a path to the list of view paths for this controller. - # - # ==== Parameters - # path:: If a String is provided, it gets converted into - # the default view path. You may also provide a custom view path - # (see ActionView::ViewPathSet for more information) - def append_view_path(path) - self.view_paths << path - end - - # Prepend a path to the list of view paths for this controller. - # - # ==== Parameters - # path:: If a String is provided, it gets converted into - # the default view path. You may also provide a custom view path - # (see ActionView::ViewPathSet for more information) - def prepend_view_path(path) - self.view_paths.unshift(path) - end - - # A list of all of the default view paths for this controller. - def view_paths - self._view_paths - end - - # Set the view paths. - # - # ==== Parameters - # paths:: If a ViewPathSet is provided, use that; - # otherwise, process the parameter into a ViewPathSet. - def view_paths=(paths) - self._view_paths = paths.is_a?(ActionView::PathSet) ? - paths : ActionView::Base.process_view_paths(paths) - end - end - end -end diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 82d05414b9..5333ca497c 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -1,5 +1,3 @@ -require 'action_controller/abstract' - module ActionController # ActionController::Metal provides a way to get a valid Rack application from a controller. # diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb index 915054f7fb..ba4302d914 100644 --- a/actionpack/test/abstract_controller/test_helper.rb +++ b/actionpack/test/abstract_controller/test_helper.rb @@ -6,7 +6,7 @@ require 'rubygems' require 'test/unit' require 'active_support' require 'active_support/test_case' -require 'action_controller/abstract' +require 'abstract_controller' require 'action_view' require 'action_view/base' require 'action_dispatch' diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 7f373ea7c5..b062a71442 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -13,7 +13,6 @@ require 'test/unit' require 'active_support' require 'active_support/test_case' -require 'action_controller/abstract' require 'action_controller' require 'fixture_template' require 'action_controller/testing/process' -- cgit v1.2.3