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@250
|
18 local static = string.match(path, "^static/([-./0-9A-Z_a-z]+)$")
|
jbe@250
|
19 if static then
|
jbe@250
|
20 if
|
jbe@250
|
21 string.match(static, "^/") or
|
jbe@250
|
22 string.match(static, "//") or
|
jbe@250
|
23 string.match(static, "/$") or
|
jbe@250
|
24 string.match(static, "^%.%.?$") or
|
jbe@250
|
25 string.match(static, "/%.%.?$") or
|
jbe@250
|
26 string.match(static, "^%.%.?/") or
|
jbe@250
|
27 string.match(static, "/%.%.?/") -- TODO: improve
|
jbe@250
|
28 then
|
jbe@250
|
29 return nil
|
jbe@250
|
30 else
|
jbe@250
|
31 return {static = static}
|
jbe@250
|
32 end
|
jbe@250
|
33 end
|
jbe@250
|
34 local module, action, view, id, suffix
|
jbe@221
|
35 module = string.match(path, "^([^/]+)/$")
|
jbe@216
|
36 if module then
|
jbe@216
|
37 return {module = module, view = "index"}
|
jbe@215
|
38 end
|
jbe@221
|
39 module, action = string.match(path, "^([^/]+)/([^/.]+)$")
|
jbe@216
|
40 if module then
|
jbe@216
|
41 return {module = module, action = action}
|
jbe@215
|
42 end
|
jbe@221
|
43 module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
|
jbe@216
|
44 if module then
|
jbe@216
|
45 return {module = module, view = view, suffix = suffix}
|
jbe@216
|
46 end
|
jbe@221
|
47 module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
|
jbe@216
|
48 if module then
|
jbe@216
|
49 return {module = module, view = view, id = id, suffix = suffix}
|
jbe@216
|
50 end
|
jbe@216
|
51 return nil
|
jbe@216
|
52 end
|
jbe@210
|
53
|
jbe@216
|
54 --//--
|