aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/new_base
diff options
context:
space:
mode:
authorlifo <lifo@null.lan>2009-04-17 14:06:26 +0100
committerlifo <lifo@null.lan>2009-04-17 14:06:26 +0100
commit20401783cf26f903d7020cb7136b1e78e60e71ea (patch)
tree5bb029802ade6dda33e051adf74915dc0a8d1fe5 /actionpack/lib/action_controller/new_base
parentf99e9f627b6e4ab7fe72bc759426312ec0c7a2cd (diff)
parentabb899c54e8777428b7a607774370ba29a5573bd (diff)
downloadrails-20401783cf26f903d7020cb7136b1e78e60e71ea.tar.gz
rails-20401783cf26f903d7020cb7136b1e78e60e71ea.tar.bz2
rails-20401783cf26f903d7020cb7136b1e78e60e71ea.zip
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_controller/base.rb railties/guides/source/caching_with_rails.textile
Diffstat (limited to 'actionpack/lib/action_controller/new_base')
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb61
-rw-r--r--actionpack/lib/action_controller/new_base/hide_actions.rb31
-rw-r--r--actionpack/lib/action_controller/new_base/layouts.rb37
-rw-r--r--actionpack/lib/action_controller/new_base/renderer.rb62
-rw-r--r--actionpack/lib/action_controller/new_base/url_for.rb40
5 files changed, 231 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
new file mode 100644
index 0000000000..0400ddbf7a
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -0,0 +1,61 @@
+module ActionController
+ class AbstractBase < AbstractController::Base
+
+ # :api: public
+ attr_internal :request, :response, :params
+
+ # :api: public
+ def self.controller_name
+ @controller_name ||= controller_path.split("/").last
+ end
+
+ # :api: public
+ def controller_name() self.class.controller_name end
+
+ # :api: public
+ def self.controller_path
+ @controller_path ||= self.name.sub(/Controller$/, '').underscore
+ end
+
+ # :api: public
+ def controller_path() self.class.controller_path end
+
+ # :api: private
+ def self.action_methods
+ @action_names ||= Set.new(self.public_instance_methods - self::CORE_METHODS)
+ end
+
+ # :api: private
+ def self.action_names() action_methods end
+
+ # :api: private
+ def action_methods() self.class.action_names end
+
+ # :api: private
+ def action_names() action_methods end
+
+ # :api: plugin
+ def self.call(env)
+ controller = new
+ controller.call(env).to_rack
+ end
+
+ # :api: plugin
+ def response_body=(body)
+ @_response["Content-Length"] = body.length
+ @_response.body = body
+ end
+
+ # :api: private
+ def call(env)
+ @_request = ActionDispatch::Request.new(env)
+ @_response = ActionDispatch::Response.new
+ process(@_request.parameters[:action])
+ end
+
+ # :api: private
+ def to_rack
+ response.to_a
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb
new file mode 100644
index 0000000000..473a8ea72b
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/hide_actions.rb
@@ -0,0 +1,31 @@
+module ActionController
+ module HideActions
+ setup do
+ extlib_inheritable_accessor :hidden_actions
+ self.hidden_actions ||= Set.new
+ end
+
+ def action_methods() self.class.action_names end
+ def action_names() action_methods end
+
+ private
+
+ def respond_to_action?(action_name)
+ !hidden_actions.include?(action_name) && (super || respond_to?(:method_missing))
+ end
+
+ module ClassMethods
+ def hide_action(*args)
+ args.each do |arg|
+ self.hidden_actions << arg.to_s
+ end
+ end
+
+ def action_methods
+ @action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)})
+ end
+
+ def self.action_names() action_methods end
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb
new file mode 100644
index 0000000000..149847c968
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/layouts.rb
@@ -0,0 +1,37 @@
+module ActionController
+ module Layouts
+ depends_on ActionController::Renderer
+ depends_on AbstractController::Layouts
+
+ module ClassMethods
+ def _implied_layout_name
+ controller_path
+ end
+ end
+
+ def render_to_string(options)
+ # render :text => ..., :layout => ...
+ # or
+ # render :anything_else
+ if !options.key?(:text) || options.key?(:layout)
+ options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
+ end
+
+ super
+ end
+
+ private
+
+ def _layout_for_option(name)
+ case name
+ when String then _layout_for_name(name)
+ when true then _default_layout(true)
+ when false, nil then nil
+ else
+ raise ArgumentError,
+ "String, true, or false, expected for `layout'; you passed #{name.inspect}"
+ end
+ end
+
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb
new file mode 100644
index 0000000000..044c15f409
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/renderer.rb
@@ -0,0 +1,62 @@
+module ActionController
+ module Renderer
+ depends_on AbstractController::Renderer
+
+ def initialize(*)
+ self.formats = [:html]
+ super
+ end
+
+ def render(action, options = {})
+ # TODO: Move this into #render_to_string
+ if action.is_a?(Hash)
+ options, action = action, nil
+ else
+ options.merge! :action => action
+ end
+
+ _process_options(options)
+
+ self.response_body = render_to_string(options)
+ end
+
+ def render_to_string(options)
+ unless options.is_a?(Hash)
+ options = {:action => options}
+ end
+
+ if options.key?(:text)
+ options[:_template] = ActionView::TextTemplate.new(_text(options))
+ template = nil
+ elsif options.key?(:template)
+ options[:_template_name] = options[:template]
+ elsif options.key?(:action)
+ options[:_template_name] = options[:action].to_s
+ options[:_prefix] = _prefix
+ end
+
+ super(options)
+ end
+
+ private
+
+ def _prefix
+ controller_path
+ end
+
+ def _text(options)
+ text = options[:text]
+
+ case text
+ when nil then " "
+ else text.to_s
+ end
+ end
+
+ def _process_options(options)
+ if status = options[:status]
+ response.status = status.to_i
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb
new file mode 100644
index 0000000000..af5b21012b
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/url_for.rb
@@ -0,0 +1,40 @@
+module ActionController
+ module UrlFor
+ def initialize_current_url
+ @url = UrlRewriter.new(request, params.clone)
+ end
+
+ # Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in
+ # the form of a hash, just like the one you would use for url_for directly. Example:
+ #
+ # def default_url_options(options)
+ # { :project => @project.active? ? @project.url_name : "unknown" }
+ # end
+ #
+ # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
+ # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
+ # by this method.
+ def default_url_options(options = nil)
+ end
+
+ def rewrite_options(options) #:nodoc:
+ if defaults = default_url_options(options)
+ defaults.merge(options)
+ else
+ options
+ end
+ end
+
+ def url_for(options = {})
+ options ||= {}
+ case options
+ when String
+ options
+ when Hash
+ @url.rewrite(rewrite_options(options))
+ else
+ polymorphic_url(options)
+ end
+ end
+ end
+end \ No newline at end of file