Wed, 24 Nov 2021 16:17:48 +0000
Bump lua-unbound from 0.5 to 1.0.0
0 | 1 | local lfs = require "lfs"; |
2 | ||
3 | local function readfile(filename) | |
4 | local fh = assert(io.open(filename)); | |
5 | local data = fh:read("*a"); | |
6 | fh:close(); | |
7 | return data; | |
8 | end | |
9 | ||
10 | local _M = {}; | |
11 | ||
12 | local template_base_path = (os.getenv("TEMPLATE_PATH") or ".").."/"; | |
13 | ||
14 | function _M.init(config) | |
15 | local templates = {}; | |
16 | ||
17 | local template_path = template_base_path..(config.templates or "html"); | |
18 | ||
19 | for filename in lfs.dir(template_path) do | |
20 | local template_name = filename; | |
21 | if filename:match("%.html$") then | |
22 | template_name = filename:gsub("%.html$", ""); | |
23 | end | |
24 | templates[template_name] = readfile(template_path.."/"..filename); | |
25 | end | |
26 | ||
27 | return templates; | |
28 | end | |
29 | ||
30 | return _M; |