-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtpl_generator.lua
More file actions
37 lines (32 loc) · 893 Bytes
/
tpl_generator.lua
File metadata and controls
37 lines (32 loc) · 893 Bytes
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
-- Source code used to generate lice-tpl.lua
-- Caution, ugly code :)
local lfs = require 'lfs'
local PATH = 'src/templates/templates/'
local TPL_NAME_PATTERN = '^([a-z0-9%_]+[%-header]*)%.txt$'
-- Serializes a given table
local function serialize(t)
local out, buf = 'return {%s}', ''
for k,v in pairs(t) do
buf = buf .. ('\n\t[\'%s\'] = \n[[%s]],\n')
:format(k:gsub('%.txt$',''),v)
end
return out:format(buf)
end
local t = {}
-- Collect all templates
for file in lfs.dir(PATH) do
if file~='.' and file ~= '..' then
if file:match(TPL_NAME_PATTERN) then
local f = assert(io.open(PATH..file, 'r'),
'Error opening file '..file)
local lic = f:read('*a')
f:close()
t[file] = lic
end
end
end
-- Write package
local out = assert(io.open('src/lice-tpl.lua', 'w+'),
'Error writing lice-tpl.lua')
out:write(serialize(t))
out:close()