mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
pull up path parsing
`add_route` needs the AST, so rather than shove it in a hash and delete later, lets move parsing up the stack so we can pass down later
This commit is contained in:
parent
7fa6600b52
commit
aaaa67902e
3 changed files with 12 additions and 11 deletions
|
@ -6,6 +6,10 @@ module ActionDispatch
|
||||||
class Parser < Racc::Parser # :nodoc:
|
class Parser < Racc::Parser # :nodoc:
|
||||||
include Journey::Nodes
|
include Journey::Nodes
|
||||||
|
|
||||||
|
def self.parse(string)
|
||||||
|
new.parse string
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@scanner = Scanner.new
|
@scanner = Scanner.new
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,13 +61,13 @@ module ActionDispatch
|
||||||
attr_reader :requirements, :conditions, :defaults
|
attr_reader :requirements, :conditions, :defaults
|
||||||
attr_reader :to, :default_controller, :default_action
|
attr_reader :to, :default_controller, :default_action
|
||||||
|
|
||||||
def self.build(scope, set, path, controller, default_action, to, via, formatted, options_constraints, options)
|
def self.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, options)
|
||||||
options = scope[:options].merge(options) if scope[:options]
|
options = scope[:options].merge(options) if scope[:options]
|
||||||
|
|
||||||
defaults = (scope[:defaults] || {}).dup
|
defaults = (scope[:defaults] || {}).dup
|
||||||
scope_constraints = scope[:constraints] || {}
|
scope_constraints = scope[:constraints] || {}
|
||||||
|
|
||||||
new set, path, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, options
|
new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, options
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_via(via)
|
def self.check_via(via)
|
||||||
|
@ -98,7 +98,7 @@ module ActionDispatch
|
||||||
format != false && !path.include?(':format') && !path.end_with?('/')
|
format != false && !path.include?(':format') && !path.end_with?('/')
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(set, path, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, options)
|
def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, options)
|
||||||
@defaults = defaults
|
@defaults = defaults
|
||||||
@set = set
|
@set = set
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ module ActionDispatch
|
||||||
@default_controller = controller
|
@default_controller = controller
|
||||||
@default_action = default_action
|
@default_action = default_action
|
||||||
|
|
||||||
ast = path_ast path
|
|
||||||
path_params = path_params ast
|
path_params = path_params ast
|
||||||
|
|
||||||
options = normalize_options!(options, formatted, path_params, ast, modyoule)
|
options = normalize_options!(options, formatted, path_params, ast, modyoule)
|
||||||
|
@ -306,11 +305,6 @@ module ActionDispatch
|
||||||
ast.grep(Journey::Nodes::Symbol).map { |n| n.name.to_sym }
|
ast.grep(Journey::Nodes::Symbol).map { |n| n.name.to_sym }
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_ast(path)
|
|
||||||
parser = Journey::Parser.new
|
|
||||||
parser.parse path
|
|
||||||
end
|
|
||||||
|
|
||||||
def dispatcher(raise_on_name_error)
|
def dispatcher(raise_on_name_error)
|
||||||
@set.dispatcher raise_on_name_error
|
@set.dispatcher raise_on_name_error
|
||||||
end
|
end
|
||||||
|
@ -1607,7 +1601,9 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
path = Mapping.normalize_path URI.parser.escape(path), formatted
|
path = Mapping.normalize_path URI.parser.escape(path), formatted
|
||||||
mapping = Mapping.build(@scope, @set, path, controller, default_action, to, via, formatted, options_constraints, options)
|
ast = Journey::Parser.parse path
|
||||||
|
|
||||||
|
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, options)
|
||||||
app, conditions, requirements, defaults = mapping.to_route
|
app, conditions, requirements, defaults = mapping.to_route
|
||||||
@set.add_route(app, conditions, requirements, defaults, as, anchor)
|
@set.add_route(app, conditions, requirements, defaults, as, anchor)
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,7 +98,8 @@ module ActionDispatch
|
||||||
def test_mapping_requirements
|
def test_mapping_requirements
|
||||||
options = { }
|
options = { }
|
||||||
scope = Mapper::Scope.new({})
|
scope = Mapper::Scope.new({})
|
||||||
m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, {}, options)
|
ast = Journey::Parser.parse '/store/:name(*rest)'
|
||||||
|
m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, options)
|
||||||
_, _, requirements, _ = m.to_route
|
_, _, requirements, _ = m.to_route
|
||||||
assert_equal(/.+?/, requirements[:rest])
|
assert_equal(/.+?/, requirements[:rest])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue