Sun, 06 Sep 2020 22:12:52 +0300
Don't auto-create directories that will be empty
2 | 1 | |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
2 | --@module handlers |
2 | 3 | |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
4 | local handlers={} |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
5 | |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
6 | handlers.render=require("handlers.render") |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
7 | handlers.copy=require("handlers.copy") |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
8 | handlers.ignore=require("handlers.ignore") |
2 | 9 | |
10 | local available={ | |
34 | 11 | { pattern = "%.note$", handler = handlers.ignore}, |
12 | { pattern = "^%.", handler = handlers.ignore}, | |
13 | { pattern = "/%.", handler = handlers.ignore}, | |
3 | 14 | { pattern = "%.lg$", handler = handlers.render}, |
26
77cd7b8fb6a6
Rename path.lua mypath.lua not conflict with other lua path modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
7
diff
changeset
|
15 | { pattern = "%.md$", handler = handlers.render}, |
3 | 16 | { pattern = "", handler = handlers.copy}, |
2 | 17 | } |
18 | ||
19 | ||
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
20 | function handlers.find(f) |
2 | 21 | for _, h in ipairs(available) do |
3 | 22 | if string.match(f, h.pattern) then |
2 | 23 | return h.handler |
24 | end | |
25 | end | |
26 | return handlers.ignore | |
27 | end | |
28 | ||
29 | local cached={} | |
30 | ||
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
31 | function handlers.choose(f, env) |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
32 | cached[f] = handlers.find(f) |
2 | 33 | end |
34 | ||
35 | -- load | |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
36 | function handlers.phase1(f, env) |
2 | 37 | return cached[f].phase1(f, env) |
38 | end | |
39 | ||
40 | -- write | |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
41 | function handlers.phase2(f, env) |
2 | 42 | return cached[f].phase2(f, env) |
43 | end | |
44 | ||
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
4
diff
changeset
|
45 | return handlers |