Route variable part is suffixed with a star *
:
var route = new AppGlobRoute("/*")
assert route.match("/")
assert route.match("/user")
assert route.match("/user/10")
Glob routes can be combined with parameters:
route = new AppGlobRoute("/user/:id/*")
assert not route.match("/user")
assert route.match("/user/10")
assert route.match("/user/10/profile")
Note that the star can be used directly on the end of an URI part:
route = new AppGlobRoute("/user*")
assert route.match("/user")
assert route.match("/username")
assert route.match("/user/10/profile")
assert not route.match("/foo")
For now, stars cannot be used inside a route, use URI parameters instead.
popcorn :: AppGlobRoute :: defaultinit
popcorn $ AppGlobRoute :: SELF
Type of this instance, automatically specialized in every classpopcorn $ AppGlobRoute :: resolve_path
Path without the trailing*
.
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
popcorn :: AppParamRoute :: defaultinit
popcorn :: AppGlobRoute :: defaultinit
popcorn :: AppRoute :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).popcorn :: AppParamRoute :: parse_path_parameters
Cutpath
into UriParts
.
popcorn :: AppParamRoute :: parse_uri_parameters
Extract parameter values fromuri
.
popcorn :: AppRoute :: resolve_path
Replace path parameters with concrete values from theuri
.
# Route with glob.
#
# Route variable part is suffixed with a star `*`:
# ~~~
# var route = new AppGlobRoute("/*")
# assert route.match("/")
# assert route.match("/user")
# assert route.match("/user/10")
# ~~~
#
# Glob routes can be combined with parameters:
# ~~~
# route = new AppGlobRoute("/user/:id/*")
# assert not route.match("/user")
# assert route.match("/user/10")
# assert route.match("/user/10/profile")
# ~~~
#
# Note that the star can be used directly on the end of an URI part:
# ~~~
# route = new AppGlobRoute("/user*")
# assert route.match("/user")
# assert route.match("/username")
# assert route.match("/user/10/profile")
# assert not route.match("/foo")
# ~~~
#
# For now, stars cannot be used inside a route, use URI parameters instead.
class AppGlobRoute
super AppParamRoute
# Path without the trailing `*`.
# ~~~
# var route = new AppGlobRoute("/user/:id/*")
# assert route.resolve_path("/user/10/profile") == "/user/10"
#
# route = new AppGlobRoute("/user/:userId/items/:itemId*")
# assert route.resolve_path("/user/Morriar/items/i156/desc") == "/user/Morriar/items/i156"
# ~~~
redef fun resolve_path(uri) do
var path = super
if path.has_suffix("*") then
return path.substring(0, path.length - 1).simplify_path
end
return path.simplify_path
end
redef fun match(uri) do
var path = resolve_path(uri)
return uri.has_prefix(path.substring(0, path.length - 1))
end
end
lib/popcorn/pop_routes.nit:178,1--229,3