src/templates.lua

Wed, 24 Nov 2021 16:18:11 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 24 Nov 2021 16:18:11 +0000
changeset 9
e5f706093df7
parent 0
6279a7d40ae7
child 11
635b385df3a2
permissions
-rw-r--r--

Bump Prosody to 85d51bfcf56b (for util.openmetrics change)

local lfs = require "lfs";

local function readfile(filename)
	local fh = assert(io.open(filename));
	local data = fh:read("*a");
	fh:close();
	return data;
end

local _M = {};

local template_base_path = (os.getenv("TEMPLATE_PATH") or ".").."/";

function _M.init(config)
	local templates = {};

	local template_path = template_base_path..(config.templates or "html");

	for filename in lfs.dir(template_path) do
		local template_name = filename;
		if filename:match("%.html$") then
			template_name = filename:gsub("%.html$", "");
		end
		templates[template_name] = readfile(template_path.."/"..filename);
	end

	return templates;
end

return _M;

mercurial