lgen.lua

Wed, 08 Dec 2021 23:32:16 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 08 Dec 2021 23:32:16 +0200
changeset 40
458b3ce6e2f2
parent 35
2f927eae429b
child 42
260f867d46c0
permissions
-rw-r--r--

highlight.js changes update

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

mercurial