handlers.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 34
4c7122a505d4
child 37
d63f9862304a
permissions
-rw-r--r--

Don't auto-create directories that will be empty


--@module handlers

local handlers={}

handlers.render=require("handlers.render")
handlers.copy=require("handlers.copy")
handlers.ignore=require("handlers.ignore")

local available={
    { pattern = "%.note$", handler = handlers.ignore},
    { pattern = "^%.", handler = handlers.ignore},
    { pattern = "/%.", handler = handlers.ignore},
    { pattern = "%.lg$", handler = handlers.render},
    { pattern = "%.md$", handler = handlers.render},
    { pattern = "",      handler = handlers.copy},
}


function handlers.find(f)
    for _, h in ipairs(available) do
        if string.match(f, h.pattern) then
            return h.handler
        end
    end
    return handlers.ignore
end

local cached={}

function handlers.choose(f, env)
    cached[f] = handlers.find(f)
end

-- load
function handlers.phase1(f, env)
    return cached[f].phase1(f, env)
end

-- write
function handlers.phase2(f, env)
    return cached[f].phase2(f, env)
end

return handlers

mercurial