lgen.lua

Sun, 06 Sep 2020 22:12:52 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 06 Sep 2020 22:12:52 +0300
changeset 35
2f927eae429b
parent 26
77cd7b8fb6a6
child 42
260f867d46c0
permissions
-rw-r--r--

Don't auto-create directories that will be empty


local lgen={}
local lgen_path=string.gsub(arg[0], "(.*)/[^/]*", "%1");
if lgen_path~=nil then
    package.path=package.path .. ';' .. lgen_path .. '/?.lua'
end

-- Lua 5.1 setfenv/getfenv compatibility for Lua 5.2
-- This is required by the "obsolete" ltp module
local CE = require('compat_env')
_G.setfenv = CE.setfenv
_G.getfenv = CE.getfenv

local scan=require('scan')
local handlers=require('handlers')
-- globally add missing stuff 
local luaext=require('luaext')
local lfs=require('lfs')
local path=require('mypath')

--
-- Main
--

if #arg < 3 then
    error("Usage: lgen src tmpl dst")
end

local src = arg[1]
local tmpl = arg[2]
local dst = arg[3]

print('Scan...')

local hierarchy = scan.scan(src)


local env={
    paths={
        src=src,
        dst=dst,
        tmpl=tmpl,
        lgen_location=lgen_path,
    },
    pages={
    },
}
    
    
-- Pitäisi env konstruoida. polun perusteella.
scan.map(hierarchy, function(f) handlers.choose(f, env) end)

print('Phase 1...')
scan.map(hierarchy, function(f) handlers.phase1(f, env) end)
print('Phase 2...')
scan.map(hierarchy, function(f) handlers.phase2(f, env) end,
                    function(d) 
                        --log.log("Make path "..path.join(dst, d).."\n")
                        --lfs.mkdir(path.join(dst, d))
                    end)
--print('Phase 3...')
--scan.map(hierarchy, function(f) handlers.phase3(f, env) end)

mercurial