rev |
line source |
jbe@216
|
1 --[[--
|
jbe@216
|
2 route =
|
jbe@216
|
3 request.default_router(
|
jbe@216
|
4 path -- URL path, including a leading slash
|
jbe@216
|
5 )
|
jbe@210
|
6
|
jbe@216
|
7 Default conversion from a path to a route. Called by request.router().
|
jbe@216
|
8
|
jbe@216
|
9 --]]--
|
jbe@215
|
10
|
jbe@215
|
11 function request.default_router(path)
|
jbe@216
|
12 if not path then
|
jbe@216
|
13 return nil
|
jbe@216
|
14 end
|
jbe@221
|
15 if path == "" then
|
jbe@216
|
16 return {module = "index", view = "index"}
|
jbe@216
|
17 end
|
jbe@347
|
18 local static = string.match(path, "^static/([-./0-9A-Z_a-z]*)$")
|
jbe@250
|
19 if static then
|
jbe@347
|
20 -- TODO: move sanitizer to request.handler(...)
|
jbe@347
|
21 if string.match(static, "^/") or string.match(static, "//") then
|
jbe@250
|
22 return nil
|
jbe@250
|
23 end
|
jbe@347
|
24 for element in string.gmatch(static, "[^/]+") do
|
jbe@347
|
25 if element == "." or element == ".." then
|
jbe@347
|
26 return nil
|
jbe@347
|
27 end
|
jbe@347
|
28 end
|
jbe@347
|
29 return {static = static}
|
jbe@250
|
30 end
|
jbe@250
|
31 local module, action, view, id, suffix
|
jbe@221
|
32 module = string.match(path, "^([^/]+)/$")
|
jbe@216
|
33 if module then
|
jbe@216
|
34 return {module = module, view = "index"}
|
jbe@215
|
35 end
|
jbe@221
|
36 module, action = string.match(path, "^([^/]+)/([^/.]+)$")
|
jbe@216
|
37 if module then
|
jbe@216
|
38 return {module = module, action = action}
|
jbe@215
|
39 end
|
jbe@221
|
40 module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
|
jbe@216
|
41 if module then
|
jbe@216
|
42 return {module = module, view = view, suffix = suffix}
|
jbe@216
|
43 end
|
jbe@221
|
44 module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
|
jbe@216
|
45 if module then
|
jbe@216
|
46 return {module = module, view = view, id = id, suffix = suffix}
|
jbe@216
|
47 end
|
jbe@216
|
48 return nil
|
jbe@216
|
49 end
|
jbe@210
|
50
|
jbe@216
|
51 --//--
|