about summary refs log tree commit diff stats
path: root/test/compile.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/compile.lua')
-rw-r--r--test/compile.lua102
1 files changed, 102 insertions, 0 deletions
diff --git a/test/compile.lua b/test/compile.lua new file mode 100644 index 0000000..765f348 --- /dev/null +++ b/test/compile.lua
@@ -0,0 +1,102 @@
1#!/usr/bin/env lua
2-- A compiler for Autocento of the breakfast table
3-- written in Lua (because we can, and because
4-- it's good practice for Functional Programming)
5-- ((OR WHATEVER YOU CALL IT, GAHD))
6-- vim: fdm=indent
7
8dir = "/d/Copy/writing/autocento/"
9
10function filterout (list, filter)
11 local output = {}
12 for _,v in ipairs(list) do
13 if not string.match(v, filter) then
14 -- table.insert Y U NO WORK?
15 output[#output + 1] = v
16 end
17 end
18 return output
19end
20function intable (table, item)
21 for k,v in pairs(table) do
22 if v == item then return k end
23 end
24 return false
25end
26function tabsub (table, pattern, replace)
27 local output = {}
28 for k,v in pairs(table) do
29 output[k] = v:gsub(pattern, replace)
30 end
31 return output
32end
33
34function compile (files, output_fmt, extension, template, args)
35 local errors = {}
36 if template then table.insert(args, 'template="'..template..'"') end
37 for _, file in pairs(files) do
38 local pandoc_run = {
39 'pandoc',
40 '-f markdown',
41 '-t '..output_fmt,
42 table.concat(tabsub(args, "^", "--"), ' '),
43 '-o '..file:gsub('^.*/(.-)%.%a+', '%1.'..extension),
44 file
45 }
46 print("Compiling "..file.." to ".. extension)
47 -- print(table.concat(pandoc_run, ' '))
48 os.execute(table.concat(pandoc_run, ' '))
49 end
50end
51
52function move (files, new_dir)
53 local exe = {}
54 for _,file in pairs(files) do
55 print("Moving "..file.." to "..new_dir.."/ ..")
56 table.insert(exe, 'mv '..file..' '..new_dir..'/')
57 end
58 os.execute(table.concat(exe, ' && '))
59 -- print(table.concat(exe, '; '))
60end
61
62function lozenge (files)
63 local output = 'var files=['
64 for _,file in pairs(files) do
65 output = output .. file:gsub('.*', '"%0",')
66 end
67 output = output:gsub(',$', ']')
68 return output
69end
70
71local files = filterout(arg, '^%-')
72if not files or #files == 0 then
73 print("> No file list. WUT?")
74 os.exit(1)
75end
76local args = filterout(arg, '^[^%-]')
77if not args or #args == 0 or args == {'-all'} then
78 args = {
79 '-html',
80 '-river',
81 '-lozenge',
82 }
83end
84
85if intable(args, '-html') then
86 print("Compiling HTML ... ")
87 compile(files, "html5", "html", ".template.html", {
88 "smart",
89 "mathml",
90 "section-divs",
91 })
92 -- move(tabsub(files,'^.*/(.*)%.txt','%1.html'), ".")
93end
94if intable(args, '-river') then
95 print("Compiling RIVER ... ")
96 compile(files, "lua/river.lua", "river", nil, {})
97 move(tabsub(files,'^.*/(.*)%.txt','%1.river'), "river")
98end
99if intable(args, '-lozenge') then
100 print("Updating lozenge.js with file list ... ")
101 -- TODO
102end