handlers.lua

changeset 7
038275cd92ed
parent 4
4cb0d1dbc65b
child 26
77cd7b8fb6a6
equal deleted inserted replaced
6:219d7a7304f8 7:038275cd92ed
1 1
2 module("handlers", package.seeall) 2 --@module handlers
3 3
4 require("handlers.render") 4 local handlers={}
5 require("handlers.copy") 5
6 require("handlers.ignore") 6 handlers.render=require("handlers.render")
7 handlers.copy=require("handlers.copy")
8 handlers.ignore=require("handlers.ignore")
7 9
8 local available={ 10 local available={
9 { pattern = "%.lg$", handler = handlers.render}, 11 { pattern = "%.lg$", handler = handlers.render},
10 { pattern = "%.note$", handler = handlers.ignore}, 12 { pattern = "%.note$", handler = handlers.ignore},
11 { pattern = "", handler = handlers.copy}, 13 { pattern = "", handler = handlers.copy},
12 } 14 }
13 15
14 16
15 function find(f) 17 function handlers.find(f)
16 for _, h in ipairs(available) do 18 for _, h in ipairs(available) do
17 if string.match(f, h.pattern) then 19 if string.match(f, h.pattern) then
18 return h.handler 20 return h.handler
19 end 21 end
20 end 22 end
21 return handlers.ignore 23 return handlers.ignore
22 end 24 end
23 25
24 local cached={} 26 local cached={}
25 27
26 function choose(f, env) 28 function handlers.choose(f, env)
27 cached[f] = find(f) 29 cached[f] = handlers.find(f)
28 end 30 end
29 31
30 -- load 32 -- load
31 function phase1(f, env) 33 function handlers.phase1(f, env)
32 return cached[f].phase1(f, env) 34 return cached[f].phase1(f, env)
33 end 35 end
34 36
35 -- write 37 -- write
36 function phase2(f, env) 38 function handlers.phase2(f, env)
37 return cached[f].phase2(f, env) 39 return cached[f].phase2(f, env)
38 end 40 end
39 41
42 return handlers

mercurial