--[[ 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") require("global") local pagenames = { "index", "author_index", "claim", "paste", "edit", "read", "nostory", "cantedit", "noauthor", "login", "author_paste", "author_edit", "search", "error", "edit_bio", } local pages = {} for k,v in pairs(pagenames) do local path = string.format("pages/%s.etlua",v) local parser = et.Parser() local f = assert(io.open(path,"r")) local fdata = assert(f:read("*a")) local e,code = assert(xpcall(function() return parser:compile_to_lua(fdata) end,function(err) return debug.traceback(string.format("Failed to parse %s: %s",path, err)) end)) local func, err = parser:load(code) if not func then error(string.format("Failed to load %s: %s",path, err)) end f:close() assert(func, "Failed to load " .. path) pages[v] = function(...) local buf = assert(parser:run(func,...)) return table.concat(buf) end end return pages