lgen.lua

Tue, 16 Jan 2018 17:13:40 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 16 Jan 2018 17:13:40 +0000
changeset 10
118ab361da29
parent 9
751216807683
child 21
3c71c525cec2
permissions
-rw-r--r--

Added an example website based on http://tuomov.iki.fi/

7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
1
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
2 local path=string.gsub(arg[0], "(.*)/[^/]*", "%1");
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
3 if path~=nil then
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
4 package.path=package.path .. ';' .. path .. '/?.lua'
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
5 end
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
5
7667b101cb1e Lua 5.2 compatibility hack
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
7 -- Lua 5.1 setfenv/getfenv compatibility for Lua 5.2
9
751216807683 Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents: 7
diff changeset
8 -- This is required by the "obsolete" ltp module
5
7667b101cb1e Lua 5.2 compatibility hack
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
9 local CE = require('compat_env')
7667b101cb1e Lua 5.2 compatibility hack
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
10 _G.setfenv = CE.setfenv
7667b101cb1e Lua 5.2 compatibility hack
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
11 _G.getfenv = CE.getfenv
7667b101cb1e Lua 5.2 compatibility hack
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
12
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
13 local scan=require('scan')
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
14 local handlers=require('handlers')
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
15 -- globally add missing stuff
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
16 local luaext=require('luaext')
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
17 local lfs=require('lfs')
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
18 local path=require('path')
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 --
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 -- Main
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 --
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
24 if #arg < 3 then
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
25 error("Usage: lgen src tmpl dst")
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
28 local src = arg[1]
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
29 local tmpl = arg[2]
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
30 local dst = arg[3]
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 print('Scan...')
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
33
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
34 local hierarchy = scan.scan(src)
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
36
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
37 local env={
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
38 paths={
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
39 src=src,
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
40 dst=dst,
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
41 tmpl=tmpl,
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
42 },
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
43 pages={
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
44 },
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
45 }
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
46
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
47
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48 -- Pitäisi env konstruoida. polun perusteella.
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 scan.map(hierarchy, function(f) handlers.choose(f, env) end)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 print('Phase 1...')
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 scan.map(hierarchy, function(f) handlers.phase1(f, env) end)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 print('Phase 2...')
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
54 scan.map(hierarchy, function(f) handlers.phase2(f, env) end,
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
55 function(d)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
56 --log.log("Make path "..path.join(dst, d).."\n")
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
57 lfs.mkdir(path.join(dst, d))
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
58 end)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
59 --print('Phase 3...')
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
60 --scan.map(hierarchy, function(f) handlers.phase3(f, env) end)

mercurial