--[[ 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 code, err = parser:compile_to_lua(fdata) if not code then errorf("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(env) assert(type(env) == "table","env must be a table") local buff, err = parser:run(func,env) if not buff then errorf("Failed to render %s : %s", path, err) end return table.concat(buff) end end return pages