webmcp
view framework/env/request/default_router.lua @ 220:e69251d4ba0e
Bugfix: call execute.prefork_initializers() only once in mcp.lua
| author | jbe | 
|---|---|
| date | Sun Feb 22 17:16:13 2015 +0100 (2015-02-22) | 
| parents | fd0360594636 | 
| 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 --//--
