-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplates.lua
51 lines (39 loc) · 985 Bytes
/
templates.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local mustache = require'mustache'
local t={}
local _M
local function get(name)
local f = assert(io.open("scripts/r18/templates/"..name..'.html','rb'))
if f then
local template = f:read("*all")
f:close()
template = mustache.compile(template)
return template
end
end
_M=setmetatable({},{__index=function(self,k)
local cached = t[k]
if cached~=nil then assert(cached) return cached end
local template = get(k)
if template then
local function renderer(ctx_stack, getpartial, write, d1, d2, escape)
local getpartial_ = getpartial
getpartial = function(name)
if getpartial_ then
local ret = getpartial_(name)
if ret then return ret end
end
return get(name)
end
return {
layout = false,
mustache.render(template, ctx_stack, getpartial, write, d1, d2, escape)
}
end
cached = renderer
else
cached=false
end
t[k]=cached
return cached
end})
return _M