Instiki 0.16.3: Rails 2.3.0
Instiki now runs on the Rails 2.3.0 Candidate Release. Among other improvements, this means that it now automagically selects between WEBrick and Mongrel. Just run ./instiki --daemon
This commit is contained in:
parent
43aadecc99
commit
4e14ccc74d
893 changed files with 71965 additions and 28511 deletions
|
@ -34,6 +34,8 @@ module ActionController
|
|||
def segment_for(string)
|
||||
segment =
|
||||
case string
|
||||
when /\A\.(:format)?\//
|
||||
OptionalFormatSegment.new
|
||||
when /\A:(\w+)/
|
||||
key = $1.to_sym
|
||||
key == :controller ? ControllerSegment.new(key) : DynamicSegment.new(key)
|
||||
|
|
|
@ -65,7 +65,7 @@ module ActionController
|
|||
# rather than triggering the expensive logic in +url_for+.
|
||||
class PositionalArguments < Optimiser
|
||||
def guard_conditions
|
||||
number_of_arguments = route.segment_keys.size
|
||||
number_of_arguments = route.required_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
|
||||
|
|
|
@ -56,7 +56,7 @@ module ActionController
|
|||
result = recognize_optimized(path, environment) and return result
|
||||
|
||||
# Route was not recognized. Try to find out why (maybe wrong verb).
|
||||
allows = HTTP_METHODS.select { |verb| routes.find { |r| r.recognize(path, :method => verb) } }
|
||||
allows = HTTP_METHODS.select { |verb| routes.find { |r| r.recognize(path, environment.merge(:method => verb)) } }
|
||||
|
||||
if environment[:method] && !HTTP_METHODS.include?(environment[:method])
|
||||
raise NotImplemented.new(*allows)
|
||||
|
|
|
@ -35,6 +35,11 @@ module ActionController
|
|||
segment.key if segment.respond_to? :key
|
||||
end.compact
|
||||
end
|
||||
|
||||
def required_segment_keys
|
||||
required_segments = segments.select {|seg| (!seg.optional? && !seg.is_a?(DividerSegment)) || seg.is_a?(PathSegment) }
|
||||
required_segments.collect { |seg| seg.key if seg.respond_to?(:key)}.compact
|
||||
end
|
||||
|
||||
# Build a query string from the keys of the given hash. If +only_keys+
|
||||
# is given (as an array), only the keys indicated will be used to build
|
||||
|
@ -122,6 +127,16 @@ module ActionController
|
|||
super
|
||||
end
|
||||
|
||||
def generate(options, hash, expire_on = {})
|
||||
path, hash = generate_raw(options, hash, expire_on)
|
||||
append_query_string(path, hash, extra_keys(options))
|
||||
end
|
||||
|
||||
def generate_extras(options, hash, expire_on = {})
|
||||
path, hash = generate_raw(options, hash, expire_on)
|
||||
[path, extra_keys(options)]
|
||||
end
|
||||
|
||||
private
|
||||
def requirement_for(key)
|
||||
return requirements[key] if requirements.key? key
|
||||
|
@ -150,11 +165,6 @@ module ActionController
|
|||
# the query string. (Never use keys from the recalled request when building the
|
||||
# query string.)
|
||||
|
||||
method_decl = "def generate(#{args})\npath, hash = generate_raw(options, hash, expire_on)\nappend_query_string(path, hash, extra_keys(options))\nend"
|
||||
instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
|
||||
|
||||
method_decl = "def generate_extras(#{args})\npath, hash = generate_raw(options, hash, expire_on)\n[path, extra_keys(options)]\nend"
|
||||
instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
|
||||
raw_method
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ module ActionController
|
|||
# Mapper instances have relatively few instance methods, in order to avoid
|
||||
# clashes with named routes.
|
||||
class Mapper #:doc:
|
||||
include ActionController::Resources
|
||||
|
||||
def initialize(set) #:nodoc:
|
||||
@set = set
|
||||
end
|
||||
|
@ -136,13 +138,17 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
def named_helper_module_eval(code, *args)
|
||||
@module.module_eval(code, *args)
|
||||
end
|
||||
|
||||
def define_hash_access(route, name, kind, options)
|
||||
selector = hash_access_name(name, kind)
|
||||
@module.module_eval <<-end_eval # We use module_eval to avoid leaks
|
||||
def #{selector}(options = nil)
|
||||
options ? #{options.inspect}.merge(options) : #{options.inspect}
|
||||
end
|
||||
protected :#{selector}
|
||||
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
|
||||
def #{selector}(options = nil) # def hash_for_users_url(options = nil)
|
||||
options ? #{options.inspect}.merge(options) : #{options.inspect} # options ? {:only_path=>false}.merge(options) : {:only_path=>false}
|
||||
end # end
|
||||
protected :#{selector} # protected :hash_for_users_url
|
||||
end_eval
|
||||
helpers << selector
|
||||
end
|
||||
|
@ -166,33 +172,44 @@ module ActionController
|
|||
#
|
||||
# foo_url(bar, baz, bang, :sort_by => 'baz')
|
||||
#
|
||||
@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
|
||||
args.first || {}
|
||||
else
|
||||
options = args.extract_options!
|
||||
args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|
|
||||
h[k] = v
|
||||
h
|
||||
end
|
||||
options.merge(args)
|
||||
end
|
||||
|
||||
url_for(#{hash_access_method}(opts))
|
||||
end
|
||||
protected :#{selector}
|
||||
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
|
||||
def #{selector}(*args) # def users_url(*args)
|
||||
#
|
||||
#{generate_optimisation_block(route, kind)} # #{generate_optimisation_block(route, kind)}
|
||||
#
|
||||
opts = if args.empty? || Hash === args.first # opts = if args.empty? || Hash === args.first
|
||||
args.first || {} # args.first || {}
|
||||
else # else
|
||||
options = args.extract_options! # options = args.extract_options!
|
||||
args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)| # args = args.zip([]).inject({}) do |h, (v, k)|
|
||||
h[k] = v # h[k] = v
|
||||
h # h
|
||||
end # end
|
||||
options.merge(args) # options.merge(args)
|
||||
end # end
|
||||
#
|
||||
url_for(#{hash_access_method}(opts)) # url_for(hash_for_users_url(opts))
|
||||
#
|
||||
end # end
|
||||
#Add an alias to support the now deprecated formatted_* URL. # #Add an alias to support the now deprecated formatted_* URL.
|
||||
def formatted_#{selector}(*args) # def formatted_users_url(*args)
|
||||
ActiveSupport::Deprecation.warn( # ActiveSupport::Deprecation.warn(
|
||||
"formatted_#{selector}() has been deprecated. " + # "formatted_users_url() has been deprecated. " +
|
||||
"Please pass format to the standard " + # "Please pass format to the standard " +
|
||||
"#{selector} method instead.", caller) # "users_url method instead.", caller)
|
||||
#{selector}(*args) # users_url(*args)
|
||||
end # end
|
||||
protected :#{selector} # protected :users_url
|
||||
end_eval
|
||||
helpers << selector
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :routes, :named_routes, :configuration_file
|
||||
attr_accessor :routes, :named_routes, :configuration_files
|
||||
|
||||
def initialize
|
||||
self.configuration_files = []
|
||||
|
||||
self.routes = []
|
||||
self.named_routes = NamedRouteCollection.new
|
||||
|
||||
|
@ -206,7 +223,6 @@ module ActionController
|
|||
end
|
||||
|
||||
def draw
|
||||
clear!
|
||||
yield Mapper.new(self)
|
||||
install_helpers
|
||||
end
|
||||
|
@ -230,8 +246,22 @@ module ActionController
|
|||
routes.empty?
|
||||
end
|
||||
|
||||
def add_configuration_file(path)
|
||||
self.configuration_files << path
|
||||
end
|
||||
|
||||
# Deprecated accessor
|
||||
def configuration_file=(path)
|
||||
add_configuration_file(path)
|
||||
end
|
||||
|
||||
# Deprecated accessor
|
||||
def configuration_file
|
||||
configuration_files
|
||||
end
|
||||
|
||||
def load!
|
||||
Routing.use_controllers! nil # Clear the controller cache so we may discover new ones
|
||||
Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
|
||||
clear!
|
||||
load_routes!
|
||||
end
|
||||
|
@ -240,24 +270,39 @@ module ActionController
|
|||
alias reload! load!
|
||||
|
||||
def reload
|
||||
if @routes_last_modified && configuration_file
|
||||
mtime = File.stat(configuration_file).mtime
|
||||
# if it hasn't been changed, then just return
|
||||
return if mtime == @routes_last_modified
|
||||
# if it has changed then record the new time and fall to the load! below
|
||||
@routes_last_modified = mtime
|
||||
if configuration_files.any? && @routes_last_modified
|
||||
if routes_changed_at == @routes_last_modified
|
||||
return # routes didn't change, don't reload
|
||||
else
|
||||
@routes_last_modified = routes_changed_at
|
||||
end
|
||||
end
|
||||
|
||||
load!
|
||||
end
|
||||
|
||||
def load_routes!
|
||||
if configuration_file
|
||||
load configuration_file
|
||||
@routes_last_modified = File.stat(configuration_file).mtime
|
||||
if configuration_files.any?
|
||||
configuration_files.each { |config| load(config) }
|
||||
@routes_last_modified = routes_changed_at
|
||||
else
|
||||
add_route ":controller/:action/:id"
|
||||
end
|
||||
end
|
||||
|
||||
def routes_changed_at
|
||||
routes_changed_at = nil
|
||||
|
||||
configuration_files.each do |config|
|
||||
config_changed_at = File.stat(config).mtime
|
||||
|
||||
if routes_changed_at.nil? || config_changed_at > routes_changed_at
|
||||
routes_changed_at = config_changed_at
|
||||
end
|
||||
end
|
||||
|
||||
routes_changed_at
|
||||
end
|
||||
|
||||
def add_route(path, options = {})
|
||||
route = builder.build(path, options)
|
||||
|
@ -359,7 +404,7 @@ module ActionController
|
|||
end
|
||||
|
||||
# don't use the recalled keys when determining which routes to check
|
||||
routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }]
|
||||
routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
|
||||
|
||||
routes.each do |route|
|
||||
results = route.__send__(method, options, merged, expire_on)
|
||||
|
@ -382,6 +427,12 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
def call(env)
|
||||
request = Request.new(env)
|
||||
app = Routing::Routes.recognize(request)
|
||||
app.call(env).to_a
|
||||
end
|
||||
|
||||
def recognize(request)
|
||||
params = recognize_path(request.path, extract_request_environment(request))
|
||||
request.path_parameters = params.with_indifferent_access
|
||||
|
|
|
@ -308,5 +308,36 @@ module ActionController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The OptionalFormatSegment allows for any resource route to have an optional
|
||||
# :format, which decreases the amount of routes created by 50%.
|
||||
class OptionalFormatSegment < DynamicSegment
|
||||
|
||||
def initialize(key = nil, options = {})
|
||||
super(:format, {:optional => true}.merge(options))
|
||||
end
|
||||
|
||||
def interpolation_chunk
|
||||
"." + super
|
||||
end
|
||||
|
||||
def regexp_chunk
|
||||
'(\.[^/?\.]+)?'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'(.:format)?'
|
||||
end
|
||||
|
||||
#the value should not include the period (.)
|
||||
def match_extraction(next_capture)
|
||||
%[
|
||||
if (m = match[#{next_capture}])
|
||||
params[:#{key}] = URI.unescape(m.from(1))
|
||||
end
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue