webmcp

view framework/env/request/default_router.lua @ 216:fd0360594636

Work on request.process(...), request.default_router(...), request.router(), request.handler(...)
author jbe
date Mon Jan 12 03:02:26 2015 +0100 (2015-01-12)
parents ba3dd4a17e3d
children 25a20bd1f416
line source
1 --[[--
2 route =
3 request.default_router(
4 path -- URL path, including a leading slash
5 )
7 Default conversion from a path to a route. Called by request.router().
9 --]]--
11 function request.default_router(path)
12 if not path then
13 return nil
14 end
15 if not string.match(path, "^/") then
16 path = "/" .. path
17 end
18 if path == "/" then
19 return {module = "index", view = "index"}
20 end
21 module = string.match(path, "^/([^/]+)/$")
22 if module then
23 return {module = module, view = "index"}
24 end
25 module, action = string.match(path, "^/([^/]+)/([^/.]+)$")
26 if module then
27 return {module = module, action = action}
28 end
29 module, view, suffix = string.match(path, "^/([^/]+)/([^/.]+)%.([^/]+)$")
30 if module then
31 return {module = module, view = view, suffix = suffix}
32 end
33 module, view, id, suffix = string.match(path, "^/([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
34 if module then
35 return {module = module, view = view, id = id, suffix = suffix}
36 end
37 return nil
38 end
40 --//--

Impressum / About Us