Remove only formats in shortcuts and do it just once.

This commit is contained in:
José Valim 2010-04-20 14:04:46 +02:00
parent 2e3d903e1b
commit da32661f10

@ -64,10 +64,11 @@ def extract_path_and_options(args)
end
path = normalize_path(path)
path_without_format = path.sub(/\(\.:format\)$/, '')
if using_match_shorthand?(path, options)
options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1').sub(%r{\(.*\)}, '')
options[:as] ||= path[1..-1].gsub("/", "_").sub(%r{\(.*\)}, '')
if using_match_shorthand?(path_without_format, options)
options[:to] ||= path_without_format[1..-1].sub(%r{/([^/]*)$}, '#\1')
options[:as] ||= path_without_format[1..-1].gsub("/", "_")
end
[ path, options ]
@ -80,7 +81,7 @@ def using_to_shorthand?(args, options)
# match "account/overview"
def using_match_shorthand?(path, options)
path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w+/?]+(\(.*\))*$}
path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$}
end
def normalize_path(path)