webmcp
view framework/env/request/default_router.lua @ 289:d36e69dfb59e
Removed TODO message regarding trace system
| author | jbe | 
|---|---|
| date | Sun Mar 22 12:26:01 2015 +0100 (2015-03-22) | 
| parents | db79324a13fe | 
| children | 169dfbd0246a | 
 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 path == "" then
    16     return {module = "index", view = "index"}
    17   end
    18   local static = string.match(path, "^static/([-./0-9A-Z_a-z]+)$")
    19   if static then
    20     if
    21       string.match(static, "^/") or
    22       string.match(static, "//") or
    23       string.match(static, "/$") or
    24       string.match(static, "^%.%.?$") or
    25       string.match(static, "/%.%.?$") or
    26       string.match(static, "^%.%.?/") or
    27       string.match(static, "/%.%.?/")  -- TODO: improve
    28     then
    29       return nil
    30     else
    31       return {static = static}
    32     end
    33   end
    34   local module, action, view, id, suffix
    35   module = string.match(path, "^([^/]+)/$")
    36   if module then
    37     return {module = module, view = "index"}
    38   end
    39   module, action = string.match(path, "^([^/]+)/([^/.]+)$")
    40   if module then
    41     return {module = module, action = action}
    42   end
    43   module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
    44   if module then
    45     return {module = module, view = view, suffix = suffix}
    46   end
    47   module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
    48   if module then
    49     return {module = module, view = view, id = id, suffix = suffix}
    50   end
    51   return nil
    52 end
    54 --//--
