47 lines
1007 B
Lua
47 lines
1007 B
Lua
--[[
|
|
Compiles all the pages under src/pages/ with etlua. See the etlua documentation
|
|
for more info (https://github.com/leafo/etlua)
|
|
]]
|
|
local et = require("etlua")
|
|
local pagenames = {
|
|
"index",
|
|
"author_index",
|
|
"claim",
|
|
"paste",
|
|
"edit",
|
|
"read",
|
|
"nostory",
|
|
"cantedit",
|
|
"noauthor",
|
|
"login",
|
|
"author_paste",
|
|
"author_edit",
|
|
"search",
|
|
}
|
|
local pages = {}
|
|
local function load1(page)
|
|
local path = string.format("pages/%s.etlua",page)
|
|
local parser = et.Parser()
|
|
local f = assert(io.open(path,"r"))
|
|
local fdata = assert(f:read("*a"))
|
|
local code = assert(parser:parse(fdata))
|
|
local func = assert(parser:load(parser:chunks_to_lua(),path))
|
|
f:close()
|
|
return function(...)
|
|
buf = assert(parser:run(func,...))
|
|
return table.concat(buf)
|
|
end
|
|
end
|
|
local function load2(page)
|
|
local path = string.format("pages/%s.etlua",page)
|
|
local f = assert(io.open(path,"r"))
|
|
local ret = assert(et.compile(f:read("*a")))
|
|
f:close()
|
|
return ret
|
|
end
|
|
for k,v in pairs(pagenames) do
|
|
pages[v] = load1(v)
|
|
end
|
|
|
|
return pages
|