lgen.lua

Mon, 20 Apr 2020 12:02:54 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 20 Apr 2020 12:02:54 -0500
changeset 18
30b9b7402f94
parent 9
751216807683
child 21
3c71c525cec2
permissions
-rw-r--r--

Add title


local path=string.gsub(arg[0], "(.*)/[^/]*", "%1");
if path~=nil then
    package.path=package.path .. ';' .. 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('path')

--
-- 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,
    },
    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