about summary refs log tree commit diff stats
path: root/compile.lua
diff options
context:
space:
mode:
authorCase Duckworth2015-03-06 22:08:20 -0700
committerCase Duckworth2015-03-06 22:08:20 -0700
commite01ed83975933e4c8eafcda7950db98342ddfd63 (patch)
tree0739c8cea3fb07b5ee48870ed096b093e33e8c3b /compile.lua
parentChange compile.sh to also compile RIVER files (diff)
downloadautocento-e01ed83975933e4c8eafcda7950db98342ddfd63.tar.gz
autocento-e01ed83975933e4c8eafcda7950db98342ddfd63.zip
Switch to compile.lua for reasons
Diffstat (limited to 'compile.lua')
-rw-r--r--compile.lua98
1 files changed, 98 insertions, 0 deletions
diff --git a/compile.lua b/compile.lua new file mode 100644 index 0000000..f70cfbc --- /dev/null +++ b/compile.lua
@@ -0,0 +1,98 @@
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", { "smart", "mathml" })
88 -- move(tabsub(files,'^.*/(.*)%.txt','%1.html'), ".")
89end
90if intable(args, '-river') then
91 print("Compiling RIVER ... ")
92 compile(files, "lua/river.lua", "river", nil, {})
93 move(tabsub(files,'^.*/(.*)%.txt','%1.river'), "river")
94end
95if intable(args, '-lozenge') then
96 print("Updating lozenge.js with file list ... ")
97 -- TODO
98end