Rails 2.2.2
Updated to Rails 2.2.2. Added a couple more Ruby 1.9 fixes, but that's pretty much at a standstill, until one gets Maruku and HTML5lib working right under Ruby 1.9.
This commit is contained in:
parent
1b69b148de
commit
2e81ca2d30
716 changed files with 8009 additions and 113047 deletions
80
vendor/rails/actionpack/lib/action_controller/base.rb
vendored
Executable file → Normal file
80
vendor/rails/actionpack/lib/action_controller/base.rb
vendored
Executable file → Normal file
|
@ -278,12 +278,6 @@ module ActionController #:nodoc:
|
|||
@@consider_all_requests_local = true
|
||||
cattr_accessor :consider_all_requests_local
|
||||
|
||||
# Enable or disable the collection of failure information for RoutingErrors.
|
||||
# This information can be extremely useful when tweaking custom routes, but is
|
||||
# pointless once routes have been tested and verified.
|
||||
@@debug_routes = true
|
||||
cattr_accessor :debug_routes
|
||||
|
||||
# Indicates whether to allow concurrent action processing. Your
|
||||
# controller actions and any other code they call must also behave well
|
||||
# when called from concurrent threads. Turned off by default.
|
||||
|
@ -364,11 +358,8 @@ module ActionController #:nodoc:
|
|||
# If you are deploying to a subdirectory, you will need to set
|
||||
# <tt>config.action_controller.relative_url_root</tt>
|
||||
# This defaults to ENV['RAILS_RELATIVE_URL_ROOT']
|
||||
cattr_writer :relative_url_root
|
||||
|
||||
def self.relative_url_root
|
||||
@@relative_url_root || ENV['RAILS_RELATIVE_URL_ROOT']
|
||||
end
|
||||
cattr_accessor :relative_url_root
|
||||
self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
|
||||
|
||||
# Holds the request object that's primarily used to get environment variables through access like
|
||||
# <tt>request.env["REQUEST_URI"]</tt>.
|
||||
|
@ -801,6 +792,19 @@ module ActionController #:nodoc:
|
|||
# # Renders "Hello from code!"
|
||||
# render :text => proc { |response, output| output.write("Hello from code!") }
|
||||
#
|
||||
# === Rendering XML
|
||||
#
|
||||
# Rendering XML sets the content type to application/xml.
|
||||
#
|
||||
# # Renders '<name>David</name>'
|
||||
# render :xml => {:name => "David"}.to_xml
|
||||
#
|
||||
# It's not necessary to call <tt>to_xml</tt> on the object you want to render, since <tt>render</tt> will
|
||||
# automatically do that for you:
|
||||
#
|
||||
# # Also renders '<name>David</name>'
|
||||
# render :xml => {:name => "David"}
|
||||
#
|
||||
# === Rendering JSON
|
||||
#
|
||||
# Rendering JSON sets the content type to application/json and optionally wraps the JSON in a callback. It is expected
|
||||
|
@ -846,8 +850,14 @@ module ActionController #:nodoc:
|
|||
# page.visual_effect :highlight, 'user_list'
|
||||
# end
|
||||
#
|
||||
# === Rendering with status and location headers
|
||||
# === Rendering vanilla JavaScript
|
||||
#
|
||||
# In addition to using RJS with render :update, you can also just render vanilla JavaScript with :js.
|
||||
#
|
||||
# # Renders "alert('hello')" and sets the mime type to text/javascript
|
||||
# render :js => "alert('hello')"
|
||||
#
|
||||
# === Rendering with status and location headers
|
||||
# All renders take the <tt>:status</tt> and <tt>:location</tt> options and turn them into headers. They can even be used together:
|
||||
#
|
||||
# render :xml => post.to_xml, :status => :created, :location => post_url(post)
|
||||
|
@ -898,6 +908,10 @@ module ActionController #:nodoc:
|
|||
response.content_type ||= Mime::XML
|
||||
render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status])
|
||||
|
||||
elsif js = options[:js]
|
||||
response.content_type ||= Mime::JS
|
||||
render_for_text(js, options[:status])
|
||||
|
||||
elsif json = options[:json]
|
||||
json = json.to_json unless json.is_a?(String)
|
||||
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
|
||||
|
@ -933,6 +947,7 @@ module ActionController #:nodoc:
|
|||
def render_to_string(options = nil, &block) #:doc:
|
||||
render(options, &block)
|
||||
ensure
|
||||
response.content_type = nil
|
||||
erase_render_results
|
||||
reset_variables_added_to_assigns
|
||||
end
|
||||
|
@ -1014,10 +1029,10 @@ module ActionController #:nodoc:
|
|||
#
|
||||
# * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
|
||||
# * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
|
||||
# * <tt>String starting with protocol:// (like http://)</tt> - Is passed straight through as the target for redirection.
|
||||
# * <tt>String not containing a protocol</tt> - The current protocol and host is prepended to the string.
|
||||
# * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) - Is passed straight through as the target for redirection.
|
||||
# * <tt>String</tt> not containing a protocol - The current protocol and host is prepended to the string.
|
||||
# * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
|
||||
# Short-hand for redirect_to(request.env["HTTP_REFERER"])
|
||||
# Short-hand for <tt>redirect_to(request.env["HTTP_REFERER"])</tt>
|
||||
#
|
||||
# Examples:
|
||||
# redirect_to :action => "show", :id => 5
|
||||
|
@ -1049,11 +1064,14 @@ module ActionController #:nodoc:
|
|||
status = 302
|
||||
end
|
||||
|
||||
response.redirected_to= options
|
||||
response.redirected_to = options
|
||||
logger.info("Redirected to #{options}") if logger && logger.info?
|
||||
|
||||
case options
|
||||
when %r{^\w+://.*}
|
||||
# The scheme name consist of a letter followed by any combination of
|
||||
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
|
||||
# characters; and is terminated by a colon (":").
|
||||
when %r{^\w[\w\d+.-]*:.*}
|
||||
redirect_to_full_url(options, status)
|
||||
when String
|
||||
redirect_to_full_url(request.protocol + request.host_with_port + options, status)
|
||||
|
@ -1198,11 +1216,33 @@ module ActionController #:nodoc:
|
|||
|
||||
def log_processing
|
||||
if logger && logger.info?
|
||||
logger.info "\n\nProcessing #{self.class.name}\##{action_name} (for #{request_origin}) [#{request.method.to_s.upcase}]"
|
||||
logger.info " Session ID: #{@_session.session_id}" if @_session and @_session.respond_to?(:session_id)
|
||||
logger.info " Parameters: #{respond_to?(:filter_parameters) ? filter_parameters(params).inspect : params.inspect}"
|
||||
log_processing_for_request_id
|
||||
log_processing_for_session_id
|
||||
log_processing_for_parameters
|
||||
end
|
||||
end
|
||||
|
||||
def log_processing_for_request_id
|
||||
request_id = "\n\nProcessing #{self.class.name}\##{action_name} "
|
||||
request_id << "to #{params[:format]} " if params[:format]
|
||||
request_id << "(for #{request_origin}) [#{request.method.to_s.upcase}]"
|
||||
|
||||
logger.info(request_id)
|
||||
end
|
||||
|
||||
def log_processing_for_session_id
|
||||
if @_session && @_session.respond_to?(:session_id) && @_session.respond_to?(:dbman) &&
|
||||
!@_session.dbman.is_a?(CGI::Session::CookieStore)
|
||||
logger.info " Session ID: #{@_session.session_id}"
|
||||
end
|
||||
end
|
||||
|
||||
def log_processing_for_parameters
|
||||
parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params.dup
|
||||
parameters = parameters.except!(:controller, :action, :format, :_method)
|
||||
|
||||
logger.info " Parameters: #{parameters.inspect}" unless parameters.empty?
|
||||
end
|
||||
|
||||
def default_render #:nodoc:
|
||||
render
|
||||
|
|
|
@ -23,11 +23,14 @@ module ActionController
|
|||
|
||||
if defined?(ActiveRecord)
|
||||
after_dispatch :checkin_connections
|
||||
before_dispatch { ActiveRecord::Base.verify_active_connections! }
|
||||
to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
|
||||
end
|
||||
|
||||
after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush)
|
||||
|
||||
to_prepare do
|
||||
I18n.reload!
|
||||
end
|
||||
end
|
||||
|
||||
# Backward-compatible class method takes CGI-specific args. Deprecated
|
||||
|
|
|
@ -20,8 +20,20 @@ module Mime
|
|||
# end
|
||||
class Type
|
||||
@@html_types = Set.new [:html, :all]
|
||||
cattr_reader :html_types
|
||||
|
||||
# These are the content types which browsers can generate without using ajax, flash, etc
|
||||
# i.e. following a link, getting an image or posting a form. CSRF protection
|
||||
# only needs to protect against these types.
|
||||
@@browser_generated_types = Set.new [:html, :url_encoded_form, :multipart_form, :text]
|
||||
cattr_reader :browser_generated_types
|
||||
|
||||
|
||||
@@unverifiable_types = Set.new [:text, :json, :csv, :xml, :rss, :atom, :yaml]
|
||||
cattr_reader :html_types, :unverifiable_types
|
||||
def self.unverifiable_types
|
||||
ActiveSupport::Deprecation.warn("unverifiable_types is deprecated and has no effect", caller)
|
||||
@@unverifiable_types
|
||||
end
|
||||
|
||||
# A simple helper class used in parsing the accept header
|
||||
class AcceptItem #:nodoc:
|
||||
|
@ -165,15 +177,19 @@ module Mime
|
|||
end
|
||||
|
||||
# Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
|
||||
# ActionController::RequestForgerProtection.
|
||||
# ActionController::RequestForgeryProtection.
|
||||
def verify_request?
|
||||
!@@unverifiable_types.include?(to_sym)
|
||||
browser_generated?
|
||||
end
|
||||
|
||||
def html?
|
||||
@@html_types.include?(to_sym) || @string =~ /html/
|
||||
end
|
||||
|
||||
def browser_generated?
|
||||
@@browser_generated_types.include?(to_sym)
|
||||
end
|
||||
|
||||
private
|
||||
def method_missing(method, *args)
|
||||
if method.to_s =~ /(\w+)\?$/
|
||||
|
|
|
@ -73,7 +73,8 @@ module ActionController
|
|||
#
|
||||
def polymorphic_url(record_or_hash_or_array, options = {})
|
||||
if record_or_hash_or_array.kind_of?(Array)
|
||||
record_or_hash_or_array = record_or_hash_or_array.dup
|
||||
record_or_hash_or_array = record_or_hash_or_array.compact
|
||||
record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
|
||||
end
|
||||
|
||||
record = extract_record(record_or_hash_or_array)
|
||||
|
|
|
@ -9,10 +9,11 @@ module ActionController
|
|||
class AbstractRequest
|
||||
extend ActiveSupport::Memoizable
|
||||
|
||||
def self.relative_url_root=(*args)
|
||||
def self.relative_url_root=(relative_url_root)
|
||||
ActiveSupport::Deprecation.warn(
|
||||
"ActionController::AbstractRequest.relative_url_root= has been renamed." +
|
||||
"You can now set it with config.action_controller.relative_url_root=", caller)
|
||||
ActionController::Base.relative_url_root=relative_url_root
|
||||
end
|
||||
|
||||
HTTP_METHODS = %w(get head put post delete options)
|
||||
|
|
|
@ -99,7 +99,7 @@ module ActionController #:nodoc:
|
|||
end
|
||||
|
||||
def verifiable_request_format?
|
||||
request.content_type.nil? || request.content_type.verify_request?
|
||||
!request.content_type.nil? && request.content_type.verify_request?
|
||||
end
|
||||
|
||||
# Sets the token value for the current session. Pass a <tt>:secret</tt> option
|
||||
|
|
0
vendor/rails/actionpack/lib/action_controller/request_profiler.rb
vendored
Executable file → Normal file
0
vendor/rails/actionpack/lib/action_controller/request_profiler.rb
vendored
Executable file → Normal file
|
@ -42,7 +42,11 @@ module ActionController
|
|||
#
|
||||
# Read more about REST at http://en.wikipedia.org/wiki/Representational_State_Transfer
|
||||
module Resources
|
||||
INHERITABLE_OPTIONS = :namespace, :shallow, :actions
|
||||
|
||||
class Resource #:nodoc:
|
||||
DEFAULT_ACTIONS = :index, :create, :new, :edit, :show, :update, :destroy
|
||||
|
||||
attr_reader :collection_methods, :member_methods, :new_methods
|
||||
attr_reader :path_prefix, :name_prefix, :path_segment
|
||||
attr_reader :plural, :singular
|
||||
|
@ -57,6 +61,7 @@ module ActionController
|
|||
|
||||
arrange_actions
|
||||
add_default_actions
|
||||
set_allowed_actions
|
||||
set_prefixes
|
||||
end
|
||||
|
||||
|
@ -113,6 +118,10 @@ module ActionController
|
|||
@singular.to_s == @plural.to_s
|
||||
end
|
||||
|
||||
def has_action?(action)
|
||||
!DEFAULT_ACTIONS.include?(action) || @options[:actions].nil? || @options[:actions].include?(action)
|
||||
end
|
||||
|
||||
protected
|
||||
def arrange_actions
|
||||
@collection_methods = arrange_actions_by_methods(options.delete(:collection))
|
||||
|
@ -125,6 +134,25 @@ module ActionController
|
|||
add_default_action(new_methods, :get, :new)
|
||||
end
|
||||
|
||||
def set_allowed_actions
|
||||
only = @options.delete(:only)
|
||||
except = @options.delete(:except)
|
||||
|
||||
if only && except
|
||||
raise ArgumentError, 'Please supply either :only or :except, not both.'
|
||||
elsif only == :all || except == :none
|
||||
options[:actions] = DEFAULT_ACTIONS
|
||||
elsif only == :none || except == :all
|
||||
options[:actions] = []
|
||||
elsif only
|
||||
options[:actions] = DEFAULT_ACTIONS & Array(only).map(&:to_sym)
|
||||
elsif except
|
||||
options[:actions] = DEFAULT_ACTIONS - Array(except).map(&:to_sym)
|
||||
else
|
||||
# leave options[:actions] alone
|
||||
end
|
||||
end
|
||||
|
||||
def set_prefixes
|
||||
@path_prefix = options.delete(:path_prefix)
|
||||
@name_prefix = options.delete(:name_prefix)
|
||||
|
@ -353,6 +381,25 @@ module ActionController
|
|||
#
|
||||
# map.resources :users, :has_many => { :posts => :comments }, :shallow => true
|
||||
#
|
||||
# * <tt>:only</tt> and <tt>:except</tt> - Specify which of the seven default actions should be routed to.
|
||||
#
|
||||
# <tt>:only</tt> and <tt>:except</tt> may be set to <tt>:all</tt>, <tt>:none</tt>, an action name or a
|
||||
# list of action names. By default, routes are generated for all seven actions.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# map.resources :posts, :only => [:index, :show] do |post|
|
||||
# post.resources :comments, :except => [:update, :destroy]
|
||||
# end
|
||||
# # --> GET /posts (maps to the PostsController#index action)
|
||||
# # --> POST /posts (fails)
|
||||
# # --> GET /posts/1 (maps to the PostsController#show action)
|
||||
# # --> DELETE /posts/1 (fails)
|
||||
# # --> POST /posts/1/comments (maps to the CommentsController#create action)
|
||||
# # --> PUT /posts/1/comments/1 (fails)
|
||||
#
|
||||
# The <tt>:only</tt> and <tt>:except</tt> options are inherited by any nested resource(s).
|
||||
#
|
||||
# If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
|
||||
#
|
||||
# Examples:
|
||||
|
@ -478,7 +525,7 @@ module ActionController
|
|||
map_associations(resource, options)
|
||||
|
||||
if block_given?
|
||||
with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], &block)
|
||||
with_options(options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix), &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -495,7 +542,7 @@ module ActionController
|
|||
map_associations(resource, options)
|
||||
|
||||
if block_given?
|
||||
with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], &block)
|
||||
with_options(options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix), &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -507,7 +554,7 @@ module ActionController
|
|||
name_prefix = "#{options.delete(:name_prefix)}#{resource.nesting_name_prefix}"
|
||||
|
||||
Array(options[:has_one]).each do |association|
|
||||
resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace], :shallow => options[:shallow])
|
||||
resource(association, options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => path_prefix, :name_prefix => name_prefix))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -522,7 +569,7 @@ module ActionController
|
|||
map_has_many_associations(resource, association, options)
|
||||
end
|
||||
when Symbol, String
|
||||
resources(associations, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], :has_many => options[:has_many])
|
||||
resources(associations, options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :has_many => options[:has_many]))
|
||||
else
|
||||
end
|
||||
end
|
||||
|
@ -531,41 +578,39 @@ module ActionController
|
|||
resource.collection_methods.each do |method, actions|
|
||||
actions.each do |action|
|
||||
[method].flatten.each do |m|
|
||||
action_options = action_options_for(action, resource, m)
|
||||
map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
|
||||
map_resource_routes(map, resource, action, "#{resource.path}#{resource.action_separator}#{action}", "#{action}_#{resource.name_prefix}#{resource.plural}", m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def map_default_collection_actions(map, resource)
|
||||
index_action_options = action_options_for("index", resource)
|
||||
index_route_name = "#{resource.name_prefix}#{resource.plural}"
|
||||
|
||||
if resource.uncountable?
|
||||
index_route_name << "_index"
|
||||
end
|
||||
|
||||
map_named_routes(map, index_route_name, resource.path, index_action_options)
|
||||
|
||||
create_action_options = action_options_for("create", resource)
|
||||
map_unnamed_routes(map, resource.path, create_action_options)
|
||||
map_resource_routes(map, resource, :index, resource.path, index_route_name)
|
||||
map_resource_routes(map, resource, :create, resource.path, index_route_name)
|
||||
end
|
||||
|
||||
def map_default_singleton_actions(map, resource)
|
||||
create_action_options = action_options_for("create", resource)
|
||||
map_unnamed_routes(map, resource.path, create_action_options)
|
||||
map_resource_routes(map, resource, :create, resource.path, "#{resource.shallow_name_prefix}#{resource.singular}")
|
||||
end
|
||||
|
||||
def map_new_actions(map, resource)
|
||||
resource.new_methods.each do |method, actions|
|
||||
actions.each do |action|
|
||||
action_options = action_options_for(action, resource, method)
|
||||
if action == :new
|
||||
map_named_routes(map, "new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options)
|
||||
else
|
||||
map_named_routes(map, "#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options)
|
||||
route_path = resource.new_path
|
||||
route_name = "new_#{resource.name_prefix}#{resource.singular}"
|
||||
|
||||
unless action == :new
|
||||
route_path = "#{route_path}#{resource.action_separator}#{action}"
|
||||
route_name = "#{action}_#{route_name}"
|
||||
end
|
||||
|
||||
map_resource_routes(map, resource, action, route_path, route_name, method)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -574,34 +619,33 @@ module ActionController
|
|||
resource.member_methods.each do |method, actions|
|
||||
actions.each do |action|
|
||||
[method].flatten.each do |m|
|
||||
action_options = action_options_for(action, resource, m)
|
||||
|
||||
action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
|
||||
action_path ||= Base.resources_path_names[action] || action
|
||||
|
||||
map_named_routes(map, "#{action}_#{resource.shallow_name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
|
||||
map_resource_routes(map, resource, action, "#{resource.member_path}#{resource.action_separator}#{action_path}", "#{action}_#{resource.shallow_name_prefix}#{resource.singular}", m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
show_action_options = action_options_for("show", resource)
|
||||
map_named_routes(map, "#{resource.shallow_name_prefix}#{resource.singular}", resource.member_path, show_action_options)
|
||||
|
||||
update_action_options = action_options_for("update", resource)
|
||||
map_unnamed_routes(map, resource.member_path, update_action_options)
|
||||
|
||||
destroy_action_options = action_options_for("destroy", resource)
|
||||
map_unnamed_routes(map, resource.member_path, destroy_action_options)
|
||||
route_path = "#{resource.shallow_name_prefix}#{resource.singular}"
|
||||
map_resource_routes(map, resource, :show, resource.member_path, route_path)
|
||||
map_resource_routes(map, resource, :update, resource.member_path, route_path)
|
||||
map_resource_routes(map, resource, :destroy, resource.member_path, route_path)
|
||||
end
|
||||
|
||||
def map_unnamed_routes(map, path_without_format, options)
|
||||
map.connect(path_without_format, options)
|
||||
map.connect("#{path_without_format}.:format", options)
|
||||
end
|
||||
def map_resource_routes(map, resource, action, route_path, route_name = nil, method = nil)
|
||||
if resource.has_action?(action)
|
||||
action_options = action_options_for(action, resource, method)
|
||||
formatted_route_path = "#{route_path}.:format"
|
||||
|
||||
def map_named_routes(map, name, path_without_format, options)
|
||||
map.named_route(name, path_without_format, options)
|
||||
map.named_route("formatted_#{name}", "#{path_without_format}.:format", options)
|
||||
if route_name && @set.named_routes[route_name.to_sym].nil?
|
||||
map.named_route(route_name, route_path, action_options)
|
||||
map.named_route("formatted_#{route_name}", formatted_route_path, action_options)
|
||||
else
|
||||
map.connect(route_path, action_options)
|
||||
map.connect(formatted_route_path, action_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_conditions_for(conditions, method)
|
||||
|
|
0
vendor/rails/actionpack/lib/action_controller/response.rb
vendored
Executable file → Normal file
0
vendor/rails/actionpack/lib/action_controller/response.rb
vendored
Executable file → Normal file
|
@ -1,23 +1,16 @@
|
|||
module ActionController
|
||||
module Routing
|
||||
class RouteBuilder #:nodoc:
|
||||
attr_accessor :separators, :optional_separators
|
||||
attr_reader :separators, :optional_separators
|
||||
attr_reader :separator_regexp, :nonseparator_regexp, :interval_regexp
|
||||
|
||||
def initialize
|
||||
self.separators = Routing::SEPARATORS
|
||||
self.optional_separators = %w( / )
|
||||
end
|
||||
@separators = Routing::SEPARATORS
|
||||
@optional_separators = %w( / )
|
||||
|
||||
def separator_pattern(inverted = false)
|
||||
"[#{'^' if inverted}#{Regexp.escape(separators.join)}]"
|
||||
end
|
||||
|
||||
def interval_regexp
|
||||
Regexp.new "(.*?)(#{separators.source}|$)"
|
||||
end
|
||||
|
||||
def multiline_regexp?(expression)
|
||||
expression.options & Regexp::MULTILINE == Regexp::MULTILINE
|
||||
@separator_regexp = /[#{Regexp.escape(separators.join)}]/
|
||||
@nonseparator_regexp = /\A([^#{Regexp.escape(separators.join)}]+)/
|
||||
@interval_regexp = /(.*?)(#{separator_regexp}|$)/
|
||||
end
|
||||
|
||||
# Accepts a "route path" (a string defining a route), and returns the array
|
||||
|
@ -30,7 +23,7 @@ module ActionController
|
|||
rest, segments = path, []
|
||||
|
||||
until rest.empty?
|
||||
segment, rest = segment_for rest
|
||||
segment, rest = segment_for(rest)
|
||||
segments << segment
|
||||
end
|
||||
segments
|
||||
|
@ -39,20 +32,20 @@ module ActionController
|
|||
# A factory method that returns a new segment instance appropriate for the
|
||||
# format of the given string.
|
||||
def segment_for(string)
|
||||
segment = case string
|
||||
when /\A:(\w+)/
|
||||
key = $1.to_sym
|
||||
case key
|
||||
when :controller then ControllerSegment.new(key)
|
||||
else DynamicSegment.new key
|
||||
end
|
||||
when /\A\*(\w+)/ then PathSegment.new($1.to_sym, :optional => true)
|
||||
when /\A\?(.*?)\?/
|
||||
StaticSegment.new($1, :optional => true)
|
||||
when /\A(#{separator_pattern(:inverted)}+)/ then StaticSegment.new($1)
|
||||
when Regexp.new(separator_pattern) then
|
||||
DividerSegment.new($&, :optional => (optional_separators.include? $&))
|
||||
end
|
||||
segment =
|
||||
case string
|
||||
when /\A:(\w+)/
|
||||
key = $1.to_sym
|
||||
key == :controller ? ControllerSegment.new(key) : DynamicSegment.new(key)
|
||||
when /\A\*(\w+)/
|
||||
PathSegment.new($1.to_sym, :optional => true)
|
||||
when /\A\?(.*?)\?/
|
||||
StaticSegment.new($1, :optional => true)
|
||||
when nonseparator_regexp
|
||||
StaticSegment.new($1)
|
||||
when separator_regexp
|
||||
DividerSegment.new($&, :optional => optional_separators.include?($&))
|
||||
end
|
||||
[segment, $~.post_match]
|
||||
end
|
||||
|
||||
|
@ -98,7 +91,7 @@ module ActionController
|
|||
if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
|
||||
raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
if multiline_regexp?(requirement)
|
||||
if requirement.multiline?
|
||||
raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
segment.regexp = requirement
|
||||
|
|
|
@ -20,14 +20,20 @@ module ActionController
|
|||
|
||||
class Optimiser
|
||||
attr_reader :route, :kind
|
||||
GLOBAL_GUARD_CONDITIONS = [
|
||||
"(!defined?(default_url_options) || default_url_options.blank?)",
|
||||
"(!defined?(controller.default_url_options) || controller.default_url_options.blank?)",
|
||||
"defined?(request)",
|
||||
"request"
|
||||
]
|
||||
|
||||
def initialize(route, kind)
|
||||
@route = route
|
||||
@kind = kind
|
||||
end
|
||||
|
||||
def guard_condition
|
||||
'false'
|
||||
def guard_conditions
|
||||
["false"]
|
||||
end
|
||||
|
||||
def generation_code
|
||||
|
@ -36,6 +42,7 @@ module ActionController
|
|||
|
||||
def source_code
|
||||
if applicable?
|
||||
guard_condition = (GLOBAL_GUARD_CONDITIONS + guard_conditions).join(" && ")
|
||||
"return #{generation_code} if #{guard_condition}\n"
|
||||
else
|
||||
"\n"
|
||||
|
@ -57,14 +64,14 @@ module ActionController
|
|||
# return a string like "/people/#{@person.to_param}"
|
||||
# rather than triggering the expensive logic in +url_for+.
|
||||
class PositionalArguments < Optimiser
|
||||
def guard_condition
|
||||
def guard_conditions
|
||||
number_of_arguments = route.segment_keys.size
|
||||
# if they're using foo_url(:id=>2) it's one
|
||||
# argument, but we don't want to generate /foos/id2
|
||||
if number_of_arguments == 1
|
||||
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
|
||||
["args.size == 1", "!args.first.is_a?(Hash)"]
|
||||
else
|
||||
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
|
||||
["args.size == #{number_of_arguments}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,8 +105,9 @@ module ActionController
|
|||
# above, but it supports additional query parameters as the last
|
||||
# argument
|
||||
class PositionalArgumentsWithAdditionalParams < PositionalArguments
|
||||
def guard_condition
|
||||
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
|
||||
def guard_conditions
|
||||
["args.size == #{route.segment_keys.size + 1}"] +
|
||||
UrlRewriter::RESERVED_OPTIONS.collect{ |key| "!args.last.has_key?(:#{key})" }
|
||||
end
|
||||
|
||||
# This case uses almost the same code as positional arguments,
|
||||
|
|
|
@ -148,18 +148,12 @@ module ActionController
|
|||
end
|
||||
nil
|
||||
end
|
||||
}, __FILE__, __LINE__
|
||||
}, '(recognize_optimized)', 1
|
||||
end
|
||||
|
||||
def clear_recognize_optimized!
|
||||
remove_recognize_optimized!
|
||||
|
||||
class << self
|
||||
def recognize_optimized(path, environment)
|
||||
write_recognize_optimized!
|
||||
recognize_optimized(path, environment)
|
||||
end
|
||||
end
|
||||
write_recognize_optimized!
|
||||
end
|
||||
|
||||
def remove_recognize_optimized!
|
||||
|
|
|
@ -219,7 +219,7 @@ module ActionController
|
|||
next_capture = 1
|
||||
extraction = segments.collect do |segment|
|
||||
x = segment.match_extraction(next_capture)
|
||||
next_capture += Regexp.new(segment.regexp_chunk).number_of_captures
|
||||
next_capture += segment.number_of_captures
|
||||
x
|
||||
end
|
||||
extraction.compact
|
||||
|
|
|
@ -168,6 +168,7 @@ module ActionController
|
|||
#
|
||||
@module.module_eval <<-end_eval # We use module_eval to avoid leaks
|
||||
def #{selector}(*args)
|
||||
|
||||
#{generate_optimisation_block(route, kind)}
|
||||
|
||||
opts = if args.empty? || Hash === args.first
|
||||
|
|
|
@ -27,6 +27,10 @@ class Regexp #:nodoc:
|
|||
Regexp.new("|#{source}").match('').captures.length
|
||||
end
|
||||
|
||||
def multiline?
|
||||
options & MULTILINE == MULTILINE
|
||||
end
|
||||
|
||||
class << self
|
||||
def optionalize(pattern)
|
||||
case unoptionalize(pattern)
|
||||
|
|
|
@ -13,6 +13,10 @@ module ActionController
|
|||
@is_optional = false
|
||||
end
|
||||
|
||||
def number_of_captures
|
||||
Regexp.new(regexp_chunk).number_of_captures
|
||||
end
|
||||
|
||||
def extraction_code
|
||||
nil
|
||||
end
|
||||
|
@ -84,6 +88,10 @@ module ActionController
|
|||
optional? ? Regexp.optionalize(chunk) : chunk
|
||||
end
|
||||
|
||||
def number_of_captures
|
||||
0
|
||||
end
|
||||
|
||||
def build_pattern(pattern)
|
||||
escaped = Regexp.escape(value)
|
||||
if optional? && ! pattern.empty?
|
||||
|
@ -194,10 +202,16 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
def number_of_captures
|
||||
if regexp
|
||||
regexp.number_of_captures + 1
|
||||
else
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
def build_pattern(pattern)
|
||||
chunk = regexp_chunk
|
||||
chunk = "(#{chunk})" if Regexp.new(chunk).number_of_captures == 0
|
||||
pattern = "#{chunk}#{pattern}"
|
||||
pattern = "#{regexp_chunk}#{pattern}"
|
||||
optional? ? Regexp.optionalize(pattern) : pattern
|
||||
end
|
||||
|
||||
|
@ -230,6 +244,10 @@ module ActionController
|
|||
"(?i-:(#{(regexp || Regexp.union(*possible_names)).source}))"
|
||||
end
|
||||
|
||||
def number_of_captures
|
||||
1
|
||||
end
|
||||
|
||||
# Don't URI.escape the controller name since it may contain slashes.
|
||||
def interpolation_chunk(value_code = local_name)
|
||||
"\#{#{value_code}.to_s}"
|
||||
|
@ -275,6 +293,10 @@ module ActionController
|
|||
regexp || "(.*)"
|
||||
end
|
||||
|
||||
def number_of_captures
|
||||
regexp ? regexp.number_of_captures : 1
|
||||
end
|
||||
|
||||
def optionality_implied?
|
||||
true
|
||||
end
|
||||
|
|
0
vendor/rails/actionpack/lib/action_controller/session/drb_server.rb
vendored
Normal file → Executable file
0
vendor/rails/actionpack/lib/action_controller/session/drb_server.rb
vendored
Normal file → Executable file
|
@ -218,7 +218,7 @@ module ActionController #:nodoc:
|
|||
# Returns the template of the file which was used to
|
||||
# render this response (or nil)
|
||||
def rendered_template
|
||||
template.send(:_first_render)
|
||||
template.instance_variable_get(:@_first_render)
|
||||
end
|
||||
|
||||
# A shortcut to the flash. Returns an empty hash if no session flash exists.
|
||||
|
@ -395,6 +395,7 @@ module ActionController #:nodoc:
|
|||
|
||||
@html_document = nil
|
||||
@request.env['REQUEST_METHOD'] ||= "GET"
|
||||
|
||||
@request.action = action.to_s
|
||||
|
||||
parameters ||= {}
|
||||
|
|
|
@ -160,7 +160,7 @@ module HTML
|
|||
if !options[:attributes].include?(attr_name) || contains_bad_protocols?(attr_name, value)
|
||||
node.attributes.delete(attr_name)
|
||||
else
|
||||
node.attributes[attr_name] = attr_name == 'style' ? sanitize_css(value) : CGI::escapeHTML(value)
|
||||
node.attributes[attr_name] = attr_name == 'style' ? sanitize_css(value) : CGI::escapeHTML(CGI::unescapeHTML(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue