Created
September 8, 2015 15:56
-
-
Save idevz/87b59948ef7bf24ba244 to your computer and use it in GitHub Desktop.
A Simple route for vanilla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- perf | |
local sgmatch = string.gmatch | |
-- init Simple and set routes | |
local Simple = {} | |
function Simple:new(request) | |
local instance = { | |
route_name = 'Simple', | |
request = request | |
} | |
setmetatable(instance, {__index = self}) | |
return instance | |
end | |
function Simple:match() | |
local uri = self.request.uri | |
local match = {} | |
local tmp = 1 | |
if uri == '/' then | |
return 'index', 'index' | |
end | |
for v in sgmatch(uri , '/([A-Za-z0-9_]+)') do | |
match[tmp] = v | |
tmp = tmp +1 | |
end | |
if #match == 1 then | |
return match[1], 'index' | |
else | |
return table.concat(match, '.', 1, #match - 1), match[#match] | |
end | |
end | |
return Simple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment